Search in sources :

Example 86 with Marshaller

use of javax.xml.bind.Marshaller in project jdk8u_jdk by JetBrains.

the class XmlConfigUtils method writeXml.

/**
     * Writes the given bean to the given output stream.
     * @param bean the bean to write.
     * @param os the output stream to write to.
     * @param fragment whether the {@code <?xml ... ?>} header should be
     *        included. The header is not included if the bean is just an
     *        XML fragment encapsulated in a higher level XML element.
     * @throws JAXBException An XML Binding exception occurred.
     **/
private static void writeXml(Object bean, OutputStream os, boolean fragment) throws JAXBException {
    final Marshaller m = createMarshaller();
    if (fragment)
        m.setProperty(m.JAXB_FRAGMENT, Boolean.TRUE);
    m.marshal(bean, os);
}
Also used : Marshaller(javax.xml.bind.Marshaller)

Example 87 with Marshaller

use of javax.xml.bind.Marshaller in project streamsx.topology by IBMStreams.

the class ToolkitRemoteContext method addToolkitInfo.

/**
     * Create an info.xml file for the toolkit.
     * @throws URISyntaxException 
     */
private void addToolkitInfo(File toolkitRoot, JsonObject jsonGraph) throws JAXBException, FileNotFoundException, IOException, URISyntaxException {
    File infoFile = new File(toolkitRoot, "info.xml");
    ToolkitInfoModelType info = new ToolkitInfoModelType();
    info.setIdentity(new IdentityType());
    info.getIdentity().setName(toolkitRoot.getName());
    info.getIdentity().setDescription(new DescriptionType());
    info.getIdentity().setVersion("1.0.0." + System.currentTimeMillis());
    info.getIdentity().setRequiredProductVersion("4.0.1.0");
    DependenciesType dependencies = new DependenciesType();
    List<ToolkitDependencyType> toolkits = dependencies.getToolkit();
    GsonUtilities.objectArray(object(jsonGraph, "spl"), TOOLKITS_JSON, tk -> {
        ToolkitDependencyType depTkInfo;
        String root = jstring(tk, "root");
        if (root != null) {
            try {
                depTkInfo = TkInfo.getTookitDependency(root);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            depTkInfo = new ToolkitDependencyType();
            depTkInfo.setName(jstring(tk, "name"));
            depTkInfo.setVersion(jstring(tk, "version"));
        }
        toolkits.add(depTkInfo);
    });
    File topologyToolkitRoot = TkInfo.getTopologyToolkitRoot();
    toolkits.add(TkInfo.getTookitDependency(topologyToolkitRoot.getAbsolutePath()));
    info.setDependencies(dependencies);
    JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    try (FileOutputStream out = new FileOutputStream(infoFile)) {
        m.marshal(info, out);
    }
}
Also used : IdentityType(com.ibm.streamsx.topology.internal.toolkit.info.IdentityType) Marshaller(javax.xml.bind.Marshaller) DescriptionType(com.ibm.streamsx.topology.internal.toolkit.info.DescriptionType) ToolkitDependencyType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitDependencyType) ToolkitInfoModelType(com.ibm.streamsx.topology.internal.toolkit.info.ToolkitInfoModelType) JAXBContext(javax.xml.bind.JAXBContext) DependenciesType(com.ibm.streamsx.topology.internal.toolkit.info.DependenciesType) URISyntaxException(java.net.URISyntaxException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 88 with Marshaller

use of javax.xml.bind.Marshaller in project jabref by JabRef.

the class ModsExportFormat method createMarshallerAndWriteToFile.

private void createMarshallerAndWriteToFile(String file, JAXBElement<ModsCollectionDefinition> jaxbElement) throws JAXBException {
    if (context == null) {
        context = JAXBContext.newInstance(ModsCollectionDefinition.class);
    }
    Marshaller marshaller = context.createMarshaller();
    //format the output
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, MODS_SCHEMA_LOCATION);
    // Write to File
    marshaller.marshal(jaxbElement, new File(file));
}
Also used : Marshaller(javax.xml.bind.Marshaller) ModsCollectionDefinition(org.jabref.logic.importer.fileformat.mods.ModsCollectionDefinition) File(java.io.File)

Example 89 with Marshaller

use of javax.xml.bind.Marshaller in project midpoint by Evolveum.

the class Upload method marshalObject.

private static String marshalObject(Object object) throws JAXBException, FileNotFoundException {
    JAXBContext jc = getJaxbContext();
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    StringWriter sw = new StringWriter();
    marshaller.marshal(object, sw);
    return sw.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext)

Example 90 with Marshaller

use of javax.xml.bind.Marshaller in project midpoint by Evolveum.

the class RunScript method marshalObject.

private static String marshalObject(Object object) throws JAXBException, FileNotFoundException {
    JAXBContext jc = getJaxbContext();
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    StringWriter sw = new StringWriter();
    marshaller.marshal(object, sw);
    return sw.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext)

Aggregations

Marshaller (javax.xml.bind.Marshaller)280 JAXBContext (javax.xml.bind.JAXBContext)162 JAXBException (javax.xml.bind.JAXBException)100 StringWriter (java.io.StringWriter)82 Test (org.junit.Test)33 JAXBElement (javax.xml.bind.JAXBElement)32 ByteArrayOutputStream (java.io.ByteArrayOutputStream)31 File (java.io.File)29 Unmarshaller (javax.xml.bind.Unmarshaller)21 IOException (java.io.IOException)20 FileOutputStream (java.io.FileOutputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)15 QName (javax.xml.namespace.QName)14 Element (org.w3c.dom.Element)14 HashMap (java.util.HashMap)12 Writer (java.io.Writer)11 Document (org.w3c.dom.Document)11 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7