summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-11-23 16:58:53 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2009-11-23 16:58:53 +0000
commit9c9214b9d88dddf680e0ad4ba82d86f3b0459627 (patch)
tree7594307b9acf6f6a7c6cff962525ec96329e95e0 /sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca
parentcc4acbfe1db724dfe8604a831a761d239eaa766f (diff)
For POL_4028 test that a policy isn't being attached to a property element or one of its children.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@883409 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca')
-rw-r--r--sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java121
1 files changed, 80 insertions, 41 deletions
diff --git a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
index cbbf54b330..9b21de3354 100644
--- a/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
+++ b/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
@@ -109,55 +109,90 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
* @throws Exception
*/
private Composite applyXPath(Composite composite, Definitions definitions, Monitor monitor) throws Exception {
- if (definitions == null || definitions.getPolicySets().isEmpty()) {
- return composite;
- }
- // Recursively apply the xpath against the composites referenced by <implementation.composite>
- for (Component component : composite.getComponents()) {
- Implementation impl = component.getImplementation();
- if (impl instanceof Composite) {
- Composite patched = applyXPath((Composite)impl, definitions, monitor);
- if (patched != impl) {
- component.setImplementation(patched);
- }
- }
- }
- Document document = null;
- 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));
+ monitor.pushContext("Composite: " + composite.getName().toString());
+
+ try {
+ if (definitions == null || definitions.getPolicySets().isEmpty()) {
+ return composite;
+ }
+ // Recursively apply the xpath against the composites referenced by <implementation.composite>
+ for (Component component : composite.getComponents()) {
+ Implementation impl = component.getImplementation();
+ if (impl instanceof Composite) {
+ Composite patched = applyXPath((Composite)impl, definitions, monitor);
+ if (patched != impl) {
+ component.setImplementation(patched);
+ }
}
}
- */
- XPathExpression exp = ps.getAttachToXPathExpression();
- if (exp != null) {
- if (document == null) {
- document = saveAsDOM(composite);
+ Document document = null;
+
+ 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));
+ }
}
- NodeList nodes = (NodeList)exp.evaluate(document, XPathConstants.NODESET);
- for (int i = 0; i < nodes.getLength(); i++) {
- Node node = nodes.item(i);
- if (applicableNodes == null || applicableNodes.contains(node)) {
- // The node can be a component, service, reference or binding
- String index = getStructuralURI(node);
- PolicySubject subject = lookup(composite, index);
- if (subject != null) {
- subject.getPolicySets().add(ps);
+ */
+ XPathExpression exp = ps.getAttachToXPathExpression();
+ if (exp != null) {
+ if (document == null) {
+ document = saveAsDOM(composite);
+ }
+ NodeList nodes = (NodeList)exp.evaluate(document, XPathConstants.NODESET);
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+
+ // POL_40002 - you can't attach a policy to a property node
+ // or one of it's children
+ // walk backwards up the node tree looking for an element called property
+ // and raise an error if we find one
+ Node testNode = node;
+ while (testNode != null){
+ if ((node.getNodeType() == Node.ELEMENT_NODE) &&
+ (node.getLocalName().equals("property"))){
+ Monitor.error(monitor,
+ this,
+ "org.apache.tuscany.sca.builder.builder-validation-messages",
+ "PolicyAttachedToProperty",
+ ps.getName().toString());
+ break;
+ }
+ testNode = testNode.getParentNode();
+ }
+
+ if (applicableNodes == null || applicableNodes.contains(node)) {
+ // The node can be a component, service, reference or binding
+ String index = getStructuralURI(node);
+ PolicySubject subject = lookup(composite, index);
+ if (subject != null) {
+ subject.getPolicySets().add(ps);
+ } else {
+ // raise a warning that the XPath node didn't match a node in the
+ // models
+ Monitor.warning(monitor,
+ this,
+ "org.apache.tuscany.sca.builder.builder-validation-messages",
+ "PolicyDOMModelMissmatch",
+ ps.getName().toString(),
+ index);
+ }
}
}
}
}
- }
-
- return composite;
+
+ return composite;
+ } finally {
+ monitor.popContext();
+ }
}
private Document saveAsDOM(Composite composite) throws XMLStreamException, ContributionWriteException, IOException,
@@ -170,6 +205,10 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder {
writer.close();
Document document = domHelper.load(sw.toString());
+
+ // Debugging
+ //System.out.println("<!-- DOM to which XPath will be applies is -->\n" + sw.toString());
+
return document;
}