Author: sanka
Date: Thu May  4 05:03:42 2006
New Revision: 399684

URL: http://svn.apache.org/viewcvs?rev=399684&view=rev
Log:
apply the patch. see:http://issues.apache.org/jira/browse/WSCOMMONS-14

Modified:
    webservices/commons/trunk/modules/neethi/project.properties
    webservices/commons/trunk/modules/neethi/project.xml
    
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java
    
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/PolicyConstants.java
    
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/DOMPolicyReader.java
    
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/OMPolicyReader.java
    
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/StAXPolicyWriter.java

Modified: webservices/commons/trunk/modules/neethi/project.properties
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/neethi/project.properties?rev=399684&r1=399683&r2=399684&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/project.properties (original)
+++ webservices/commons/trunk/modules/neethi/project.properties Thu May  4 
05:03:42 2006
@@ -17,11 +17,8 @@
 maven.xdoc.date=left
 ## maven.xdoc.version=${pom.currentVersion}
 
-neethi.version=1.0.1
-axiom.api.artifactid=axiom-api
-axiom.api.version=1.0
-axiom.impl.artifactid=axiom-impl
-axiom.impl.version=1.0
+neethi.version=SNAPSHOT
+axiom.version=SNAPSHOT
 stax.api.version=1.0
 stax.impl.groupid=stax
 stax.impl.artifactid=stax

Modified: webservices/commons/trunk/modules/neethi/project.xml
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/neethi/project.xml?rev=399684&r1=399683&r2=399684&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/project.xml (original)
+++ webservices/commons/trunk/modules/neethi/project.xml Thu May  4 05:03:42 
2006
@@ -100,13 +100,8 @@
        <dependencies>
                <dependency>
                        <groupId>ws-commons</groupId>
-                       <artifactId>${axiom.api.artifactid}</artifactId>
-                       <version>${axiom.api.version}</version>
-               </dependency>
-               <dependency>
-                       <groupId>ws-commons</groupId>
-                       <artifactId>${axiom.impl.artifactid}</artifactId>
-                       <version>${axiom.impl.version}</version>
+                       <artifactId>axiom</artifactId>
+                       <version>${axiom.version}</version>
                </dependency>
                <dependency>
                        <groupId>${stax.impl.groupid}</groupId>

Modified: 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java?rev=399684&r1=399683&r2=399684&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java 
(original)
+++ 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java 
Thu May  4 05:03:42 2006
@@ -17,9 +17,12 @@
 package org.apache.ws.policy;
 
 import java.util.ArrayList;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 
