Search in sources :

Example 1 with NotIdentifiableEvent

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

the class Utils method convertJAXBToElement.

/**
     * Converts a JAXB object to a <code>org.w3c.dom.Element</code>.
     *
     * @param jaxbObj a JAXB object
     * @return a <code>org.w3c.dom.Element</code>
     * @throws JAXBException if an error occurs while converting JAXB object.
     * @supported.api
     */
public static Element convertJAXBToElement(Object jaxbObj, boolean checkIdref) throws JAXBException {
    Marshaller m = jc.createMarshaller();
    try {
        m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
    } catch (PropertyException ex) {
        debug.error("Utils.convertJAXBToElement", ex);
    }
    if (!checkIdref) {
        m.setEventHandler(new DefaultValidationEventHandler() {

            public boolean handleEvent(ValidationEvent event) {
                if (event instanceof NotIdentifiableEvent) {
                    return true;
                }
                return super.handleEvent(event);
            }
        });
    }
    Document doc = null;
    try {
        doc = XMLUtils.newDocument();
    } catch (Exception ex) {
        debug.error("Utils.convertJAXBToElement:", ex);
    }
    m.marshal(jaxbObj, doc);
    return doc.getDocumentElement();
}
Also used : Marshaller(javax.xml.bind.Marshaller) PropertyException(javax.xml.bind.PropertyException) ValidationEvent(javax.xml.bind.ValidationEvent) DefaultValidationEventHandler(javax.xml.bind.helpers.DefaultValidationEventHandler) Document(org.w3c.dom.Document) NotIdentifiableEvent(javax.xml.bind.NotIdentifiableEvent) PropertyException(javax.xml.bind.PropertyException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 NotIdentifiableEvent (javax.xml.bind.NotIdentifiableEvent)1 PropertyException (javax.xml.bind.PropertyException)1 ValidationEvent (javax.xml.bind.ValidationEvent)1 DefaultValidationEventHandler (javax.xml.bind.helpers.DefaultValidationEventHandler)1 Document (org.w3c.dom.Document)1