Package javax.xml.bind

Examples of javax.xml.bind.Marshaller


    group.addTranslator(translator);
       
    // Now use JAXB and write the file.
    Class[] classes = { TranslatorMetaDataGroup.class };
    JAXBContext context = JAXBContext.newInstance(classes);
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,new Boolean(true));

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


     * @return an XML document of this PlanNode
     */
    public String toXml() {
      try {
        JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {PlanNode.class});
      Marshaller marshaller = jc.createMarshaller();
      marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE); //$NON-NLS-1$
      StringWriter writer = new StringWriter();
      marshaller.marshal(this, writer);
      return writer.toString();
      } catch (JAXBException e) {
        //shouldn't happen
        throw new TeiidRuntimeException(e);
      }
View Full Code Here

    tm.setName("Oracle");
    tm.setDescription("desc");
    tm.addProperty("ExtensionTranslationClassName", "org.teiid.translator.jdbc.oracle.OracleSQLTranslator");
   
    JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {TranslatorMetaDataGroup.class});
    Marshaller marshell = jc.createMarshaller();
    marshell.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,new Boolean(true));
   
    StringWriter sw = new StringWriter();
    marshell.marshal(group, sw);
       
    System.out.println(sw.toString());   
   
    Unmarshaller un = jc.createUnmarshaller();
    group = (TranslatorMetaDataGroup)un.unmarshal(new StringReader(sw.toString()));
View Full Code Here

    vdb.addDataPolicy(roleOne);
   
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(VDBMetaData.class.getResource("/vdb-deployer.xsd"));      //$NON-NLS-1$
    JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {VDBMetaData.class});
    Marshaller marshell = jc.createMarshaller();
    marshell.setSchema(schema);
    marshell.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,new Boolean(true));
   
    StringWriter sw = new StringWriter();
    marshell.marshal(vdb, sw);
       
    //System.out.println(sw.toString());

    // UnMarshell
    Unmarshaller un = jc.createUnmarshaller();
View Full Code Here

                                : env.addHeader();
                               
            discardRMHeaders(header);
            header.addNamespaceDeclaration(Names.WSRM_NAMESPACE_PREFIX,
                                           Names.WSRM_NAMESPACE_NAME);
            Marshaller marshaller = getJAXBContext().createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
          
            SequenceType seq = rmps.getSequence();
            if (null != seq) {
                encodeProperty(seq,
                               Names.WSRM_SEQUENCE_QNAME,
View Full Code Here

        headerItr.hasNext();
        EasyMock.expectLastCall().andReturn(Boolean.FALSE);
        header.addNamespaceDeclaration(Names.WSA_NAMESPACE_PREFIX,
                                       maps.getNamespaceURI());
        EasyMock.expectLastCall().andReturn(null);       
        Marshaller marshaller = control.createMock(Marshaller.class);
        ContextUtils.getJAXBContext().createMarshaller();
        EasyMock.expectLastCall().andReturn(marshaller);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        EasyMock.expectLastCall();
        IArgumentMatcher matcher = new JAXBEltMatcher();
        for (int i = 0; i < expectedValues.length; i++) {
            EasyMock.reportMatcher(matcher);
            EasyMock.eq(header);
            marshaller.marshal(null, header);
            //marshaller.marshal(expectedJAXBElements[i],
            //                   header);
            EasyMock.expectLastCall();
        }
        MimeHeaders mimeHeaders = control.createMock(MimeHeaders.class);
View Full Code Here

    }
   
    private Marshaller getMarshaller() throws JAXBException {
        JAXBContext jaxbContext =
            VersionTransformer.getExposedJAXBContext(currentNamespaceURI);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        return marshaller;
    }
View Full Code Here

                header.addNamespaceDeclaration(Names.WSA_NAMESPACE_PREFIX,
                                               maps.getNamespaceURI());
                JAXBContext jaxbContext =
                    VersionTransformer.getExposedJAXBContext(
                                                     maps.getNamespaceURI());
                Marshaller marshaller = jaxbContext.createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
                transformer.encodeAsExposed(maps.getNamespaceURI(),
                                            maps.getMessageID(),
                                            Names.WSA_MESSAGEID_NAME,
                                            AttributedURIType.class,
                                            header,
View Full Code Here

                dest.addDocument(doc);
            } else if (Object.class.isAssignableFrom(obj.getClass())) {
               
                JAXBContext context = callback.getJAXBContext();
               
                Marshaller u = context.createMarshaller();
                u.setProperty(Marshaller.JAXB_ENCODING , "UTF-8");
                u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                u.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE)
               
                DOMResult domResult = new DOMResult();
                u.marshal(obj, domResult);
                dest.addDocument((Document)domResult.getNode());               
               
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
View Full Code Here

        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

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.