+import javax.xml.namespace.QName;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.policy.util.PolicyRegistry;
@@ -30,332 +33,399 @@
  * its terms are met.
  */
 public class Policy extends AbstractAssertion implements CompositeAssertion {
-       private Log log = LogFactory.getLog(this.getClass().getName());
+    private Log log = LogFactory.getLog(this.getClass().getName());
 
-       private String xmlBase = null;
+    private Hashtable attributes = new Hashtable();
 
-       /** Stores the Id of the policy */
-       private String id = null;
+    /**
+     * Creates a policy object
+     */
+    public Policy() {
+    }
+
+    /**
+     * Creates a policy object with the specified Id
+     * 
+     * @param id
+     *            a string as the id
+     */
+    public Policy(String id) {
+        this(null, id);
+        setNormalized(false);
+    }
+
+    /**
+     * Creates a policy object with the specified xml-base and id.
+     * 
+     * @param xmlBase
+     *            the xml-base
+     * @param id
+     *            a string as the id
+     */
+    public Policy(String xmlBase, String id) {
+        setBase(xmlBase);
+        setId(id);
+        setNormalized(false);
+    }
+
+    /**
+     * Set the xml-base of the policy object
+     * 
+     * @param xmlBase
+     *            the xml base of the policy object
+     */
+    public void setBase(String xmlBase) {
+        addAttribute(new QName(PolicyConstants.XML_NAMESPACE_URI,
+                PolicyConstants.WS_POLICY_BASE), xmlBase);
+    }
+
+    /**
+     * Returns the xml-base of the policy object. Returns null if no xml-base 
is
+     * set.
+     * 
+     * @return xml base of the policy object
+     */
+    public String getBase() {
+        return (String) getAttribute(new QName(
+                PolicyConstants.XML_NAMESPACE_URI,
+                PolicyConstants.WS_POLICY_BASE));
+    }
+
+    /**
+     * Sets the id of the Policy object
+     * 
+     * @param id
+     */
+    public void setId(String id) {
+        addAttribute(new QName(PolicyConstants.WS_POLICY_NAMESPACE_URI,
+                PolicyConstants.WS_POLICY_ID), id);
+    }
+
+    /**
+     * Returns the Id of the Policy object. Returns null if no Id is set.
+     * 
+     * @return the Id of the policy object.
+     */
+    public String getId() {
+        return (String) getAttribute(new QName(
+                PolicyConstants.WS_POLICY_NAMESPACE_URI,
+                PolicyConstants.WS_POLICY_ID));
+    }
+
+    /**
+     * Returns a String which uniquely identify the policy object. It has the
+     * format of {$xmlBase}#{$id}. If the xmlBase is null it will return #{$id}
+     * as the URI String. If the Id is null, this will return.
+     * 
+     * @return a String which uniquely identify the policy object.
+     */
+    public String getPolicyURI() {
+        if (getId() != null) {
+            if (getBase() != null) {
+                return getBase() + "#" + getId();
+            }
+            return "#" + getId();
+        }
+        return null;
+    }
+
+    public Assertion normalize() {
+        return normalize(null);
+    }
+
+    public Assertion normalize(PolicyRegistry reg) {
+        log.debug("Enter: Policy::normalize");
+
+        if (isNormalized()) {
+            return this;
+        }
+
+        String xmlBase = getBase();
+        String id = getId();
+        Policy policy = new Policy(xmlBase, id);
+
+        AndCompositeAssertion AND = new AndCompositeAssertion();
+        XorCompositeAssertion XOR = new XorCompositeAssertion();
+
+        ArrayList childAndTermList = new ArrayList();
+        ArrayList childXorTermList = new ArrayList();
+
+        Iterator terms = getTerms().iterator();
+        Assertion term;
+
+        while (terms.hasNext()) {
+            term = (Assertion) terms.next();
+            term = term.normalize(reg);
+
+            if (term instanceof Policy) {
+                XorCompositeAssertion Xor = (XorCompositeAssertion) ((Policy) 
term)
+                        .getTerms().get(0);
+
+                if (Xor.size() != 1) {
+                    term = Xor;
+
+                } else {
+                    AND
+                            .addTerms(((AndCompositeAssertion) Xor.getTerms()
+                                    .get(0)).getTerms());
+                    continue;
+                }
+            }
+
+            if (term instanceof XorCompositeAssertion) {
+
+                if (((XorCompositeAssertion) term).isEmpty()) {
+                    XorCompositeAssertion emptyXor = new 
XorCompositeAssertion();
+                    emptyXor.setNormalized(true);
+
+                    policy.addTerm(emptyXor);
+                    policy.setNormalized(true);
+
+                    return policy;
+                }
+
+                childXorTermList.add(term);
+                continue;
+            }
+
+            if (term instanceof AndCompositeAssertion) {
+
+                if (((AndCompositeAssertion) term).isEmpty()) {
+                    AndCompositeAssertion emptyAnd = new 
AndCompositeAssertion();
+                    XOR.addTerm(emptyAnd);
+
+                } else {
+                    AND.addTerms(((AndCompositeAssertion) term).getTerms());
+                }
+                continue;
+            }
+            AND.addTerm((Assertion) term);
+        }
+
+        // processing child-XORCompositeAssertions
+        if (childXorTermList.size() > 1) {
+
+            for (int i = 0; i < childXorTermList.size(); i++) {
+
+                for (int j = i; j < childXorTermList.size(); j++) {
+
+                    if (i != j) {
+                        XorCompositeAssertion xorTermA = 
(XorCompositeAssertion) childXorTermList
+                                .get(i);
+                        XorCompositeAssertion xorTermB = 
(XorCompositeAssertion) childXorTermList
+                                .get(j);
+
+                        Iterator iterA = xorTermA.getTerms().iterator();
+
+                        while (iterA.hasNext()) {
+                            Assertion andTermA = (Assertion) iterA.next();
+
+                            Iterator iterB = xorTermB.getTerms().iterator();
+
+                            while (iterB.hasNext()) {
+                                Assertion andTermB = (Assertion) iterB.next();
+                                AndCompositeAssertion anAndTerm = new 
AndCompositeAssertion();
+                                anAndTerm.addTerms(andTermA.getTerms());
+                                anAndTerm.addTerms(andTermB.getTerms());
+                                XOR.addTerm(anAndTerm);
+                            }
+                        }
+                    }
+                }
+            }
+
+        } else if (childXorTermList.size() == 1) {
+            Assertion xorTerm = (Assertion) childXorTermList.get(0);
+            XOR.addTerms(xorTerm.getTerms());
+        }
+
+        if (childXorTermList.isEmpty()) {
+            XorCompositeAssertion xor = new XorCompositeAssertion();
+
+            xor.addTerm(AND);
+            policy.addTerm(xor);
+            policy.setNormalized(true);
+            return policy;
+        }
+
+        List primTerms = AND.getTerms();
+        Iterator andTerms = XOR.getTerms().iterator();
+
+        while (andTerms.hasNext()) {
+            Assertion anAndTerm = (Assertion) andTerms.next();
+            anAndTerm.addTerms(primTerms);
+        }
+
+        policy.addTerm(XOR);
+        policy.setNormalized(true);
+        return policy;
+    }
+
+    public Assertion intersect(Assertion assertion, PolicyRegistry reg) {
+        log.debug("Enter: Policy::intersect");
+
+        Assertion normalizedMe = (isNormalized()) ? this : normalize(reg);
+        if (!(normalizedMe instanceof Policy)) {
+            return normalizedMe.intersect(assertion, reg);
+        }
+
+        Assertion target = (assertion.isNormalized()) ? assertion : assertion
+                .normalize(reg);
+        short type = target.getType();
+
+        switch (type) {
+        case Assertion.COMPOSITE_POLICY_TYPE: {
+            Policy nPOLICY = new Policy();
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).intersect((XorCompositeAssertion) target
+                    .getTerms().get(0)));
+            return nPOLICY;
+        }
+        case Assertion.COMPOSITE_XOR_TYPE: {
+            Policy nPOLICY = new Policy();
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).intersect(target));
+            return nPOLICY;
+        }
+        case Assertion.COMPOSITE_AND_TYPE: {
+            Policy nPOLICY = new Policy();
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).intersect(target));
+            return nPOLICY;
+        }
+        case Assertion.PRIMITIVE_TYPE: {
+            Policy nPOLICY = new Policy();
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).intersect(target));
+            return nPOLICY;
+        }
+
+        default: {
+            throw new IllegalArgumentException("intersect is not defined for "
+                    + target.getClass().getName() + " type");
+        }
+
+        }
+    }
+
+    public Assertion merge(Assertion assertion, PolicyRegistry reg) {
+        log.debug("Enter: Policy::merge");
+
+        Assertion normalizedMe = (isNormalized()) ? this : normalize(reg);
+
+        if (!(normalizedMe instanceof Policy)) {
+            return normalizedMe.merge(assertion, reg);
+        }
+
+        Policy nPOLICY = new Policy();
+
+        Assertion target = (assertion.isNormalized()) ? assertion : assertion
+                .normalize(reg);
+        short type = target.getType();
+
+        switch (type) {
+
+        case Assertion.COMPOSITE_POLICY_TYPE: {
+
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).merge((XorCompositeAssertion) target.getTerms()
+                    .get(0)));
+            return nPOLICY;
+        }
+        case Assertion.COMPOSITE_XOR_TYPE: {
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).merge(target));
+            return nPOLICY;
+        }
+
+        case Assertion.COMPOSITE_AND_TYPE: {
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).merge(target));
+            return nPOLICY;
+        }
+
+        case Assertion.PRIMITIVE_TYPE: {
+            nPOLICY.addTerm(((XorCompositeAssertion) normalizedMe.getTerms()
+                    .get(0)).merge(target));
+            return nPOLICY;
+        }
+
+        default: {
+            throw new IllegalArgumentException(" merge for "
+                    + target.getClass().getName() + " not defined");
+        }
+
+        }
+    }
+
+    /**
+     * Returns a short value which indicates this is a Policy.
+     */
+    public final short getType() {
+        return Assertion.COMPOSITE_POLICY_TYPE;
+    }
+
+    /**
+     * Replaces all the attributes for this Policy from a single Hashtable.
+     * 
+     * @param attributes
+     *            A Hashtable containing the attributes for this Policy as
+     *            name/value pairs.
+     */
+    public void setAttributes(Hashtable attributes) {
+        this.attributes = attributes;
+    }
+
+    /**
+     * Returns all of the attributes for this Policy as a Hashtable.
+     * 
+     * @return Hashtable containing the attributes for this Policy as 
name/value
+     *         pairs.
+     */
+    public Hashtable getAttributes() {
+        return attributes;
+    }
+
+    /**
+     * Adds an attribute to the Policy.
+     * 
+     * @param qname
+     *            The QName of the attribute.
+     * @param value
+     *            The value of attribute expressed as a String.
+     */
+    public void addAttribute(QName qname, String value) {
+        if (value != null) {
+            attributes.put(qname, value);
+        }
+    }
+
+    /**
+     * Returns a specified attribute value.
+     * 
+     * @param qname
+     *            The QName of the attribute.
+     * @return String The value of the attribute.
+     */
+    public String getAttribute(QName qname) {
+        return (String) attributes.get(qname);
+    }
+
+    /**
+     * Removes a specified attribute from the Policy.
+     * 
+     * @param qname
+     *            The QName of the attribute.
+     */
+    public void removeAttribute(QName qname) {
+        attributes.remove(qname);
+    }
+
+    /**
+     * Clears all attributes from the Policy.
+     */
+    public void clearAttributes() {
+        attributes.clear();
+    }
 
