Search in sources :

Example 36 with JAXBElement

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

the class JaxbTestUtil method unmarshalObject.

public <T> T unmarshalObject(InputStream input) throws JAXBException, SchemaException {
    Object object = getUnmarshaller().unmarshal(input);
    JAXBElement<T> jaxbElement = (JAXBElement<T>) object;
    adopt(jaxbElement);
    if (jaxbElement == null) {
        return null;
    }
    T value = jaxbElement.getValue();
    // adopt not needed, already adopted in unmarshalElement call above
    return value;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) JAXBElement(javax.xml.bind.JAXBElement)

Example 37 with JAXBElement

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

the class JaxbTestUtil method marshalElementToDom.

public <T> Element marshalElementToDom(JAXBElement<T> jaxbElement, Document doc) throws JAXBException {
    if (doc == null) {
        doc = DOMUtil.getDocument();
    }
    Element element = doc.createElementNS(jaxbElement.getName().getNamespaceURI(), jaxbElement.getName().getLocalPart());
    marshalElementToDom(jaxbElement, element);
    return (Element) element.getFirstChild();
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element)

Example 38 with JAXBElement

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

the class JaxbTestUtil method compareElement.

@SuppressWarnings("unchecked")
private boolean compareElement(Object a, Object b) {
    if (a == b) {
        return true;
    }
    if (a == null && b == null) {
        return true;
    }
    if (a == null || b == null) {
        return false;
    }
    Document doc = null;
    Element ae = null;
    Element be = null;
    if (a instanceof Element) {
        ae = (Element) a;
    } else if (a instanceof JAXBElement) {
        if (doc == null) {
            doc = DOMUtil.getDocument();
        }
        try {
            ae = marshalElementToDom((JAXBElement) a, doc);
        } catch (JAXBException e) {
            throw new IllegalStateException("Failed to marshall element " + a, e);
        }
    } else {
        throw new IllegalArgumentException("Got unexpected type " + a.getClass().getName() + ": " + a);
    }
    if (b instanceof Element) {
        be = (Element) b;
    } else if (a instanceof JAXBElement) {
        if (doc == null) {
            doc = DOMUtil.getDocument();
        }
        try {
            be = marshalElementToDom((JAXBElement) a, doc);
        } catch (JAXBException e) {
            throw new IllegalStateException("Failed to marshall element " + b, e);
        }
    } else {
        throw new IllegalArgumentException("Got unexpected type " + b.getClass().getName() + ": " + b);
    }
    return DOMUtil.compareElement(ae, be, true);
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) Document(org.w3c.dom.Document)

Example 39 with JAXBElement

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

the class JaxbTestUtil method unmarshalElement.

public <T> JAXBElement<T> unmarshalElement(File file, Class<T> type) throws SchemaException, FileNotFoundException, JAXBException {
    if (file == null) {
        throw new IllegalArgumentException("File argument must not be null.");
    }
    InputStream is = null;
    try {
        is = new FileInputStream(file);
        JAXBElement<T> element = (JAXBElement<T>) getUnmarshaller().unmarshal(is);
        adopt(element);
        return element;
    } catch (RuntimeException ex) {
        throw new SystemException(ex);
    } finally {
        if (is != null) {
            IOUtils.closeQuietly(is);
        }
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JAXBElement(javax.xml.bind.JAXBElement) FileInputStream(java.io.FileInputStream)

Example 40 with JAXBElement

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

the class JaxbTestUtil method marshalToDom.

public void marshalToDom(Objectable objectable, Node parentNode) throws JAXBException {
    QName elementQName = determineElementQName(objectable);
    JAXBElement<Object> jaxbElement = new JAXBElement<Object>(elementQName, (Class) objectable.getClass(), objectable);
    marshalElementToDom(jaxbElement, parentNode);
}
Also used : QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)425 ArrayList (java.util.ArrayList)148 Element (org.w3c.dom.Element)115 QName (javax.xml.namespace.QName)102 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)102 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)98 MessageImpl (org.apache.cxf.message.MessageImpl)91 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)90 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)86 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)83 Crypto (org.apache.wss4j.common.crypto.Crypto)82 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)77 TokenProvider (org.apache.cxf.sts.token.provider.TokenProvider)74 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)72 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 Test (org.junit.Test)60 RequestSecurityTokenResponseCollectionType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseCollectionType)58 RequestedSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType)57 Principal (java.security.Principal)55