/** * 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(); }
/** * 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) throws JAXBException { Marshaller m = jc.createMarshaller(); try { m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl()); } catch (PropertyException ex) { debug.error("Utils.convertJAXBToElement", ex); } Document doc = null; try { doc = XMLUtils.newDocument(); } catch (Exception ex) { debug.error("Utils.convertJAXBToElement:", ex); } m.marshal(jaxbObj, doc); return doc.getDocumentElement(); }