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;
}
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();
}
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);
}
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);
}
}
}
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);
}
Aggregations