Search in sources :

Example 46 with Marshaller

use of javax.xml.bind.Marshaller in project Activiti by Activiti.

the class AlfrescoArtifactExporter method writeShareConfig.

/**
	 * Write the Share module XML in the given conversion to the given stream. 
	 */
public void writeShareConfig(OutputStream out, WorkflowDefinitionConversion conversion, boolean asExtension) throws IOException {
    Extension extension = AlfrescoConversionUtil.getExtension(conversion);
    try {
        Object toMarshall = extension;
        // in a "alfresco-configuration" element instead
        if (!asExtension) {
            toMarshall = new AlfrescoConfiguration();
            ((AlfrescoConfiguration) toMarshall).setConfigurations(extension.getModules().get(0).getConfigurations());
        }
        Marshaller marshaller = moduleJaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(toMarshall, out);
    } catch (JAXBException jaxbe) {
        throw new IOException(jaxbe);
    }
}
Also used : Extension(org.activiti.workflow.simple.alfresco.model.config.Extension) Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) AlfrescoConfiguration(org.activiti.workflow.simple.alfresco.model.config.AlfrescoConfiguration)

Example 47 with Marshaller

use of javax.xml.bind.Marshaller in project Activiti by Activiti.

the class AlfrescoArtifactExporter method writeContentModel.

/**
	 * Write the content model XML in the given conversion to the given stream. 
	 */
public void writeContentModel(OutputStream out, WorkflowDefinitionConversion conversion) throws IOException {
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    try {
        Marshaller marshaller = modelJaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(model, out);
    } catch (JAXBException jaxbe) {
        throw new IOException(jaxbe);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Example 48 with Marshaller

use of javax.xml.bind.Marshaller in project nhin-d by DirectProject.

the class XmlUtils method marshal.

/**
     * Marshal an object into an XML string.
     * 
     * @param altName
     *            The altName.
     * @param jaxb
     *            The object to marshal.
     * @param factory
     *            The factory class.
     * @return a marshaled string from the object.
     */
@SuppressWarnings("unchecked")
public static String marshal(QName altName, Object jaxb, Class<?> factory) {
    String ret = null;
    try {
        javax.xml.bind.JAXBContext jc = javax.xml.bind.JAXBContext.newInstance(factory);
        Marshaller u = jc.createMarshaller();
        StringWriter sw = new StringWriter();
        u.marshal(new JAXBElement(altName, jaxb.getClass(), jaxb), sw);
        StringBuffer sb = sw.getBuffer();
        ret = new String(sb);
    } catch (Exception ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn("Failed to marshal message.", ex);
    }
    return ret;
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBElement(javax.xml.bind.JAXBElement) JAXBException(javax.xml.bind.JAXBException)

Example 49 with Marshaller

use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.

the class OrcidMarshallerContextResolver method getContext.

@Override
public Marshaller getContext(Class<?> type) {
    try {
        context = JAXBContext.newInstance(type);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        return new OrcidMarshallerWrapper(marshaller);
    } catch (JAXBException e) {
        logger.error("Cannot create new marshaller", e);
        throw new WebApplicationException(getResponse(e));
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) WebApplicationException(javax.ws.rs.WebApplicationException) JAXBException(javax.xml.bind.JAXBException)

Example 50 with Marshaller

use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.

the class OrcidClientGroup method toString.

@Override
public String toString() {
    try {
        JAXBContext context = JAXBContext.newInstance(getClass());
        StringWriter writer = new StringWriter();
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(this, writer);
        return writer.toString();
    } catch (JAXBException e) {
        return ("Unable to unmarshal because: " + e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) 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