Search in sources :

Example 36 with Marshaller

use of javax.xml.bind.Marshaller in project OpenAM by OpenRock.

the class CreateWSFedMetaDataTemplate method createStandardMetaTemplate.

public static String createStandardMetaTemplate(String entityId, Map mapParams, String url) throws JAXBException, CertificateEncodingException {
    JAXBContext jc = WSFederationMetaUtils.getMetaJAXBContext();
    com.sun.identity.wsfederation.jaxb.wsfederation.ObjectFactory objFactory = new com.sun.identity.wsfederation.jaxb.wsfederation.ObjectFactory();
    FederationElement fed = objFactory.createFederationElement();
    fed.setFederationID(entityId);
    String idpAlias = (String) mapParams.get(MetaTemplateParameters.P_IDP);
    if (idpAlias != null) {
        addWSFedIdentityProviderTemplate(entityId, objFactory, fed, mapParams, url);
    }
    String spAlias = (String) mapParams.get(MetaTemplateParameters.P_SP);
    if (spAlias != null) {
        addWSFedServiceProviderTemplate(entityId, objFactory, fed, mapParams, url);
    }
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    StringWriter pw = new StringWriter();
    m.marshal(fed, pw);
    return pw.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)

Example 37 with Marshaller

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

the class ToolsUtils method serializeObject.

public static void serializeObject(Object object, Writer writer) throws JAXBException {
    if (object == null) {
        return;
    }
    Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    if (object instanceof ObjectType) {
        object = new JAXBElement(C_OBJECT, Object.class, object);
    }
    marshaller.marshal(object, writer);
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Marshaller(javax.xml.bind.Marshaller) JAXBElement(javax.xml.bind.JAXBElement)

Example 38 with Marshaller

use of javax.xml.bind.Marshaller in project OpenAM by OpenRock.

the class WSFederationMetaUtils method convertJAXBToOutputStream.

/**
     * Converts a JAXB object and writes to an <code>OutputStream</code> object.
     * @param jaxbObj a JAXB object
     * @param os an <code>OutputStream</code> object
     * @exception JAXBException if an error occurs while converting JAXB object
     */
public static void convertJAXBToOutputStream(Object jaxbObj, OutputStream os) throws JAXBException {
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(PROP_JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(PROP_NAMESPACE_PREFIX_MAPPER, nsPrefixMapper);
    marshaller.marshal(jaxbObj, os);
}
Also used : Marshaller(javax.xml.bind.Marshaller)

Example 39 with Marshaller

use of javax.xml.bind.Marshaller in project OpenAM by OpenRock.

the class SMDiscoEntryData method convertDiscoEntryToXmlStr.

private String convertDiscoEntryToXmlStr(DiscoEntryElement de) throws JAXBException {
    JAXBContext jc = JAXBContext.newInstance(Utils.getJAXBPackages());
    Marshaller m = jc.createMarshaller();
    StringWriter sw = new StringWriter();
    m.marshal(de, sw);
    return sw.getBuffer().toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext)

Example 40 with Marshaller

use of javax.xml.bind.Marshaller in project opennms by OpenNMS.

the class BundleContextHistoryManager method toXML.

private String toXML(SavedHistory hist) {
    StringWriter writer = new StringWriter();
    Marshaller marshaller;
    try {
        JAXBContext context = JAXBContext.newInstance(SavedHistory.class);
        marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
        marshaller.marshal(hist, writer);
    } catch (JAXBException e) {
        LoggerFactory.getLogger(getClass()).error("Could not marshall SavedHistory object to String", e);
    }
    return writer.toString();
}
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