Package javax.xml.bind

Examples of javax.xml.bind.JAXBContext.createMarshaller()


            } else {
                arg = new JAXBElement(ROOT_ELEMENT, Object.class, arg);
            }
            JAXBContext context = JAXBContext.newInstance(cls);
            Document doc = DOMHelper.newDocument();
            context.createMarshaller().marshal(arg, doc);
            JAXBElement<?> element = context.createUnmarshaller().unmarshal(doc, cls);
            return isElement ? element : element.getValue();
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
View Full Code Here


        return new JAXBSource(context, value);
    }

    public Document toDocument(@HasAnnotation(XmlRootElement.class)Object value) throws JAXBException, ParserConfigurationException {
        JAXBContext context = createJaxbContext(value);
        Marshaller marshaller = context.createMarshaller();

        Document doc = getJaxbConverter().createDocument();
        marshaller.marshal(value, doc);
        return doc;
    }
View Full Code Here

            JAXBSource source = new JAXBSource(context, value);
            T answer = parentTypeConverter.convertTo(type, source);
            if (answer == null) {
                // lets try a stream
                StringWriter buffer = new StringWriter();
                Marshaller marshaller = context.createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, isPrettyPrint() ? Boolean.TRUE : Boolean.FALSE);
                marshaller.marshal(value, buffer);
                return parentTypeConverter.convertTo(type, buffer.toString());
            }
            return answer;
View Full Code Here

    public static Source convertToXML(EndpointReferenceType epr) {
        try {
            JAXBContext jaxbContext =
                JAXBContext.newInstance(new Class[] {WSA_WSDL_OBJECT_FACTORY.getClass(),
                                                     WSA_OBJECT_FACTORY.getClass()});
            javax.xml.bind.Marshaller jm = jaxbContext.createMarshaller();
            jm.setProperty(Marshaller.JAXB_FRAGMENT, true);
            QName qname = new QName("http://www.w3.org/2005/08/addressing", "EndpointReference");
            JAXBElement<EndpointReferenceType>
            jaxEle = new JAXBElement<EndpointReferenceType>(qname, EndpointReferenceType.class, epr);
           
View Full Code Here

        }
        JAXBContext context = new JAXBContextHelper(new DefaultExtensionPointRegistry()).createJAXBContext(classes.toArray(new Class<?>[classes.size()]));
        for (Class<?> cls : classes) {
            Object obj = cls.newInstance();
            StringWriter sw = new StringWriter();
            context.createMarshaller().marshal(obj, sw);
            // System.out.println(sw.toString());
            StringReader sr = new StringReader(sw.toString());
            context.createUnmarshaller().unmarshal(new StreamSource(sr), cls);
        }
    }
View Full Code Here

          File tempFile = tempFile("ra-", connectorModule.getModuleId() + ".xml");

            final OutputStream out = IO.write(tempFile);
          try {
          JAXBContext ctx = JAXBContextFactory.newInstance(Connector.class);
          Marshaller marshaller = ctx.createMarshaller();
          marshaller.marshal(connector, out);
          } catch (JAXBException e) {
          } finally {
            IO.close(out);
          }
View Full Code Here

            persistence.getPersistenceUnit().add(pu);

            try {
                FileWriter writer = new FileWriter(file);
                JAXBContext jc = JAXBContextFactory.newInstance(Persistence.class);
                Marshaller marshaller = jc.createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                marshaller.marshal(persistence, writer);
                writer.close();
            } catch (Exception e) {
                LOGGER.error("can't dump pu " + reloadableEntityManagerFactory.getPUname() + " in file " + file, e);
View Full Code Here

        return new String(baos.toByteArray());
    }

    public static <T> void marshal(Class<T> type, Object object, OutputStream out) throws JAXBException {
        JAXBContext jaxbContext = getContext(type);
        Marshaller marshaller = jaxbContext.createMarshaller();

        marshaller.setProperty("jaxb.formatted.output", true);

        marshaller.marshal(object, out);
    }
View Full Code Here

       
        Class<?> objClazz = JAXBElement.class.isAssignableFrom(cls)
                            ? ((JAXBElement)obj).getDeclaredType() : cls;
                           
        JAXBContext context = getJAXBContext(objClazz, genericType);
        Marshaller marshaller = context.createMarshaller();
        if (enc != null) {
            marshaller.setProperty(Marshaller.JAXB_ENCODING, enc);
        }
        validateObjectIfNeeded(marshaller, obj);
        return marshaller;
View Full Code Here

        return new String(baos.toByteArray());
    }

    public static <T>void marshal(Class<T> type, Object object, OutputStream out) throws JAXBException {
        JAXBContext ctx2 = JaxbJavaee.getContext(type);
        Marshaller marshaller = ctx2.createMarshaller();

        marshaller.setProperty("jaxb.formatted.output", true);

        marshaller.marshal(object, out);
    }
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.