Example usage for javax.xml.bind Marshaller JAXB_NO_NAMESPACE_SCHEMA_LOCATION

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

Introduction

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

Prototype

String JAXB_NO_NAMESPACE_SCHEMA_LOCATION

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

Click Source Link

Document

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

Usage

From source file:com.l2jserver.model.template.SkillTemplateConverter.java

public static void main(String[] args) throws SQLException, IOException, ClassNotFoundException, JAXBException {
    Class.forName("com.mysql.jdbc.Driver");

    final File target = new File("data/templates");
    final JAXBContext c = JAXBContext.newInstance(SkillTemplate.class, LegacySkillList.class);
    final Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USERNAME, JDBC_PASSWORD);

    System.out.println("Generating template XML files...");
    c.generateSchema(new SchemaOutputResolver() {
        @Override//w w w.j  a v  a 2  s  .  c om
        public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
            return new StreamResult(new File(target, suggestedFileName));
        }
    });

    try {
        final Unmarshaller u = c.createUnmarshaller();
        final Marshaller m = c.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "skill");
        m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "skill ../skill.xsd");

        Collection<File> files = FileUtils.listFiles(new File(LEGACY_SKILL_FOLDER), new String[] { "xml" },
                true);
        for (final File legacyFile : files) {
            LegacySkillList list = (LegacySkillList) u.unmarshal(legacyFile);
            for (final LegacySkill legacySkill : list.skills) {
                SkillTemplate t = fillSkill(legacySkill);
                final File file = new File(target, "skill/" + t.id.getID()
                        + (t.getName() != null ? "-" + camelCase(t.getName()) : "") + ".xml");
                templates.add(t);

                try {
                    m.marshal(t, getXMLSerializer(new FileOutputStream(file)));
                } catch (MarshalException e) {
                    System.err.println(
                            "Could not generate XML template file for " + t.getName() + " - " + t.getID());
                    file.delete();
                }
            }
        }

        System.out.println("Generated " + templates.size() + " templates");

        System.gc();
        System.out.println("Free: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().freeMemory()));
        System.out.println("Total: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().totalMemory()));
        System.out.println("Used: " + FileUtils.byteCountToDisplaySize(
                Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
        System.out.println("Max: " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory()));
    } finally {
        conn.close();
    }
}

From source file:org.jellycastle.maven.Maven.java

/**
 * Serialize Maven POM object tree.//from  w w  w.j a  v  a 2 s .c o  m
 * @param outputStream
 */
public void serialize(Project project, OutputStream outputStream) {
    StreamResult stream = new StreamResult(outputStream);

    Map<String, Object> marshallerProperties = new HashMap<String, Object>();
    marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshallerProperties.put(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "");

    marshaller.setMarshallerProperties(marshallerProperties);
    marshaller.marshal(project, stream);
}

From source file:org.openengsb.connector.promreport.internal.ProcessFileStore.java

private void createFile(File mxmlFile, String processId) {
    LOGGER.debug(String.format("create file %s for process %s", mxmlFile.getName(), processId));
    try {/*from  w w  w  .  j  ava2s .c  o  m*/
        if (mxmlFile.createNewFile()) {
            Marshaller m = jaxbContext.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION,
                    "http://is.tm.tue.nl/research/processmining/WorkflowLog.xsd");
            m.setSchema(schema);
            m.marshal(createWorkflowLogTemplate(processId), mxmlFile);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.openmainframe.ade.ext.output.ExtJaxbAnalyzedIntervalV2XmlStorer.java

/**
 * Begin of Stream//from w ww . jav  a2  s .  co m
 */
@Override
public void beginOfStream() throws AdeException, AdeFlowException {
    if (s_marshaller == null) {
        JAXBContext jaxbContext;
        try {
            jaxbContext = JAXBContext.newInstance(ADEEXT_JAXB_CONTEXT);
        } catch (JAXBException e) {
            throw new AdeInternalException(
                    "failed to create JAXBContext object for package " + Arrays.toString(ADEEXT_JAXB_CONTEXT),
                    e);
        }
        try {
            s_marshaller = jaxbContext.createMarshaller();
        } catch (JAXBException e) {
            throw new AdeInternalException("failed to create JAXB Marshaller object", e);
        }
        try {
            s_marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, m_formatXMLOutput);
            s_marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
            s_marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, XML_INTERVAL_V2_XSD);

        } catch (PropertyException e) {
            throw new AdeInternalException("failed to set formatted output for JAXB Marshaller object", e);
        }

        SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

        File xmlParent = Ade.getAde().getConfigProperties().getXsltDir().getAbsoluteFile();
        xmlParent = xmlParent.getParentFile();
        File intervalSchema = new File(xmlParent, XML_INTERVAL_V2_XSD);

        Schema schema;
        try {
            URL analyzedIntervalSchema = intervalSchema.toURI().toURL();
            schema = sf.newSchema(analyzedIntervalSchema);
        } catch (SAXException e) {
            throw new AdeInternalException("failed to create XML Schemal for event log analysis results", e);
        } catch (MalformedURLException e) {
            throw new AdeInternalException(
                    "failed to create URL from Schema path: " + intervalSchema.getAbsolutePath(), e);
        }
        s_marshaller.setSchema(schema);
    }
    m_xmlMetaData = new XMLMetaDataRetriever();
}

From source file:org.openmainframe.ade.ext.output.ExtJaxbAnalyzedPeriodV2XmlStorer.java

/**
 * Begin of Stream//from ww  w . ja  v  a  2 s .co m
 */
@Override
public void beginOfStream() throws AdeException, AdeFlowException {
    if (s_marshaller == null) {
        JAXBContext jaxbContext;
        try {
            jaxbContext = JAXBContext.newInstance(ADEEXT_JAXB_CONTEXT);
        } catch (JAXBException e) {
            throw new AdeInternalException(
                    "failed to create JAXBContext object for package " + Arrays.toString(ADEEXT_JAXB_CONTEXT),
                    e);
        }
        try {
            s_marshaller = jaxbContext.createMarshaller();
        } catch (JAXBException e) {
            throw new AdeInternalException("failed to create JAXB Marshaller object", e);
        }
        try {
            s_marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, m_formatXMLOutput);
            s_marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
            s_marshaller.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, XML_PLEX_V2_XSD);
        } catch (PropertyException e) {
            throw new AdeInternalException("failed to set formatted output for JAXB Marshaller object", e);
        }

        SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);

        File xmlParent = Ade.getAde().getConfigProperties().getXsltDir().getAbsoluteFile();
        xmlParent = xmlParent.getParentFile();
        File systemSchema = new File(xmlParent, XML_PLEX_V2_XSD);

        Schema schema;
        try {
            URL systemSchemaURL = systemSchema.toURI().toURL();
            schema = sf.newSchema(systemSchemaURL);
        } catch (SAXException e) {
            throw new AdeInternalException("failed to create XML Schemal for event log analysis results", e);
        } catch (MalformedURLException e) {
            throw new AdeInternalException(
                    "failed to create URL from Schema path: " + systemSchema.getAbsolutePath(), e);
        }
        s_marshaller.setSchema(schema);
    }

    /* Retrieve the Model Data Here.  Force refresh, in case the Model's Analysis Group Change without impacting
     * the model internal ID. */
    m_xmlMetaData.retrieveXMLMetaData(m_lastKnownModelInternalID, true, m_framingFlowType.getDuration());

    /* Write out the period when it's begin of stream, within a period */
    if (m_inPeriod) {
        writePeriod();
    }
}