summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/policy/src/main
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-07-08 17:13:15 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2008-07-08 17:13:15 +0000
commit81fd31c03081719efb23bf1de579381875dcabfc (patch)
treee5b5bf318364dbf73a897a320f4a5516397a929c /java/sca/modules/policy/src/main
parent85f5a5467d5b5f1f44da7e7c4ae296ef8ffe2e5e (diff)
TUSCANY-2464 - Applying Greg's patch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@674885 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/policy/src/main')
-rw-r--r--java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java55
1 files changed, 22 insertions, 33 deletions
diff --git a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java
index 18bb273589..1c56cbacbc 100644
--- a/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java
+++ b/java/sca/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java
@@ -231,15 +231,13 @@ public class PolicyComputationUtils {
private static byte[] addApplicablePolicySets(Document doc, Collection<PolicySet> policySets)
throws XPathExpressionException, TransformerConfigurationException, TransformerException {
- int prefixCount = 1;
-
for (PolicySet policySet : policySets) {
if (policySet.getAppliesTo() != null) {
- addApplicablePolicySets(policySet, doc, prefixCount);
+ addApplicablePolicySets(policySet, doc);
}
if (policySet.getAlwaysAppliesTo() != null) {
- addAlwaysApplicablePolicySets(policySet, doc, prefixCount);
+ addAlwaysApplicablePolicySets(policySet, doc);
}
}
@@ -265,8 +263,7 @@ public class PolicyComputationUtils {
}
private static void addAlwaysApplicablePolicySets(PolicySet policySet,
- Document doc,
- int prefixCount) throws XPathExpressionException {
+ Document doc) throws XPathExpressionException {
XPathExpression expression = policySet.getAlwaysAppliesToXPathExpression();
NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);
@@ -275,14 +272,11 @@ public class PolicyComputationUtils {
Node aResultNode = result.item(counter);
String alwaysApplicablePolicySets = null;
- String policySetPrefix = POLICYSET_PREFIX + prefixCount++;
- String policySetsAttrPrefix = "sca";
-
- policySetPrefix =
- declareNamespace((Element)aResultNode, policySetPrefix, policySet.getName()
- .getNamespaceURI());
- policySetsAttrPrefix =
- declareNamespace((Element)aResultNode, policySetsAttrPrefix, SCA10_NS);
+
+ String policySetPrefix =
+ declareNamespace((Element)aResultNode, policySet.getName().getNamespaceURI());
+ String policySetsAttrPrefix =
+ declareNamespace((Element)aResultNode, SCA10_NS);
if (aResultNode.getAttributes().getNamedItem(POLICY_SETS_ATTR) != null) {
alwaysApplicablePolicySets =
aResultNode.getAttributes().getNamedItem(POLICY_SETS_ATTR).getNodeValue();
@@ -305,8 +299,7 @@ public class PolicyComputationUtils {
}
private static void addApplicablePolicySets(PolicySet policySet,
- Document doc,
- int prefixCount) throws XPathExpressionException {
+ Document doc) throws XPathExpressionException {
XPathExpression expression = policySet.getAppliesToXPathExpression();
NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);
@@ -315,15 +308,11 @@ public class PolicyComputationUtils {
Node aResultNode = result.item(counter);
String applicablePolicySets = null;
- String policySetPrefix = POLICYSET_PREFIX + prefixCount++;
- String appPolicyAttrPrefix = APPLICABLE_POLICYSET_ATTR_PREFIX;
- policySetPrefix =
- declareNamespace((Element)aResultNode, policySetPrefix, policySet.getName()
- .getNamespaceURI());
- appPolicyAttrPrefix =
+ String policySetPrefix =
+ declareNamespace((Element)aResultNode, policySet.getName().getNamespaceURI());
+ String appPolicyAttrPrefix =
declareNamespace((Element)aResultNode,
- appPolicyAttrPrefix,
APPLICABLE_POLICYSET_ATTR_NS);
if (aResultNode.getAttributes().getNamedItemNS(APPLICABLE_POLICYSET_ATTR_NS,
APPLICABLE_POLICYSET_ATTR) != null) {
@@ -385,20 +374,12 @@ public class PolicyComputationUtils {
}
- private static String declareNamespace(Element element, String prefix, String ns) {
+ private static String declareNamespace(Element element, String ns) {
if (ns == null) {
ns = "";
}
- if (prefix == null) {
- prefix = "";
- }
- String qname = null;
- if ("".equals(prefix)) {
- qname = "xmlns";
- } else {
- qname = "xmlns:" + prefix;
- }
Node node = element;
+ String prefix = "";
boolean declared = false;
while (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
if ( node.lookupPrefix(ns) != null ) {
@@ -419,6 +400,14 @@ public class PolicyComputationUtils {
}
}
if (!declared) {
+ // Find an available prefix
+ for (int i=1; ; i++) {
+ prefix = POLICYSET_PREFIX + i;
+ if (element.lookupNamespaceURI(prefix) == null) {
+ break;
+ }
+ }
+ String qname = "xmlns:" + prefix;
org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname);
attr.setValue(ns);
element.setAttributeNodeNS(attr);