KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > data > xpath > RelativePath


1 package org.jbpm.bpel.data.xpath;
2
3 import java.util.Collections JavaDoc;
4 import java.util.List JavaDoc;
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 JavaDoc;
12
13 import org.jbpm.bpel.xml.util.NodeUtil;
14
15 /**
16  * @author Alejandro Guízar
17  * @version $Revision: 1.3 $ $Date: 2005/06/23 02:22:46 $
18  */

19 class RelativePath extends XPathScript {
20   
21   private static final long serialVersionUID = 1L;
22
23   RelativePath(String JavaDoc snippet) throws JaxenException {
24     super(snippet);
25   }
26   
27   protected FunctionContext createFunctionContext() {
28     return XPathFunctionContext.getInstance();
29   }
30   
31   protected Context getContext(Object JavaDoc node) {
32     Context context = new Context(getContextSupport());
33     Element JavaDoc element = (Element JavaDoc) node;
34     context.setNodeSet(Collections.singletonList(element));
35     return context;
36   }
37   
38   public Object JavaDoc evaluate(Object JavaDoc contextInfo) {
39     try {
40       List JavaDoc nodeset = selectNodes(contextInfo);
41       return getSingleNode(nodeset);
42     }
43     catch (JaxenException e) {
44       throw new RuntimeException JavaDoc("Selection failure (internal error)", e);
45     }
46   }
47   
48   public void assign(Object JavaDoc contextInfo, Object JavaDoc value) {
49     try {
50       List JavaDoc nodes = selectOrCreateNodes((LocationPath) getRootExpr(), getContext(contextInfo));
51       NodeUtil.setValue(getSingleNode(nodes), value);
52     }
53     catch (JaxenException e) {
54       throw new RuntimeException JavaDoc("Selection failure (internal error)", e);
55     }
56   }
57 }
58
Popular Tags