1 package org.jbpm.bpel.data.xpath; 2 3 import java.util.List ; 4 5 import javax.xml.namespace.QName ; 6 7 import org.jaxen.*; 8 import org.jaxen.function.StringFunction; 9 10 import org.jbpm.bpel.data.exe.MessageVariableInstance; 11 import org.jbpm.bpel.data.exe.VariableInstance; 12 13 21 public class GetVariablePropertyFunction implements Function { 22 23 public Object call(Context context, List args) throws FunctionCallException { 24 if (args.size() != 2) { 25 throw new FunctionCallException("getVariableProperty() requires two arguments"); 26 } 27 return evaluate(args.get(0), args.get(1), context); 28 } 29 30 public static Object evaluate(Object variableArg, Object propertyArg, Context context) 31 throws FunctionCallException { 32 Navigator nav = context.getNavigator(); 34 String variableName = StringFunction.evaluate(variableArg, nav); 35 String propertyName = StringFunction.evaluate(propertyArg, nav); 36 ContextSupport sup = context.getContextSupport(); 38 NamespaceContext nsContext = sup.getNamespaceContext(); 39 QName propertyQName = toQName(propertyName, nsContext); 40 ScopeVariables variables = (ScopeVariables) sup.getVariableContext(); 42 VariableInstance instance = variables.getVariable(variableName); 43 if (instance == null) { 44 throw new FunctionCallException("variable not found: " + variableName); 45 } 46 if (!(instance instanceof MessageVariableInstance)) { 47 throw new FunctionCallException("variable does not have a message type: " + variableName); 48 } 49 return ((MessageVariableInstance) instance).getProperty(propertyQName); 51 } 52 53 public static QName toQName(String prefixedName, NamespaceContext namespaceContext) { 54 QName qName; 55 int colonIndex = prefixedName.indexOf(':'); 56 if (colonIndex == -1) { 57 qName = new QName (prefixedName); 58 } 59 else { 60 String name = prefixedName.substring(colonIndex + 1); 61 String prefix = prefixedName.substring(0, colonIndex); 62 String uri = namespaceContext.translateNamespacePrefixToUri(prefix); 63 qName = new QName (uri, name, prefix); 64 } 65 return qName; 66 } 67 } 68 | Popular Tags |