public OMDescendantsIterator(OMContainer container, boolean includeSelf) { super(includeSelf ? (OMSerializable)container : (OMSerializable)container.getFirstOMChild()); level = includeSelf ? 0 : 1; }
protected OMSerializable getNextNode(OMSerializable currentNode) { if (currentNode instanceof OMContainer) { OMNode firstChild = ((OMContainer)currentNode).getFirstOMChild(); if (firstChild != null) { level++; return firstChild; } } OMSerializable node = currentNode; while (true) { if (level == 0) { return null; } OMNode nextSibling = ((OMNode)node).getNextOMSibling(); if (nextSibling != null) { return nextSibling; } else { node = ((OMNode)node).getParent(); level--; } } } }
public final void hasNumberOfChildren(int expected) { OMNode child = getSubject().getFirstOMChild(); int actual = 0; while (child != null) { actual++; child = child.getNextOMSibling(); } if (actual != expected) { failWithRawMessage("number of children is %s instead of %s", actual, expected); } } }
/** * @param node * @return first child or null */ private OMNode _getFirstChild(OMContainer node) { if (isOMSourcedElement(node)) { OMNode first = node.getFirstOMChild(); OMNode sibling = first; while (sibling != null) { sibling = sibling.getNextOMSibling(); } return first; } else { return ((IContainer)node).getFirstOMChildIfAvailable(); } }
public void testSynapse242() throws Exception { // create a new switch mediator XSLTMediator transformMediator = new XSLTMediator(); // set XSLT transformation URL setXsltTransformationURL(transformMediator, "xslt-key"); // invoke transformation, with static enveope MessageContext synCtx = new TestMessageContextBuilder().addFileEntry("xslt-key", "../../repository/conf/sample/resources/transform/transform_load_2.xml") .setBodyFromFile("../../repository/conf/sample/resources/transform/med_message.xml") .addTextAroundBody().setRequireAxis2MessageContext(true).build(); transformMediator.mediate(synCtx); // validate result OMContainer body = synCtx.getEnvelope().getBody(); assertTrue(body.getFirstOMChild().getNextOMSibling() instanceof OMElement); assertTrue(((OMElement) body.getFirstOMChild().getNextOMSibling()).getText().length() > 0); }
public void testTransformXSLTCustomSourceNonMainElement() throws Exception { // create a new switch mediator XSLTMediator transformMediator = new XSLTMediator(); // set xpath condition to select source SynapseXPath xpath = new SynapseXPath("//m0:CheckPriceRequest"); xpath.addNamespace("m0", "http://services.samples/xsd"); transformMediator.setSource(xpath); // set XSLT transformation URL setXsltTransformationURL(transformMediator, "xslt-key"); // invoke transformation, with static enveope MessageContext synCtx = new TestMessageContextBuilder().addFileEntry("xslt-key", "../../repository/conf/sample/resources/transform/transform_unittest.xslt") .setBodyFromString(ENCLOSING_SOURCE) .addTextAroundBody().setRequireAxis2MessageContext(true).build(); transformMediator.mediate(synCtx); // validate result OMContainer body = synCtx.getEnvelope().getBody(); if (body.getFirstOMChild().getNextOMSibling() instanceof OMElement) { OMElement someOtherElem = (OMElement) body.getFirstOMChild().getNextOMSibling(); assertTrue("someOtherElement".equals(someOtherElem.getLocalName())); assertTrue("http://someother".equals(someOtherElem.getNamespace().getNamespaceURI())); assertQuoteElement(someOtherElem.getFirstOMChild()); } else { fail("Unexpected element found in SOAP body"); } }