1 package org.jbpm.bpel.data.xpath; 2 3 import java.util.Map ; 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 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 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 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 |