Example usage for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION

List of usage examples for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION.

Prototype

String JAXB_SCHEMA_LOCATION

To view the source code for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION.

Click Source Link

Document

The name of the property used to specify the xsi:schemaLocation attribute value to place in the marshalled XML output.

Usage

From source file:org.opennms.features.vaadin.pmatrix.manual.PmatrixDpdCalculatorSimpleMovingAverageImplMarshalTest.java

public void testMarshalData() {
    System.out.println("start of test:testMarshalData()");

    // check slf4j settings
    LOG.debug("debug message");
    LOG.warn("warn message");
    LOG.info("info message");

    try {//from w w w .  j a v  a2s.  c  om
        String testFileName = this.getClass().getSimpleName() + "_File.xml";
        File file = new File("target/" + testFileName);
        PrintWriter writer = new PrintWriter(file, "UTF-8");
        writer.close();
        System.out.println("file location:" + file.getAbsolutePath());

        JAXBContext jaxbContext = JAXBContext.newInstance("org.opennms.features.vaadin.pmatrix.calculator");

        // *****************
        // create calculator
        // *****************
        PmatrixDpdCalculatorSimpleMovingAvgImpl simpleMovingAvgCalc = new PmatrixDpdCalculatorSimpleMovingAvgImpl();

        simpleMovingAvgCalc.setLatestDataValue(1010d);
        simpleMovingAvgCalc.setLatestTimestamp(new Date().getTime());
        simpleMovingAvgCalc.setPrevDataValue(3040d);
        simpleMovingAvgCalc.setPreviousTimestamp(new Date().getTime());

        NameValuePair property = new NameValuePair(
                PmatrixDpdCalculatorSimpleMovingAvgImpl.MAX_SAMPLE_NO_PROPERTY_NAME, "10");
        simpleMovingAvgCalc.getConfiguration().add(property);

        for (int i = 1; i < 15; i++) {
            Double latestDataValue = Double.valueOf(i);
            Long latestTimestamp = new Date().getTime() + i; // adding to show small increment in time
            simpleMovingAvgCalc.updateCalculation(latestDataValue, latestTimestamp);
        }

        // **********************
        // marshal test file
        // **********************

        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

        // output pretty printed
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "http://xmlns.opennms.org/xsd/config/pmatrix pmatrixConfig.xsd");

        jaxbMarshaller.marshal(simpleMovingAvgCalc, file);
        //jaxbMarshaller.marshal(pmatrixSpecificationList_context, file);

        // **********************
        // unmarshal test file
        // **********************

        Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller();

        //Object o = jaxbUnMarshaller.unmarshal( new StringReader( marshalledXml )  );

        Object o = jaxbUnMarshaller.unmarshal(file);

        System.out.println("o.tostring:" + o.toString());
        if (o instanceof PmatrixDpdCalculatorSimpleMovingAvgImpl) {
            System.out.println("unmarshalled list:");
            System.out.println((PmatrixDpdCalculatorSimpleMovingAvgImpl) o);
        } else
            System.out.println("cant unmarshal object:");

    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("end of test:testMarshalData()");

}

From source file:com.sap.prd.mobile.ios.mios.VersionInfoManager.java

private void createVersionInfoFile(final String groupId, final String artifactId, final String version,
        Properties versionInfo, List<Dependency> dependencies, OutputStream os)
        throws MojoExecutionException, JAXBException {
    try {/*from   w w w.j a v  a2  s .c  o  m*/

        final String connectionString = "scm:perforce:" + versionInfo.getProperty("port") + ":"
                + getDepotPath(versionInfo.getProperty("depotpath"));

        final Versions versions = new Versions();

        for (final Dependency dep : dependencies)
            versions.addDependency(dep);

        final SCM scm = new SCM();
        scm.setConnection(connectionString);
        scm.setRevision(versionInfo.getProperty("changelist"));

        final Coordinates coordinates = new Coordinates();
        coordinates.setGroupId(groupId);
        coordinates.setArtifactId(artifactId);
        coordinates.setVersion(version);

        versions.setScm(scm);
        versions.setCoordinates(coordinates);

        final JAXBContext context = JAXBContext.newInstance(Versions.class);

        final Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "urn:xml.sap.com:XCodePlugin:VersionInfo" + " " + NEXUS_URL + "/content/repositories/"
                        + SCHEMA_REPOSITORY + "/" + SCHEMA_GROUP_ID.replace(".", "/") + "/" + SCHEMA_ARTIFACT_ID
                        + "/" + SCHEMA_VERSION + "/" + SCHEMA_ARTIFACT_ID + "-" + SCHEMA_VERSION + ".xsd");

        final ByteArrayOutputStream byteOs = new ByteArrayOutputStream();

        marshaller.marshal(versions, byteOs);

        final byte[] b = byteOs.toByteArray();

        DomUtils.validateDocument(
                DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(b)));

        IOUtils.write(b, os);
    } catch (ParserConfigurationException e) {
        throw new MojoExecutionException("Cannot create versions.xml.", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot create versions.xml.", e);
    } catch (SAXException e) {
        throw new MojoExecutionException("Cannot create versions.xml.", e);
    }
}

