Examples of Marshaller


Examples of javax.xml.bind.Marshaller

        try {
            if (context == null) {
                context = JAXBContext.newInstance(elValue.getClass());
            }
            Object mObj = elValue;
            Marshaller u = context.createMarshaller();
            u.setProperty(Marshaller.JAXB_ENCODING , "UTF-8");
            u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

            if (elValue.getClass().isAnnotationPresent(XmlRootElement.class)) {
                String packageName = elValue.getClass().getPackage().getName();
                Class<?> objectFactory = Class.forName(packageName + ".ObjectFactory", false,
                                                       elValue.getClass().getClassLoader());

                Method methods[] = objectFactory.getDeclaredMethods();
                for (Method method : methods) {
                    if (method.getParameterTypes().length == 1
                        && method.getParameterTypes()[0].equals(elValue.getClass())) {

                        XmlElementDecl elementDecl = method.getAnnotation(XmlElementDecl.class);
                        if (null != elementDecl) {
                            QName elementType = new QName(elementDecl.namespace(), elementDecl.name());
                            if (elementType.equals(elNname)) {
                                mObj = method.invoke(objectFactory.newInstance(),
                                                    elValue);                       
                            }
                        }
                    }
                }
            } else {
                mObj = JAXBElement.class.getConstructor(new Class[] {QName.class, Class.class, Object.class})
                    .newInstance(elNname, mObj.getClass(), mObj);
            }
            u.setSchema(schema);
            u.marshal(mObj, destNode);
        } catch (MarshalException me) {
            // It's helpful to include the cause in the case of
            // schema validation exceptions.
            String message = "Marshalling error ";
            if (me.getCause() != null) {
View Full Code Here

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

Examples of javax.xml.bind.Marshaller

     */
    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

Examples of javax.xml.bind.Marshaller

  
   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

Examples of javax.xml.bind.Marshaller

      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

Examples of javax.xml.bind.Marshaller

            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

Examples of javax.xml.bind.Marshaller

   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

Examples of javax.xml.bind.Marshaller

      }
      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

Examples of javax.xml.bind.Marshaller

   }
  
   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

Examples of javax.xml.bind.Marshaller

         }
      }
      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
TOP
Copyright © 2018 www.massapi.com. 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.