private XmlObject resolveXPath(XmlObject contextXmlObject, String xpath) { if (xpath.isEmpty()) return contextXmlObject; XmlObjectXPathEvaluator xpe = contextXmlObject.getXmlContext().createXPathEvaluator(); try { XmlObject childToAdopt = xpe.selectSingleXmlObjectNode(contextXmlObject, xpath, XmlObject.class); return childToAdopt; } catch (XPathExpressionException xpee) { throw new UncheckedException(String.format("Invalid XPath expression '%s'.", xpath)); } }
@Override public Message findMessage() { XmlObjectXPathEvaluator xpathEvaluator = getXmlContext().createXPathEvaluator(); QName messageQName = getMessage(); try { Message result = xpathEvaluator.selectSingleXmlObjectNode(getXmlObjectBaseRoot(), String.format("//wsdl11:message[@name='%s' and ../@targetNamespace='%s']", messageQName.getLocalPart(), messageQName.getNamespaceURI()), Message.class); return result; } catch (XPathExpressionException xee) { throw new UncheckedException(xee); } }
@Override public PortType findPortType() { XmlObjectXPathEvaluator xpathEvaluator = getXmlContext().createXPathEvaluator(); QName type = getType(); try { PortType result = xpathEvaluator.selectSingleXmlObjectNode(getXmlObjectBaseRoot(), String.format("//wsdl11:portType[@name='%s' and ../@targetNamespace='%s']", type.getLocalPart(), type.getNamespaceURI()), PortType.class); return result; } catch (XPathExpressionException xee) { throw new UncheckedException(xee); } }
@Override public Binding findBinding() { XmlObjectXPathEvaluator xpathEvaluator = getXmlContext().createXPathEvaluator(); QName bindingQName = getBinding(); try { XmlObject root = getXmlObjectRoot(); Binding result = xpathEvaluator.selectSingleXmlObjectNode(root, String.format("//wsdl11:binding[@name='%s' and ../@targetNamespace='%s']", bindingQName.getLocalPart(), bindingQName.getNamespaceURI()), Binding.class); return result; } catch (XPathExpressionException xee) { throw new UncheckedException(xee); } }
@Override public Message findMessage() { XmlObjectXPathEvaluator xpathEvaluator = getXmlContext() .createXPathEvaluator(); QName messageQName = getMessage(); if (messageQName == null) return null; try { Message result = xpathEvaluator.selectSingleXmlObjectNode(getXmlObjectBaseRoot(), String.format("//wsdl11:message[@name='%s' and ../@targetNamespace='%s']", messageQName.getLocalPart(), messageQName.getNamespaceURI()), Message.class); return result; } catch (XPathExpressionException xee) { throw new UncheckedException(xee); } }
public static <T extends BaseElement> T findObjectInDefinitions(Definitions defs, String id, Class<T> wantedClass) throws BPMNException { if (xpe == null) { xpe = defs.getXmlContext().createXPathEvaluator(); } try { return xpe.selectSingleXmlObjectNode(defs, "//*[@id='" + id + "']", wantedClass); } catch (XPathExpressionException e) { throw new BPMNException("No bpmn element has been found for this id : "+id,e); } }
@Override public Element findElement() { XmlObjectXPathEvaluator xpathEvaluator = getXmlContext() .createXPathEvaluator(); QName elementQName = getElement(); if (elementQName == null) return null; try { Element result = xpathEvaluator .selectSingleXmlObjectNode( getXmlObjectBaseRoot(), String.format( "//xs:schema[@targetNamespace='%s']//xs:element[@name='%s']", elementQName.getNamespaceURI(), elementQName.getLocalPart()), Element.class); return result; } catch (XPathExpressionException xee) { throw new UncheckedException(xee); } }