-       /**
-        * Creates a policy object
-        */
-       public Policy() {
-       }
-
-       /**
-        * Creates a policy object with the specified Id
-        * 
-        * @param id
-        *            a string as the id
-        */
-       public Policy(String id) {
-               this(null, id);
-               setNormalized(false);
-       }
-
-       /**
-        * Creates a policy object with the specified xml-base and id.
-        * 
-        * @param xmlBase
-        *            the xml-base
-        * @param id
-        *            a string as the id
-        */
-       public Policy(String xmlBase, String id) {
-               this.xmlBase = xmlBase;
-               this.id = id;
-               setNormalized(false);
-       }
-
-       /**
-        * Set the xml-base of the policy object
-        * 
-        * @param xmlBase
-        *            the xml base of the policy object
-        */
-       public void setBase(String xmlBase) {
-               this.xmlBase = xmlBase;
-       }
-
-       /**
-        * Returns the xml-base of the policy object. Returns null if no 
xml-base is
-        * set.
-        * 
-        * @return xml base of the policy object
-        */
-       public String getBase() {
-               return xmlBase;
-       }
-
-       /**
-        * Sets the id of the Policy object
-        * 
-        * @param id
-        */
-       public void setId(String id) {
-               this.id = id;
-       }
-
-       /**
-        * Returns the Id of the Policy object. Returns null if no Id is set.
-        * 
-        * @return the Id of the policy object.
-        */
-       public String getId() {
-               return id;
-       }
-
-       /**
-        * Returns a String which uniquely identify the policy object. It has 
the
-        * format of {$xmlBase}#{$id}. If the xmlBase is null it will return 
#{$id}
-        * as the URI String. If the Id is null, this will return.
-        * 
-        * @return a String which uniquely identify the policy object.
-        */
-       public String getPolicyURI() {
-               if (id != null) {
-                       if (xmlBase != null) {
-                               return xmlBase + "#" + id;
-                       }
-                       return "#" + id;
-               }
-               return null;
-       }
-
-       public Assertion normalize() {
-               return normalize(null);
-       }
-
-       public Assertion normalize(PolicyRegistry reg) {
-               log.debug("Enter: Policy::normalize");
-
-               if (isNormalized()) {
-                       return this;
-               }
-
-               String xmlBase = getBase();
-               String id = getId();
-               Policy policy = new Policy(xmlBase, id);
-
-               AndCompositeAssertion AND = new AndCompositeAssertion();
-               XorCompositeAssertion XOR = new XorCompositeAssertion();
-
-               ArrayList childAndTermList = new ArrayList();
-               ArrayList childXorTermList = new ArrayList();
-
-               Iterator terms = getTerms().iterator();
-               Assertion term;
-
-               while (terms.hasNext()) {
-                       term = (Assertion) terms.next();
-                       term = term.normalize(reg);
-
-                       if (term instanceof Policy) {
-                               XorCompositeAssertion Xor = 
(XorCompositeAssertion) ((Policy) term)
-                                               .getTerms().get(0);
-
-                               if (Xor.size() != 1) {
-                                       term = Xor;
-
-                               } else {
-                                       AND
-                                                       
.addTerms(((AndCompositeAssertion) Xor.getTerms()
-                                                                       
.get(0)).getTerms());
-                                       continue;
-                               }
-                       }
-
-                       if (term instanceof XorCompositeAssertion) {
-
-                               if (((XorCompositeAssertion) term).isEmpty()) {
-                                       XorCompositeAssertion emptyXor = new 
XorCompositeAssertion();
-                                       emptyXor.setNormalized(true);
-
-                                       policy.addTerm(emptyXor);
-                                       policy.setNormalized(true);
-
-                                       return policy;
-                               }
-
-                               childXorTermList.add(term);
-                               continue;
-                       }
-
-                       if (term instanceof AndCompositeAssertion) {
-
-                               if (((AndCompositeAssertion) term).isEmpty()) {
-                                       AndCompositeAssertion emptyAnd = new 
AndCompositeAssertion();
-                                       XOR.addTerm(emptyAnd);
-
-                               } else {
-                                       AND.addTerms(((AndCompositeAssertion) 
term).getTerms());
-                               }
-                               continue;
-                       }
-                       AND.addTerm((Assertion) term);
-               }
-
-               // processing child-XORCompositeAssertions
-               if (childXorTermList.size() > 1) {
-
-                       for (int i = 0; i < childXorTermList.size(); i++) {
-
-                               for (int j = i; j < childXorTermList.size(); 
j++) {
-
-                                       if (i != j) {
-                                               XorCompositeAssertion xorTermA 
= (XorCompositeAssertion) childXorTermList
-                                                               .get(i);
-                                               XorCompositeAssertion xorTermB 
= (XorCompositeAssertion) childXorTermList
-                                                               .get(j);
-
-                                               Iterator iterA = 
xorTermA.getTerms().iterator();
-
-                                               while (iterA.hasNext()) {
-                                                       Assertion andTermA = 
(Assertion) iterA.next();
-
-                                                       Iterator iterB = 
xorTermB.getTerms().iterator();
-
-                                                       while (iterB.hasNext()) 
{
-                                                               Assertion 
andTermB = (Assertion) iterB.next();
-                                                               
AndCompositeAssertion anAndTerm = new AndCompositeAssertion();
-                                                               
anAndTerm.addTerms(andTermA.getTerms());
-                                                               
anAndTerm.addTerms(andTermB.getTerms());
-                                                               
XOR.addTerm(anAndTerm);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-
-               } else if (childXorTermList.size() == 1) {
-                       Assertion xorTerm = (Assertion) childXorTermList.get(0);
-                       XOR.addTerms(xorTerm.getTerms());
-               }
-
-               if (childXorTermList.isEmpty()) {
-                       XorCompositeAssertion xor = new XorCompositeAssertion();
-
-                       xor.addTerm(AND);
-                       policy.addTerm(xor);
-                       policy.setNormalized(true);
-                       return policy;
-               }
-
-               List primTerms = AND.getTerms();
-               Iterator andTerms = XOR.getTerms().iterator();
-
-               while (andTerms.hasNext()) {
-                       Assertion anAndTerm = (Assertion) andTerms.next();
-                       anAndTerm.addTerms(primTerms);
-               }
-
-               policy.addTerm(XOR);
-               policy.setNormalized(true);
-               return policy;
-       }
-
-       public Assertion intersect(Assertion assertion, PolicyRegistry reg) {
-               log.debug("Enter: Policy::intersect");
-
-               Assertion normalizedMe = (isNormalized()) ? this : 
normalize(reg);
-               if (!(normalizedMe instanceof Policy)) {
-                       return normalizedMe.intersect(assertion, reg);
-               }
-
-               Assertion target = (assertion.isNormalized()) ? assertion : 
assertion
-                               .normalize(reg);
-               short type = target.getType();
-
-               switch (type) {
-               case Assertion.COMPOSITE_POLICY_TYPE: {
-                       Policy nPOLICY = new Policy();
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       
.get(0)).intersect((XorCompositeAssertion) target
-                                       .getTerms().get(0)));
-                       return nPOLICY;
-               }
-               case Assertion.COMPOSITE_XOR_TYPE: {
-                       Policy nPOLICY = new Policy();
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       .get(0)).intersect(target));
-                       return nPOLICY;
-               }
-               case Assertion.COMPOSITE_AND_TYPE: {
-                       Policy nPOLICY = new Policy();
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       .get(0)).intersect(target));
-                       return nPOLICY;
-               }
-               case Assertion.PRIMITIVE_TYPE: {
-                       Policy nPOLICY = new Policy();
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       .get(0)).intersect(target));
-                       return nPOLICY;
-               }
-
-               default: {
-                       throw new IllegalArgumentException("intersect is not 
defined for "
-                                       + target.getClass().getName() + " 
type");
-               }
-
-               }
-       }
-
-       public Assertion merge(Assertion assertion, PolicyRegistry reg) {
-               log.debug("Enter: Policy::merge");
-
-               Assertion normalizedMe = (isNormalized()) ? this : 
normalize(reg);
-
-               if (!(normalizedMe instanceof Policy)) {
-                       return normalizedMe.merge(assertion, reg);
-               }
-
-               Policy nPOLICY = new Policy();
-
-               Assertion target = (assertion.isNormalized()) ? assertion : 
assertion
-                               .normalize(reg);
-               short type = target.getType();
-
-               switch (type) {
-
-               case Assertion.COMPOSITE_POLICY_TYPE: {
-
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       .get(0)).merge((XorCompositeAssertion) 
target.getTerms()
-                                       .get(0)));
-                       return nPOLICY;
-               }
-               case Assertion.COMPOSITE_XOR_TYPE: {
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       .get(0)).merge(target));
-                       return nPOLICY;
-               }
-
-               case Assertion.COMPOSITE_AND_TYPE: {
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       .get(0)).merge(target));
-                       return nPOLICY;
-               }
-
-               case Assertion.PRIMITIVE_TYPE: {
-                       nPOLICY.addTerm(((XorCompositeAssertion) 
normalizedMe.getTerms()
-                                       .get(0)).merge(target));
-                       return nPOLICY;
-               }
-
-               default: {
-                       throw new IllegalArgumentException(" merge for "
-                                       + target.getClass().getName() + " not 
defined");
-               }
-
-               }
-       }
-
-       /**
-        * Returns a short value which indicates this is a Policy.
-        */
-       public final short getType() {
-               return Assertion.COMPOSITE_POLICY_TYPE;
-       }
 }

