Author: slaws
Date: Mon Nov 23 16:58:53 2009
New Revision: 883409
URL: http://svn.apache.org/viewvc?rev=883409&view=rev
Log:
For POL_4028 test that a policy isn't being attached to a property element or
one of its children.
Added:
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties
(with props)
Modified:
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
Modified:
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java?rev=883409&r1=883408&r2=883409&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java
Mon Nov 23 16:58:53 2009
@@ -109,55 +109,90 @@
* @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 @@
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;
}
Added:
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties?rev=883409&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties
(added)
+++
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties
Mon Nov 23 16:58:53 2009
@@ -0,0 +1,25 @@
+#
+#
+# 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.
+#
+#
+
+# there are a whole stack of builder related messages that
+# are still yet to be moved here from assembly-validation-messages.properties
+PolicyAttachedToProperty = [POL40002] The policy {0} has been attached to a
property or one of its children. This is not allowed.
+PolicyDOMModelMissmatch = The DOM node which has been found as a result of
evaluating the XPath attachment of policy {0} cannot be mapped back to an
element in the SCA model. The structural URI of the node is {1}
Propchange:
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
tuscany/sca-java-2.x/trunk/modules/builder/src/main/resources/org/apache/tuscany/sca/builder/builder-validation-messages.properties
------------------------------------------------------------------------------
svn:mime-type = text/plain