1 17 package org.apache.servicemix.eip.patterns; 18 19 import javax.jbi.management.DeploymentException; 20 import javax.xml.namespace.NamespaceContext ; 21 import javax.xml.transform.Source ; 22 import javax.xml.transform.dom.DOMSource ; 23 import javax.xml.xpath.XPathFactory ; 24 import javax.xml.xpath.XPathFunctionResolver ; 25 26 import org.apache.servicemix.eip.support.AbstractSplitter; 27 import org.apache.servicemix.expression.JAXPNodeSetXPathExpression; 28 import org.apache.servicemix.expression.MessageVariableResolver; 29 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.NodeList ; 32 33 43 public class XPathSplitter extends AbstractSplitter { 44 45 48 private JAXPNodeSetXPathExpression xpathExpression = new JAXPNodeSetXPathExpression(); 49 50 53 public void validate() throws DeploymentException { 54 super.validate(); 55 try { 57 xpathExpression.afterPropertiesSet(); 58 } catch (Exception e) { 59 throw new DeploymentException("Error validating xpath expression", e); 60 } 61 } 62 63 66 protected Source [] split(Source main) throws Exception { 67 Node doc = new SourceTransformer().toDOMNode(main); 68 NodeList nodes = (NodeList ) xpathExpression.evaluateXPath(doc); 69 Source [] parts = new Source [nodes.getLength()]; 70 for (int i = 0; i < parts.length; i++) { 71 parts[i] = new DOMSource (nodes.item(i)); 72 } 73 return parts; 74 } 75 76 79 public XPathFactory getFactory() { 80 return xpathExpression.getFactory(); 81 } 82 83 86 public XPathFunctionResolver getFunctionResolver() { 87 return xpathExpression.getFunctionResolver(); 88 } 89 90 93 public NamespaceContext getNamespaceContext() { 94 return xpathExpression.getNamespaceContext(); 95 } 96 97 100 public SourceTransformer getTransformer() { 101 return xpathExpression.getTransformer(); 102 } 103 104 107 public MessageVariableResolver getVariableResolver() { 108 return xpathExpression.getVariableResolver(); 109 } 110 111 114 public String getXPath() { 115 return xpathExpression.getXPath(); 116 } 117 118 121 public void setFactory(XPathFactory factory) { 122 xpathExpression.setFactory(factory); 123 } 124 125 128 public void setFunctionResolver(XPathFunctionResolver functionResolver) { 129 xpathExpression.setFunctionResolver(functionResolver); 130 } 131 132 135 public void setNamespaceContext(NamespaceContext namespaceContext) { 136 xpathExpression.setNamespaceContext(namespaceContext); 137 } 138 139 142 public void setTransformer(SourceTransformer transformer) { 143 xpathExpression.setTransformer(transformer); 144 } 145 146 149 public void setVariableResolver(MessageVariableResolver variableResolver) { 150 xpathExpression.setVariableResolver(variableResolver); 151 } 152 153 156 public void setXPath(String xpath) { 157 xpathExpression.setXPath(xpath); 158 } 159 160 } 161 | Popular Tags |