From source file:mx.bigdata.sat.cfdi.TFDv11.java

public void guardar(OutputStream out) throws Exception {
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv3.PREFIXES));
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd");
    m.marshal(document.getComprobante(), out);
}

From source file:de.iteratec.iteraplan.businesslogic.service.SavedQueryXmlHelper.java

private static Marshaller getMarshaller(Class<?> clazz, String schemaName) throws JAXBException, SAXException {
    JAXBContext context = JAXBContext.newInstance(clazz);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setSchema(getSchema(schemaName));/*from  w w w .ja v a2s  .  co  m*/
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, SCHEMA_URI + " " + SCHEMA_URI + schemaName);

    return m;
}

From source file:mx.bigdata.sat.cfdi.TFDv11c33.java

public void guardar(OutputStream out) throws Exception {
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv32.PREFIXES));
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd");
    m.marshal(document.getComprobante(), out);
}

From source file:mx.bigdata.sat.cfdi.TFDv1_v32.java

public void guardar(OutputStream out) throws Exception {
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv32.PREFIXES));
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.sat.gob.mx/cfd/3  "
            + "http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd "
            + CFDv32.getComplementosNameSpaceAndSchema()
            + "http://www.sat.gob.mx/TimbreFiscalDigital http://www.sat.gob.mx/sitio_internet/TimbreFiscalDigital/TimbreFiscalDigital.xsd ");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);//from w  ww . ja va  2s .  co  m
    m.marshal(document, out);
}

From source file:org.opennms.features.vaadin.pmatrix.manual.AppContextSpecificationMarshalTest.java

public void testJaxbFromContext() {
    System.out.println("start of test:testJaxbFromContext()");
    try {//from  ww w .  j a  va 2  s.  co  m
        String testFileName = this.getClass().getSimpleName() + "_File.xml";
        File file = new File("target/" + testFileName);
        PrintWriter writer = new PrintWriter(file, "UTF-8");
        writer.close();
        System.out.println("file location:" + file.getAbsolutePath());

        // see http://stackoverflow.com/questions/1043109/why-cant-jaxb-find-my-jaxb-index-when-running-inside-apache-felix
        // need to provide bundles class loader
        ClassLoader cl = org.opennms.features.vaadin.pmatrix.model.DataPointDefinition.class.getClassLoader();
        JAXBContext jaxbContext = JAXBContext.newInstance("org.opennms.features.vaadin.pmatrix.model", cl);

        //JAXBContext jaxbContext = JAXBContext.newInstance("org.opennms.features.vaadin.pmatrix.model");

        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

        // output pretty printed
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        PmatrixSpecificationList pmatrixSpecificationList_context = (PmatrixSpecificationList) appContext
                .getBean("pmatrixSpecificationList");
        //PmatrixSpecification pmatrixSpec_Context = (PmatrixSpecification) appContext.getBean("pmatrixSpecification");

        //System.out.println("list to be marshalled:");
        System.out.println(pmatrixSpecificationList_context);

        System.out.println("marshalled list:");
        //jaxbMarshaller.marshal(testDatalist, file);

        //jaxbMarshaller.marshal(pmatrixSpec, System.out); // works
        //jaxbMarshaller.marshal(pmatrixSpecificationList, System.out); //works

        //test of marshaling context data
        //jaxbMarshaller.marshal(pmatrixSpecificationList_context, System.out);
        jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "http://xmlns.opennms.org/xsd/config/pmatrix pmatrixConfig.xsd");

        jaxbMarshaller.marshal(pmatrixSpecificationList_context, file);
        //jaxbMarshaller.marshal(pmatrixSpecificationList_context, file);

        //unmarshal test file

        Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller();

        //Object o = jaxbUnMarshaller.unmarshal( new StringReader( marshalledXml )  );

        Object o = jaxbUnMarshaller.unmarshal(file);

        System.out.println("o.tostring:" + o.toString());
        if (o instanceof PmatrixSpecificationList) {
            System.out.println("unmarshalled list:");
            System.out.println((PmatrixSpecificationList) o);

        } else
            System.out.println("cant unmarshal object:");

    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("end of test:testAppContext()");
}

From source file:mx.bigdata.sat.cfdi.CFDv3.java

public void guardar(OutputStream out) throws Exception {
    Marshaller m = context.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/cfd/3  " + "http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv3.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);//from w w  w  . j a  v  a2  s  .c om
    m.marshal(document, out);
}

From source file:mx.bigdata.cfdi.TFDv1.java

private Element marshalTFD() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);//www .j  av  a  2  s  .com
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/TimbreFiscalDigital TimbreFiscalDigital.xsd");
    m.marshal(tfd, doc);
    return doc.getDocumentElement();
}

From source file:mx.bigdata.sat.cfdi.TFDv1.java

private Element marshalTFD() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);/* w  w w. j  av a 2  s  . c o m*/
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv3.PREFIXES));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/TimbreFiscalDigital TimbreFiscalDigital.xsd");
    m.marshal(tfd, doc);
    return doc.getDocumentElement();
}