1 package org.jbpm.bpel.data.xpath; 2 3 import java.util.Collections ; 4 import java.util.List ; 5 6 import org.jaxen.Context; 7 import org.jaxen.FunctionContext; 8 import org.jaxen.JaxenException; 9 import org.jaxen.XPathFunctionContext; 10 import org.jaxen.expr.LocationPath; 11 import org.w3c.dom.Element ; 12 13 import org.jbpm.bpel.xml.util.NodeUtil; 14 15 19 class RelativePath extends XPathScript { 20 21 private static final long serialVersionUID = 1L; 22 23 RelativePath(String snippet) throws JaxenException { 24 super(snippet); 25 } 26 27 protected FunctionContext createFunctionContext() { 28 return XPathFunctionContext.getInstance(); 29 } 30 31 protected Context getContext(Object node) { 32 Context context = new Context(getContextSupport()); 33 Element element = (Element ) node; 34 context.setNodeSet(Collections.singletonList(element)); 35 return context; 36 } 37 38 public Object evaluate(Object contextInfo) { 39 try { 40 List nodeset = selectNodes(contextInfo); 41 return getSingleNode(nodeset); 42 } 43 catch (JaxenException e) { 44 throw new RuntimeException ("Selection failure (internal error)", e); 45 } 46 } 47 48 public void assign(Object contextInfo, Object value) { 49 try { 50 List nodes = selectOrCreateNodes((LocationPath) getRootExpr(), getContext(contextInfo)); 51 NodeUtil.setValue(getSingleNode(nodes), value); 52 } 53 catch (JaxenException e) { 54 throw new RuntimeException ("Selection failure (internal error)", e); 55 } 56 } 57 } 58 | Popular Tags |