From ca41745086839578dd2497cea2227c0d34d7643a Mon Sep 17 00:00:00 2001 From: rfeng Date: Mon, 21 Sep 2009 18:19:45 +0000 Subject: Add a more complicated test scenario git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@817359 13f79535-47bb-0310-9956-ffa450edef68 --- .../builder/impl/PolicyAttachmentBuilderImpl.java | 21 ++++++++++-- .../sca/policy/builder/impl/Composite1.composite | 34 ++++++++++++++++++ .../sca/policy/builder/impl/Composite2.composite | 33 ++++++++++++++++++ .../sca/policy/builder/impl/Composite3.composite | 29 ++++++++++++++++ .../sca/policy/builder/impl/Composite4.composite | 32 +++++++++++++++++ .../sca/policy/builder/impl/definitions.xml | 38 +++++++++++++++++++++ .../tuscany/sca/policy/builder/impl/scenario.odg | Bin 0 -> 15312 bytes .../tuscany/sca/policy/builder/impl/scenario.png | Bin 0 -> 4041817 bytes 8 files changed, 184 insertions(+), 3 deletions(-) create mode 100644 java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite1.composite create mode 100644 java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite2.composite create mode 100644 java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite3.composite create mode 100644 java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/Composite4.composite create mode 100644 java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/definitions.xml create mode 100644 java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg create mode 100644 java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png (limited to 'java/sca') 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 applicableNodes = null; + /* + XPathExpression appliesTo = ps.getAppliesToXPathExpression(); + if (appliesTo != null) { + applicableNodes = new HashSet(); + 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 @@ + + + + + + + + + + + + + + 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 @@ + + + + + + + + + + + + + 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 @@ + + + + + + + + + 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 @@ + + + + + + + + + + + + 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 @@ + + + + + + + + + + + + + + \ 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 Binary files /dev/null and b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.odg 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 Binary files /dev/null and b/java/sca/modules/policy-builder/src/test/resources/org/apache/tuscany/sca/policy/builder/impl/scenario.png differ -- cgit v1.2.3