summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/policy-builder
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-09-21 18:19:45 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-09-21 18:19:45 +0000
commitca41745086839578dd2497cea2227c0d34d7643a (patch)
tree4c6f03c7b90130305f6d7892c4ca8d85a2d0c136 /java/sca/modules/policy-builder
parent2f3c1011e6029fa969c584709454063498c6d8d7 (diff)
Add a more complicated test scenario
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@817359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java21
-rw-r--r--java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite34
-rw-r--r--java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite33
-rw-r--r--java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite29
-rw-r--r--java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite32
-rw-r--r--java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml38
-rw-r--r--java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odgbin0 -> 15312 bytes
-rw-r--r--java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.pngbin0 -> 4041817 bytes
8 files changed, 184 insertions, 3 deletions
diff --git a/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java b/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java
index 0e82fdd73c..ecd8bfc10b 100644
--- a/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java
+++ b/java/sca/modules/policy-builder/src/main/java/org/apache/tuscany/sca/policy/builder/impl/PolicyAttachmentBuilderImpl.java
@@ -24,6 +24,7 @@ import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE;
import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
import java.io.StringWriter;
+import java.util.Set;
import java.util.StringTokenizer;
import javax.xml.namespace.QName;
@@ -103,14 +104,28 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
boolean changed = false;
for (PolicySet ps : definitions.getPolicySets()) {
+ // First calculate the applicable nodes
+ Set<Node> applicableNodes = null;
+ /*
+ XPathExpression appliesTo = ps.getAppliesToXPathExpression();
+ if (appliesTo != null) {
+ applicableNodes = new HashSet<Node>();
+ NodeList nodes = (NodeList)appliesTo.evaluate(document, XPathConstants.NODESET);
+ for (int i = 0; i < nodes.getLength(); i++) {
+ applicableNodes.add(nodes.item(i));
+ }
+ }
+ */
XPathExpression exp = ps.getAttachToXPathExpression();
if (exp != null) {
NodeList nodes = (NodeList)exp.evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
- // The node can be a component, service, reference or binding
- if (attach(node, ps) && !changed) {
- changed = true;
+ if (applicableNodes == null || applicableNodes.contains(node)) {
+ // The node can be a component, service, reference or binding
+ if (attach(node, ps) && !changed) {
+ changed = true;
+ }
}
}
}
diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite
new file mode 100644
index 0000000000..105a478842
--- /dev/null
+++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Composite1">
+ <include composite="sample:Composite3"/>
+
+ <component name="Component1A">
+ <implementation.java class="sample.Component1AImpl"/>
+ </component>
+
+ <component name="Component1B">
+ <implementation.composite name="sample:Composite4"/>
+ </component>
+
+</composite>
diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite
new file mode 100644
index 0000000000..d3d5bafdfc
--- /dev/null
+++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Composite2">
+
+ <component name="Component2A">
+ <implementation.java class="sample.Component2AImpl"/>
+ </component>
+
+ <component name="Component2B">
+ <implementation.composite name="sample:Composite4"/>
+ </component>
+
+</composite>
diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite
new file mode 100644
index 0000000000..12aa35b694
--- /dev/null
+++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Composite3">
+
+ <component name="Component3A">
+ <implementation.java class="sample.Component3AImpl"/>
+ </component>
+
+</composite>
diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite
new file mode 100644
index 0000000000..141ff2a4ea
--- /dev/null
+++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ name="Composite4">
+
+ <service name="Service1" promote="Component4A/Service1"/>
+ <reference name="reference1" promote="Component4A/reference1"/>
+
+ <component name="Component4A">
+ <implementation.java class="sample.Component4AImpl"/>
+ </component>
+
+</composite>
diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml
new file mode 100644
index 0000000000..7ea9f0b1c5
--- /dev/null
+++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.
+-->
+<definitions
+ xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ targetNamespace="http://sample"
+ xmlns:sample="http://sample"
+ xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
+
+ <policySet name="PolicySet1" appliesTo="sca:composite"
+ attachTo = "//composite[@name='Composite1' or @name='Composite2']">
+ </policySet>
+
+ <policySet name="PolicySet2" appliesTo="sca:implementation.java"
+ attachTo = "//component[@name='Component3A']">
+ </policySet>
+
+ <policySet name="PolicySet3" appliesTo="sca:binding.ws"
+ attachTo = "//sca:component[URIRef('Component2B/Component4A)]">
+ </policySet>
+
+</definitions> \ No newline at end of file
diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg
new file mode 100644
index 0000000000..ccdac84b32
--- /dev/null
+++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg
Binary files differ
diff --git a/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png
new file mode 100644
index 0000000000..94062e1d72
--- /dev/null
+++ b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png
Binary files differ