summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java48
-rw-r--r--java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java2
-rw-r--r--java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java45
3 files changed, 86 insertions, 9 deletions
diff --git a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
index ffabad5644..f015fc90fb 100644
--- a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
+++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
@@ -52,9 +52,55 @@ public class PolicyXPathFunction implements XPathFunction {
}
public Object evaluate(List args) throws XPathFunctionException {
+ System.out.println(functionName + "(" + args + ")");
// FIXME: [rfeng] To be implemented
String arg = (String)args.get(0);
- System.out.println(functionName + "(" + arg + ")");
+ if (InterfaceRef.equals(functionName)) {
+ return evaluateInterface(arg);
+ } else if (OperationRef.equals(functionName)) {
+ String[] params = arg.split("/");
+ if (params.length != 2) {
+ throw new IllegalArgumentException("Invalid argument: " + arg);
+ }
+ String interfaceName = params[0];
+ String operationName = params[1];
+ return evaluateOperation(interfaceName, operationName);
+ } else if (MessageRef.equals(functionName)) {
+ String[] params = arg.split("/");
+ if (params.length != 3) {
+ throw new IllegalArgumentException("Invalid argument: " + arg);
+ }
+ String interfaceName = params[0];
+ String operationName = params[1];
+ String messageName = params[2];
+ return evaluateMessage(interfaceName, operationName, messageName);
+ } else if (URIRef.equals(functionName)) {
+ return evaluateURI(arg);
+ } else if (IntentRefs.equals(functionName)) {
+ String[] intents = arg.split("(\\s)+");
+ return evaluateIntents(intents);
+ } else {
+ return Boolean.FALSE;
+ }
+ }
+
+ private Boolean evaluateInterface(String interfaceName) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateOperation(String interfaceName, String operationName) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateMessage(String interfaceName, String operationName, String messageName) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateURI(String uri) {
+ return Boolean.FALSE;
+ }
+
+ private Boolean evaluateIntents(String[] intents) {
return Boolean.FALSE;
}
diff --git a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
index 733b208de7..2d04a27cd7 100644
--- a/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
+++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
@@ -60,7 +60,7 @@ public class PolicyXPathFunctionResolver implements XPathFunctionResolver {
if (arity == 1) {
return new PolicyXPathFunction(namespaceContext, functionName);
} else {
- return null;
+ throw new IllegalArgumentException("Invalid number of arguments: " + arity);
}
}
return null;
diff --git a/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java b/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
index fea1afb941..7b647819b4 100644
--- a/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
+++ b/java/sca/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolverTestCase.java
@@ -39,28 +39,59 @@ import org.xml.sax.InputSource;
*
*/
public class PolicyXPathFunctionResolverTestCase {
- private static XPathFactory factory;
+ private static XPath xpath;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
- factory = XPathFactory.newInstance();
+ XPathFactory factory = XPathFactory.newInstance();
+ xpath = factory.newXPath();
+ xpath.setNamespaceContext(new NamespaceContextImpl());
+ xpath.setXPathFunctionResolver(new PolicyXPathFunctionResolver(xpath.getNamespaceContext()));
}
@Test
- public void testXPath() throws Exception {
- XPath xpath = factory.newXPath();
- xpath.setNamespaceContext(new NamespaceContextImpl());
- xpath.setXPathFunctionResolver(new PolicyXPathFunctionResolver(xpath.getNamespaceContext()));
+ public void testIntentsRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile("//sca:composite/sca:component[sca:IntentRefs('sca:confidentiality')]");
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
+ @Test
+ public void testURIRef() throws Exception {
InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
- XPathExpression exp = xpath.compile("//sca:composite//sca:component[sca:IntentRefs('sca:confidentiality')]");
+ XPathExpression exp = xpath.compile("sca:composite/sca:component[sca:URIRef('AddServiceComponent')]");
Object result = exp.evaluate(xml, XPathConstants.NODESET);
Assert.assertTrue(result instanceof NodeList);
NodeList nodes = (NodeList)result;
// Assert.assertEquals(1, nodes.getLength());
}
+
+ @Test
+ public void testInterfaceRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile("//sca:composite/sca:component/sca:service[sca:InterfaceRef('AddService')]");
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
+ @Test
+ public void testOperationRef() throws Exception {
+ InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
+ XPathExpression exp = xpath.compile("//sca:composite/sca:component/sca:reference[sca:OperationRef('AddService/add')]");
+ Object result = exp.evaluate(xml, XPathConstants.NODESET);
+ Assert.assertTrue(result instanceof NodeList);
+ NodeList nodes = (NodeList)result;
+ // Assert.assertEquals(1, nodes.getLength());
+ }
+
/**
* @throws java.lang.Exception