Modified: 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/PolicyConstants.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/PolicyConstants.java?rev=399684&r1=399683&r2=399684&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/PolicyConstants.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/PolicyConstants.java
 Thu May  4 05:03:42 2006
@@ -48,5 +48,14 @@
 
        /** XML namespace */
        public static final String XML_NAMESPACE_URI = 
"http://www.w3.org/XML/1998/namespace";;
+  
+  /** Policy Id attribute **/
+  public static final String WS_POLICY_ID = "Id";
+  
+  /** Policy base attribute **/
+  public static final String WS_POLICY_BASE = "base";
+  
+  /** Namespace of xmlns prefix when defining namespace aliases  */
+  public static final String NAMESPACE_XMLNS = "http://www.w3.org/2000/xmlns/";;
 
 }

Modified: 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/DOMPolicyReader.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/DOMPolicyReader.java?rev=399684&r1=399683&r2=399684&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/DOMPolicyReader.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/DOMPolicyReader.java
 Thu May  4 05:03:42 2006
@@ -102,22 +102,20 @@
     }
 
     public Policy readPolicy(Element element) {
-        Policy policy = new Policy();
-        Attr attri;
-        attri = element.getAttributeNodeNS(PolicyConstants.WSU_NAMESPACE_URI,
-                "Id");
-        if (attri != null) {
-            policy.setId(attri.getValue());
+      Policy policy = new Policy();
+      // We treat all attributes equally ...
+      NamedNodeMap attributes = element.getAttributes();
+      if (attributes != null) {
+        for (int i = 0; i < attributes.getLength(); i++) {
+          Node attributeNode = attributes.item(i);
+          QName attrName = new QName(attributeNode.getNamespaceURI(), 
attributeNode
+              .getLocalName());
+          policy.addAttribute(new QName(attributeNode.getNamespaceURI(), 
attributeNode
+              .getLocalName()), attributeNode.getNodeValue());
         }
-
-        attri = element.getAttributeNodeNS(PolicyConstants.XML_NAMESPACE_URI,
-                "base");
-        if (attri != null) {
-            policy.setBase(attri.getValue());
-        }
-
-        policy.addTerms(readTerms(element));
-        return policy;
+      }
+      policy.addTerms(readTerms(element));
+      return policy;
     }
 
     private AndCompositeAssertion readAndComposite(Element element) {

Modified: 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/OMPolicyReader.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/OMPolicyReader.java?rev=399684&r1=399683&r2=399684&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/OMPolicyReader.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/OMPolicyReader.java
 Thu May  4 05:03:42 2006
@@ -91,22 +91,17 @@
        }
 
        public Policy readPolicy(OMElement element) {
-               Policy policy = new Policy();
+    Policy policy = new Policy();
 
-               OMAttribute attri;
-               attri = element.getAttribute(new QName(
-                               PolicyConstants.WSU_NAMESPACE_URI, "Id"));
-               if (attri != null) {
-                       policy.setId(attri.getAttributeValue());
-               }
-               attri = element.getAttribute(new QName(
-                               PolicyConstants.XML_NAMESPACE_URI, "base"));
-               if (attri != null) {
-                       policy.setBase(attri.getAttributeValue());
-               }
-
-               policy.addTerms(readTerms(element));
-               return policy;
+    // We treat all attributes equally ...
+    OMAttribute attri;
+    Iterator it = element.getAllAttributes();
+    while (it.hasNext()) {
+      attri = (OMAttribute) it.next();
+      policy.addAttribute(attri.getQName(), attri.getAttributeValue());
+    }
+    policy.addTerms(readTerms(element));
+    return policy;
        }
 
        private AndCompositeAssertion readAndComposite(OMElement element) {

Modified: 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/StAXPolicyWriter.java
URL: 
http://svn.apache.org/viewcvs/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/StAXPolicyWriter.java?rev=399684&r1=399683&r2=399684&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/StAXPolicyWriter.java
 (original)
+++ 
webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/util/StAXPolicyWriter.java
 Thu May  4 05:03:42 2006
@@ -17,6 +17,7 @@
 package org.apache.ws.policy.util;
 
 import java.io.OutputStream;
+import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
@@ -62,10 +63,10 @@
 
        public void writePolicy(Policy policy, XMLStreamWriter writer)
                        throws XMLStreamException {
-               String writerPerfix = writer
+               String writerPrefix = writer
                                
.getPrefix(PolicyConstants.WS_POLICY_NAMESPACE_URI);
 
-               if (writerPerfix != null) {
+               if (writerPrefix != null) {
                        
writer.writeStartElement(PolicyConstants.WS_POLICY_NAMESPACE_URI,
                                        PolicyConstants.WS_POLICY);
 
@@ -80,24 +81,54 @@
 
                }
 
-               if (policy.getId() != null) {
+    Hashtable attributes = policy.getAttributes();
+    Enumeration attrNames = attributes.keys();
+    while (attrNames.hasMoreElements()) {
+      QName tAttrName = (QName) attrNames.nextElement();
+      String tAttrNamespaceURI = tAttrName.getNamespaceURI();
+      // If it's a namespace, make sure we note that it's been written ...
+
+      if (tAttrNamespaceURI != null) {
+        if (tAttrNamespaceURI.equals(PolicyConstants.NAMESPACE_XMLNS)) {
+          String tPrefix = tAttrName.getLocalPart();
+          // For XMLSNS attributes, the attribute value is the actual 
namespace.
+          writerPrefix = writer.getPrefix((String) attributes.get(tAttrName));
+          // We only need to act upon it if we haven't seen it before ...
+          if (writerPrefix == null) {
+            writer.setPrefix(tPrefix, (String) attributes.get(tAttrName));
+            writer.writeNamespace(tPrefix, (String) attributes.get(tAttrName));
+          }
+        } else {
+          // It must be a standard attribute ...
+          String tPrefix = writer.getPrefix(tAttrNamespaceURI);
+
+          // Firstly, deal with the ones that have prefixes in common usage ...
+          if (tAttrNamespaceURI.equals(PolicyConstants.WSU_NAMESPACE_URI)) {
+            if (tPrefix == null) {
+              tPrefix = PolicyConstants.WSU_NAMESPACE_PREFIX;
+              writer.setPrefix(tPrefix, tAttrNamespaceURI);
+              writer.writeNamespace(tPrefix, tAttrNamespaceURI);
+            }
+          } else {
+            if (tPrefix == null) {
+              tPrefix = generateNamespace();
+              writer.setPrefix(tPrefix, tAttrNamespaceURI);
+              writer.writeNamespace(tPrefix, tAttrNamespaceURI);
+            }
+          }
+          writer.writeAttribute(tPrefix, tAttrNamespaceURI, tAttrName
+              .getLocalPart(), (String) attributes.get(tAttrName));
+        }
+      }
+    }
+    Iterator iterator = policy.getTerms().iterator();
+    while (iterator.hasNext()) {
+      Assertion term = (Assertion) iterator.next();
+      writeAssertion(term, writer);
+    }
 
-                       
writer.writeNamespace(PolicyConstants.WSU_NAMESPACE_PREFIX,
-                                       PolicyConstants.WSU_NAMESPACE_URI);
-                       writer.setPrefix(PolicyConstants.WSU_NAMESPACE_PREFIX,
-                                       PolicyConstants.WSU_NAMESPACE_URI);
+    writer.writeEndElement();
 
-                       writer.writeAttribute("wsu", 
PolicyConstants.WSU_NAMESPACE_URI,
-                                       "Id", policy.getId());
-               }
-
-               Iterator iterator = policy.getTerms().iterator();
-               while (iterator.hasNext()) {
-                       Assertion term = (Assertion) iterator.next();
-                       writeAssertion(term, writer);
-               }
-
-               writer.writeEndElement();
        }
 
        private void writeAssertion(Assertion assertion, XMLStreamWriter writer)


Reply via email to