Package javax.xml.bind

Examples of javax.xml.bind.Marshaller


   
    public static String toString(Object obj) throws JAXBException {
        String name = obj.getClass().getPackage().getName();
        JAXBContext context = JAXBContext.newInstance(name);
        JAXBElement<Object> el = new JAXBElement<Object>(new QName("test"), Object.class, obj);
        Marshaller m = context.createMarshaller();
        StringWriter writer = new StringWriter();
        m.marshal(el, writer);

        return writer.toString();      
    }
View Full Code Here


     */
    public void marshall(Class parent, QName qname, ExtensibilityElement obj, PrintWriter pw,
                         final Definition wsdl, ExtensionRegistry registry) throws WSDLException {
        // TODO Auto-generated method stub
        try {
            Marshaller u = context.createMarshaller();
            u.setProperty("jaxb.encoding", "UTF-8");
            u.setProperty("jaxb.fragment", Boolean.TRUE);
            u.setProperty("jaxb.formatted.output", Boolean.TRUE);
           
            Object mObj = obj;
           
            Class<?> objectFactory = Class.forName(typeClass.getPackage().getName() + ".ObjectFactory");
            Method methods[] = objectFactory.getDeclaredMethods();
            for (Method method : methods) {
                if (method.getParameterTypes().length == 1
                    && method.getParameterTypes()[0].equals(typeClass)) {
                   
                    mObj = method.invoke(objectFactory.newInstance(), new Object[] {obj});
                }
            }

            javax.xml.stream.XMLOutputFactory fact = javax.xml.stream.XMLOutputFactory.newInstance();
            XMLStreamWriter writer = fact.createXMLStreamWriter(pw);
            writer.setNamespaceContext(new javax.xml.namespace.NamespaceContext() {
               
                public String getNamespaceURI(String arg) {
                    return wsdl.getNamespace(arg);
                }
                               
                public String getPrefix(String arg) {
                    for (Object ent : wsdl.getNamespaces().entrySet()) {
                        Map.Entry entry = (Map.Entry)ent;
                        if (arg.equals(entry.getValue())) {
                            return (String)entry.getKey();
                        }
                    }
                    return null;
                }
               
                public Iterator getPrefixes(String arg) {
                    return wsdl.getNamespaces().keySet().iterator();
                }
            });
           
            u.marshal(mObj, writer);
            writer.flush();           
        } catch (Exception ex) {
            throw new WSDLException(WSDLException.PARSER_ERROR,
                                    "",
                                    ex);
View Full Code Here

  
   public static String marshalResourceAsString(ManagedConnectionFactoryDeploymentGroup group) throws Exception
   {
      Class[] classes = {ManagedConnectionFactoryDeploymentGroup.class, ManagedConnectionFactoryDeploymentMetaData.class, LocalDataSourceDeploymentMetaData.class, NonXADataSourceDeploymentMetaData.class, DataSourceDeploymentMetaData.class};     
      JAXBContext context = JAXBContext.newInstance(classes);     
      Marshaller m = context.createMarshaller();     
      JAXBElement element = new JAXBElement(new QName("", "datasources"), group.getClass(), group);
      StringWriter w = new StringWriter();
      m.marshal(element, w);     
      return w.toString();     
   }
View Full Code Here

      if (log.isTraceEnabled())
      {
         log.trace("saveMetadata, metadataStore="+metadataStore+ ", metadata="+metadata);
      }
      JAXBContext ctx = JAXBContext.newInstance(metadata.getClass());
      Marshaller marshaller = ctx.createMarshaller();
      marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
      marshaller.marshal(metadata, metadataStore);
   }
View Full Code Here

            log.trace("property not found: " + tempProp.getName());
      }

      Class[] classes = {ManagedConnectionFactoryDeploymentGroup.class};
      JAXBContext context = JAXBContext.newInstance(classes);     
      Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);

      JAXBElement<ManagedConnectionFactoryDeploymentGroup> root =
            new JAXBElement<ManagedConnectionFactoryDeploymentGroup>(
                  new javax.xml.namespace.QName(rootElementName),
                  ManagedConnectionFactoryDeploymentGroup.class,
                  null, group
            );

      FileWriter fw = null;
      try
      {
         fw = new FileWriter(dsXml);
         marshaller.marshal(root, fw);
      }
      finally
      {
         if(fw != null)
            fw.close();
View Full Code Here

   protected void saveAttachment(File attachmentsStore, Object attachment) throws Exception
   {
      if(log.isTraceEnabled())
         log.trace("saveAttachment, attachmentsStore="+attachmentsStore+ ", attachment="+attachment);
      JAXBContext ctx = JAXBContext.newInstance(attachment.getClass());
      Marshaller marshaller = ctx.createMarshaller();
      marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
      OutputStream os = new FileOutputStream(attachmentsStore);
      try
      {
         marshaller.marshal(attachment, os);
      }
      finally
      {
         os.close();
      }
View Full Code Here

      }
      else
         throw new IllegalStateException("Unsupported destination type: " + destinationType);

      JAXBContext context = JAXBContext.newInstance(JAXBJMSConfiguration.class);
      Marshaller marshaller = context.createMarshaller();
      marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);

      JAXBElement<JAXBJMSConfiguration> root = new JAXBElement<JAXBJMSConfiguration>(
            new javax.xml.namespace.QName("urn:hornetq", "configuration"), JAXBJMSConfiguration.class, null, config);

      Writer fw = null;
      try
      {
         fw = new FileWriter(xml);
         marshaller.marshal(root, fw);
      }
      finally
      {
         if (fw != null)
         {
View Full Code Here

   }
  
   protected void serialize(PersistenceRoot moElement, File file) throws Exception
   {
      JAXBContext ctx = JAXBContext.newInstance(PersistenceRoot.class);
      Marshaller marshaller = ctx.createMarshaller();
      marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
      marshaller.marshal(moElement, file);
      marshaller.marshal(moElement, System.out);
   }
View Full Code Here

         }
      }
      try
      {
         JAXBContext ctx = finder.findCacheContext(mediaType, annotations, set.toArray(new Class[set.size()]));
         Marshaller marshaller = ctx.createMarshaller();
         NamespacePrefixMapper mapper = new NamespacePrefixMapper()
         {
            public String getPreferredPrefix(String namespace, String s1, boolean b)
            {
               if (namespace.equals("http://www.w3.org/2005/Atom")) return "atom";
               else return s1;
            }
         };

         marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);

         marshaller.marshal(feed, entityStream);
      }
      catch (JAXBException e)
      {
         throw new JAXBMarshalException("Unable to marshal: " + mediaType, e);
      }
View Full Code Here

   public String getBooksBadgerText() throws Exception
   {
      BookListing listing = getListing();
      BadgerContext context = new BadgerContext(BookListing.class);
      StringWriter writer = new StringWriter();
      Marshaller marshaller = context.createMarshaller();
      marshaller.marshal(listing, writer);
      return writer.toString();
   }
View Full Code Here

TOP

Related Classes of javax.xml.bind.Marshaller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.