List of usage examples for javax.xml.bind Binder getJAXBNode
public abstract Object getJAXBNode(XmlNode xmlNode);
From source file:org.apache.camel.spring.handler.CamelNamespaceHandler.java
protected void injectNamespaces(Element element, Binder<Node> binder) { NodeList list = element.getChildNodes(); Namespaces namespaces = null;//from w ww.ja v a 2 s . c om int size = list.getLength(); for (int i = 0; i < size; i++) { Node child = list.item(i); if (child instanceof Element) { Element childElement = (Element) child; Object object = binder.getJAXBNode(child); if (object instanceof NamespaceAware) { NamespaceAware namespaceAware = (NamespaceAware) object; if (namespaces == null) { namespaces = new Namespaces(element); } namespaces.configure(namespaceAware); } injectNamespaces(childElement, binder); } } }
From source file:org.apache.camel.spring.handler.CamelNamespaceHandler.java
/** * Used for auto registering endpoints from the <tt>from</tt> or <tt>to</tt> DSL if they have an id attribute set *///from w w w .ja va 2s . c o m protected void registerEndpointsWithIdsDefinedInFromOrToTypes(Element element, ParserContext parserContext, String contextId, Binder<Node> binder) { NodeList list = element.getChildNodes(); int size = list.getLength(); for (int i = 0; i < size; i++) { Node child = list.item(i); if (child instanceof Element) { Element childElement = (Element) child; Object object = binder.getJAXBNode(child); // we only want from/to types to be registered as endpoints if (object instanceof FromDefinition || object instanceof SendDefinition) { registerEndpoint(childElement, parserContext, contextId); } // recursive registerEndpointsWithIdsDefinedInFromOrToTypes(childElement, parserContext, contextId, binder); } } }
From source file:org.docx4j.XmlUtils.java
/** * Fetch DOM node / JAXB object pairs matching an XPath (for example "//w:p"). * /*from w ww .jav a2 s . c om*/ * In JAXB, this association is partial; not all XML elements have associated JAXB objects, * and not all JAXB objects have associated XML elements. * * If the XPath returns an element which isn't associated * with a JAXB object, the element's pair will be null. * * If you have modified your JAXB objects (eg added or changed a * w:p paragraph), you need to update the association. The problem * is that this can only be done ONCE, owing to a bug in JAXB: * see https://jaxb.dev.java.net/issues/show_bug.cgi?id=459 * * So this is left for you to choose to do via the refreshXmlFirst parameter. * * @param binder * @param jaxbElement * @param xpathExpr * @param refreshXmlFirst * @return * @throws JAXBException * @throws XPathBinderAssociationIsPartialException * @since 3.0.0 */ public static List<JAXBAssociation> getJAXBAssociationsForXPath(Binder<Node> binder, Object jaxbElement, String xpathExpr, boolean refreshXmlFirst) throws JAXBException, XPathBinderAssociationIsPartialException { if (binder == null) { log.warn("null binder"); } if (jaxbElement == null) { log.warn("null jaxbElement"); } Node node; if (refreshXmlFirst) { node = binder.updateXML(jaxbElement); } node = binder.getXMLNode(jaxbElement); if (node == null) { throw new XPathBinderAssociationIsPartialException("binder.getXMLNode returned null"); } //log.debug("XPath will execute against: " + XmlUtils.w3CDomNodeToString(node)); List<JAXBAssociation> resultList = new ArrayList<JAXBAssociation>(); for (Node n : xpath(node, xpathExpr)) { resultList.add(new JAXBAssociation(n, binder.getJAXBNode(n))); } return resultList; }