KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.data.xpath;
2
3 import java.util.Map JavaDoc;
4
5 import org.jaxen.JaxenException;
6 import org.jaxen.SimpleNamespaceContext;
7
8 import org.jbpm.bpel.data.def.Snippet;
9 import org.jbpm.bpel.data.spi.Script;
10 import org.jbpm.bpel.data.spi.ScriptFactory;
11 import org.jbpm.bpel.xml.BpelException;
12
13 /**
14  * A factory for expressions and queries written in XPath 1.0.
15  * @author Alejandro Guízar
16  * @version $Revision: 1.3 $ $Date: 2005/06/16 19:15:35 $
17  */

18 public class XPathFactory extends ScriptFactory {
19   
20   private static final XPathFactory instance = new XPathFactory();
21   
22   public Script createScript(Snippet expression) {
23     Snippet.Use use = expression.getUse();
24     String JavaDoc snippet = expression.getText();
25     try {
26       XPathScript expressionPeer;
27       if (use == Snippet.Use.EXPRESSION) {
28         expressionPeer = XPathScript.createExpression(snippet);
29       }
30       else if (use == Snippet.Use.QUERY) {
31         expressionPeer = XPathScript.createQuery(snippet);
32       }
33       else if (use == Snippet.Use.JOIN_CONDITION) {
34         expressionPeer = XPathScript.createJoinCondition(snippet);
35       }
36       else if (use == Snippet.Use.PROPERTY_ALIAS) {
37         expressionPeer = XPathScript.createPropertyAlias(snippet);
38       }
39       else {
40         throw new BpelException("xpath does not support the specified use");
41       }
42       Map JavaDoc namespaces = expression.getNamespaces();
43       if (namespaces != null) {
44         expressionPeer.setNamespaceContext(new SimpleNamespaceContext(namespaces));
45       }
46       return expressionPeer;
47     }
48     catch (JaxenException e) {
49       throw new BpelException(e.getMessage(), e);
50     }
51   }
52   
53   public static ScriptFactory getInstance() {
54     return instance;
55   }
56 }
57
Popular Tags