summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/policy-xml/src/main
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-24 04:51:49 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-24 04:51:49 +0000
commit71b78f6cd040710bcc096bbfcb268c00bf8493d1 (patch)
treec1146e7d68d89fbaa5f72337bda4710f23b40f31 /java/sca/modules/policy-xml/src/main
parent91e330ac2836a87d28688489f2714fdd3c462721 (diff)
Start to implement the @attachTo XPath functions
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@747275 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/policy-xml/src/main')
-rw-r--r--java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java61
-rw-r--r--java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java69
2 files changed, 130 insertions, 0 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
new file mode 100644
index 0000000000..ffabad5644
--- /dev/null
+++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionException;
+
+/**
+ * The SCA-defined XPath function
+ */
+public class PolicyXPathFunction implements XPathFunction {
+ static final QName InterfaceRef = new QName(PolicyConstants.SCA11_NS, "InterfaceRef");
+ static final QName OperationRef = new QName(PolicyConstants.SCA11_NS, "OperationRef");
+ static final QName MessageRef = new QName(PolicyConstants.SCA11_NS, "MessageRef");
+ static final QName IntentRefs = new QName(PolicyConstants.SCA11_NS, "IntentRefs");
+ static final QName URIRef = new QName(PolicyConstants.SCA11_NS, "URIRef");
+
+ static final Set<QName> functions =
+ new HashSet<QName>(Arrays.asList(InterfaceRef, OperationRef, MessageRef, IntentRefs, URIRef));
+
+ private NamespaceContext namespaceContext;
+ private final QName functionName;
+
+ public PolicyXPathFunction(NamespaceContext namespaceContext, QName functionName) {
+ super();
+ this.namespaceContext = namespaceContext;
+ this.functionName = functionName;
+ }
+
+ public Object evaluate(List args) throws XPathFunctionException {
+ // FIXME: [rfeng] To be implemented
+ String arg = (String)args.get(0);
+ System.out.println(functionName + "(" + arg + ")");
+ 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
new file mode 100644
index 0000000000..733b208de7
--- /dev/null
+++ b/java/sca/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathFunction;
+import javax.xml.xpath.XPathFunctionResolver;
+
+/**
+ * A resolver that handles SCA-defined XPath functions
+ *
+ * Interface Related Functions
+ * <ul>
+ * <li>InterfaceRef( InterfaceName )
+ * <li>OperationRef( InterfaceName/OperationName )
+ * <li>MessageRef( InterfaceName/OperationName/MessageName )
+ * </ul>
+ *
+ * Intent Related Functions
+ * <ul>
+ * <li>IntentRefs( IntentList )
+ * </ul>
+ *
+ * URI Based Function
+ * <ul>
+ * <li>URIRef( URI )
+ * </ul>
+ */
+public class PolicyXPathFunctionResolver implements XPathFunctionResolver {
+ private NamespaceContext namespaceContext;
+
+ public PolicyXPathFunctionResolver(NamespaceContext namespaceContext) {
+ super();
+ this.namespaceContext = namespaceContext;
+ }
+
+ public XPathFunction resolveFunction(QName functionName, int arity) {
+ if (functionName == null) {
+ throw new NullPointerException("Function name is null");
+ }
+ if (PolicyXPathFunction.functions.contains(functionName)) {
+ if (arity == 1) {
+ return new PolicyXPathFunction(namespaceContext, functionName);
+ } else {
+ return null;
+ }
+ }
+ return null;
+ }
+
+}