ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r356270 - in /webservices/commons/trunk/policy: interop/ibm/src/org/apache/ws/policy/interop/ src/org/apache/ws/policy/ src/org/apache/ws/policy/util/
Date Mon, 12 Dec 2005 16:09:51 GMT
Author: sanka
Date: Mon Dec 12 08:09:15 2005
New Revision: 356270

URL: http://svn.apache.org/viewcvs?rev=356270&view=rev
Log:
Fixed: normalize(..) causes an infinte recurrsion which result in stack overflow error

Modified:
    webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/AndCompositeAssertion.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/PrimitiveAssertion.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/XorCompositeAssertion.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyUtil.java
    webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java

Modified: webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java
(original)
+++ webservices/commons/trunk/policy/interop/ibm/src/org/apache/ws/policy/interop/SimplePolicyService.java
Mon Dec 12 08:09:15 2005
@@ -33,7 +33,7 @@
 import org.apache.axis2.om.OMXMLParserWrapper;
 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.axis2.soap.SOAPBody;
-import org.apache.ws.policy.model.Policy;
+import org.apache.ws.policy.Policy;
 import org.apache.ws.policy.util.PolicyFactory;
 import org.apache.ws.policy.util.PolicyReader;
 import org.apache.ws.policy.util.PolicyWriter;
@@ -104,7 +104,7 @@
     }
 
     private PolicyWriter getWriter() {
-        return PolicyFactory.getPolicyWriter();
+        return PolicyFactory.getPolicyWriter(PolicyFactory.StAX_POLICY_WRITER);
     }
 
     private OMElement getWholeElement(OMElement element) {

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/AndCompositeAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/AndCompositeAssertion.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/AndCompositeAssertion.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/AndCompositeAssertion.java Mon
Dec 12 08:09:15 2005
@@ -232,6 +232,8 @@
     public Assertion normalize(PolicyRegistry reg) {
         log.debug("Enter: AndCompositeAssertion::normalize");
         
+        if (isNormalized()) { return this; }
+        
         AndCompositeAssertion AND = new AndCompositeAssertion();
         XorCompositeAssertion XOR = new XorCompositeAssertion();
 

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java Mon
Dec 12 08:09:15 2005
@@ -103,7 +103,7 @@
     public Assertion normalize() {
         return normalize(null);
     }
-    
+        
     public Assertion intersect(Assertion assertion)
             throws UnsupportedOperationException {
         return intersect(assertion, null);

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java Mon Dec 12 08:09:15
2005
@@ -81,6 +81,8 @@
 
     public Assertion normalize(PolicyRegistry reg) {
         log.debug("Enter: Policy::normalize");
+        
+        if (isNormalized()) { return this;}
 
         String xmlBase = getBase();
         String id = getId();
@@ -103,9 +105,9 @@
             if (term instanceof Policy) {
                 Assertion wrapper = new AndCompositeAssertion();
                 ((AndCompositeAssertion) wrapper).addTerms(((Policy) term).getTerms());
-                term = wrapper.normalize(reg);                    
-                continue;
+                term = wrapper.normalize(reg);     
             }
+            
             if (term instanceof XorCompositeAssertion) {
                 if (((XorCompositeAssertion) term).isEmpty()) {
                     XorCompositeAssertion emptyXor = new XorCompositeAssertion();

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/PrimitiveAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/PrimitiveAssertion.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/PrimitiveAssertion.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/PrimitiveAssertion.java Mon
Dec 12 08:09:15 2005
@@ -162,116 +162,162 @@
     public Assertion normalize(PolicyRegistry reg) {
         log.debug("Enter: PrimitveAssertion:normalize");
         
+        if (isNormalized()) { return this; }
+        
         if (isOptional()) {
-            System.out.println("PA is optional");
-            XorCompositeAssertion xorCompositeAssertion = new XorCompositeAssertion();
-            AndCompositeAssertion andCompositeAssertion = new AndCompositeAssertion();
+            XorCompositeAssertion XOR = new XorCompositeAssertion();
+            AndCompositeAssertion AND = new AndCompositeAssertion();
                         
-            PrimitiveAssertion assertion = getSelfWithoutTerms();
-            assertion.removeAttribute(new QName(PolicyConstants.WS_POLICY_NAMESPACE_URI,
"Optional"));
-            assertion.setOptional(false);
-            assertion.setTerms(getTerms());
+            PrimitiveAssertion PRIM = getSelfWithoutTerms();
+            PRIM.removeAttribute(new QName(PolicyConstants.WS_POLICY_NAMESPACE_URI, "Optional"));
+            PRIM.setOptional(false);
+            PRIM.setTerms(getTerms());
             
-            andCompositeAssertion.addTerm(assertion);
-            xorCompositeAssertion.addTerm(andCompositeAssertion);
-            xorCompositeAssertion.addTerm(new AndCompositeAssertion());
+            AND.addTerm(PRIM);
+            XOR.addTerm(AND);
+            XOR.addTerm(new AndCompositeAssertion());
             
-            return xorCompositeAssertion.normalize(reg);
+            return XOR.normalize(reg);
         }
         
         if (getTerms().isEmpty()) {
-            PrimitiveAssertion primitiveAssertion = getSelfWithoutTerms();
-            primitiveAssertion.setNormalized(true);
-            return primitiveAssertion;
+            PrimitiveAssertion PRIM = getSelfWithoutTerms();
+            PRIM.setNormalized(true);
+            return PRIM;
         }
         
         ArrayList policyTerms = new ArrayList();
-        ArrayList childNonPolicyTerms = new ArrayList();
+        ArrayList nonPolicyTerms = new ArrayList();
         
         Iterator iterator = getTerms().iterator();
         
         while (iterator.hasNext()) {
             Assertion term = (Assertion) iterator.next();
-            if (!(term.isNormalized())) {
-                term = term.normalize();
-            }
+//            if (!(term.isNormalized())) {
+//                term = term.normalize();
+//            }
             
             if (term instanceof Policy) {
                 policyTerms.add(term);
                 
             } else if (term instanceof PrimitiveAssertion) {
-                childNonPolicyTerms.add(term);
+                nonPolicyTerms.add(term);
                 
             } else {
+                throw new RuntimeException();
                 //TODO should I throw an exception ..
             }
         }
                
         if (policyTerms.isEmpty()) {
-            PrimitiveAssertion primitiveAssertion = getSelfWithoutTerms();
-            primitiveAssertion.setTerms(getTerms());
-            primitiveAssertion.setNormalized(true);
-            return primitiveAssertion;           
+            PrimitiveAssertion PRIM = getSelfWithoutTerms();
+            PRIM.setTerms(getTerms());
+            PRIM.setNormalized(true);
+            return PRIM;           
         }
         
         Policy policyTerm = PolicyUtil.getSinglePolicy(policyTerms, reg);
         CompositeAssertion xorTerm = (XorCompositeAssertion) 
                 policyTerm.getTerms().get(0);
         
-        Iterator iterator2 = xorTerm.getTerms().iterator();
- //       AndCompositeAssertion andTerm = (AndCompositeAssertion) iterator2.next();
-                
-        if (!(iterator2.hasNext())) { //policy with no alternatives
-            // two scenarios ..
-            
-            /* no leaves */
-            if (childNonPolicyTerms.isEmpty()) {
-                PrimitiveAssertion primTerm = getSelfWithoutTerms();
-                primTerm.addTerm(policyTerm);
-                return primTerm;                
-            }
-                        
-            /* (2) some leaves*/           
-            ArrayList allTerms = new ArrayList();
-            allTerms.addAll(childNonPolicyTerms);
-            allTerms.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
-            PrimitiveAssertion primTerm = getSelfWithoutTerms();
-            primTerm.addTerm(getSinglePolicy(allTerms));
-            return primTerm;        
-        } 
-        
-        /* Policy with many terms */
-        Policy endPolicyTerm = new Policy();
-        XorCompositeAssertion endXorTerm = new XorCompositeAssertion();
-        endPolicyTerm.addTerm(endXorTerm);        
-        
-        ArrayList endAndTerms = new ArrayList();
-        AndCompositeAssertion anEndAndTerm = new AndCompositeAssertion();
-        PrimitiveAssertion self;
-        
-        ArrayList termsForAnEndAnd = new ArrayList();
-        self = getSelfWithoutTerms();
-        
-        termsForAnEndAnd.addAll(childNonPolicyTerms);
-        termsForAnEndAnd.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
-        self.addTerm(PolicyUtil.getPolicy(termsForAnEndAnd));
-        anEndAndTerm.addTerm(self);
-        endAndTerms.add(anEndAndTerm);
-               
+        List ANDs =  xorTerm.getTerms();
+        
+        if (ANDs.size() == 0) {
+            return new XorCompositeAssertion();
+        }
+        
+        if (ANDs.size() == 1) {
+            ((AndCompositeAssertion) ANDs.get(0)).addTerms(nonPolicyTerms);
+            PrimitiveAssertion PRIM = getSelfWithoutTerms();
+            PRIM.addTerm(policyTerm);
+            return PRIM;
+        }
+        
+        
+        Policy nPOLICY = new Policy();
+        XorCompositeAssertion nXOR = new XorCompositeAssertion();
+        nPOLICY.addTerm(nXOR);
+        
+        PrimitiveAssertion nPRIM;
+        Iterator iterator2 = ANDs.iterator();
+        
+        ArrayList list;
+        
         while (iterator2.hasNext()) {
-            anEndAndTerm = new AndCompositeAssertion();     
-            self = getSelfWithoutTerms();
-                        
-            termsForAnEndAnd.clear();
-            termsForAnEndAnd.addAll(childNonPolicyTerms);
-            termsForAnEndAnd.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
-            self.addTerm(PolicyUtil.getPolicy(termsForAnEndAnd));
+            nPRIM = getSelfWithoutTerms();
+            
+            list = new ArrayList();
+            list.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
             
-            anEndAndTerm.addTerm(self);
-            endAndTerms.add(anEndAndTerm);            
+            if (!nonPolicyTerms.isEmpty()) {
+                list.addAll(nonPolicyTerms);                
+            }
+            nPRIM.addTerm(getSinglePolicy(list));
+            AndCompositeAssertion AND = new AndCompositeAssertion();
+            AND.addTerm(nPRIM);
+            nXOR.addTerm(AND);            
         }
-        endXorTerm.addTerms(endAndTerms);
-        return endPolicyTerm;
+        nPOLICY.setNormalized(true);
+        return nPOLICY;
+        
+        
+        
+ //       AndCompositeAssertion andTerm = (AndCompositeAssertion) iterator2.next();
+                
+//        if (!(iterator2.hasNext())) { //policy with no alternatives
+//            // two scenarios ..
+//            
+//            /* no leaves */
+//            if (nonPolicyTerms.isEmpty()) {
+//                PrimitiveAssertion primTerm = getSelfWithoutTerms();
+//                primTerm.addTerm(policyTerm);
+//                primTerm.setNormalized(true);
+//                return primTerm;                
+//            }
+//                        
+//            /* (2) some leaves*/           
+//            ArrayList allTerms = new ArrayList();
+//            allTerms.addAll(nonPolicyTerms);
+//            allTerms.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
+//            PrimitiveAssertion primTerm = getSelfWithoutTerms();
+//            primTerm.addTerm(getSinglePolicy(allTerms));
+//            primTerm.setNormalized(true);
+//            return primTerm;        
+//        } 
+//        
+//        /* Policy with many terms */
+//        Policy endPolicyTerm = new Policy();
+//        XorCompositeAssertion endXorTerm = new XorCompositeAssertion();
+//        endPolicyTerm.addTerm(endXorTerm);        
+//        
+//        ArrayList endAndTerms = new ArrayList();
+//        AndCompositeAssertion anEndAndTerm = new AndCompositeAssertion();
+//        PrimitiveAssertion self;
+//        
+//        ArrayList termsForAnEndAnd = new ArrayList();
+//        self = getSelfWithoutTerms();
+//        
+//        termsForAnEndAnd.addAll(nonPolicyTerms);
+//        termsForAnEndAnd.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
+//        self.addTerm(PolicyUtil.getPolicy(termsForAnEndAnd));
+//        anEndAndTerm.addTerm(self);
+//        endAndTerms.add(anEndAndTerm);
+//               
+//        while (iterator2.hasNext()) {
+//            anEndAndTerm = new AndCompositeAssertion();     
+//            self = getSelfWithoutTerms();
+//                        
+//            termsForAnEndAnd.clear();
+//            termsForAnEndAnd.addAll(nonPolicyTerms);
+//            termsForAnEndAnd.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
+//            self.addTerm(PolicyUtil.getPolicy(termsForAnEndAnd));
+//            
+//            anEndAndTerm.addTerm(self);
+//            endAndTerms.add(anEndAndTerm);            
+//        }
+//        endXorTerm.addTerms(endAndTerms);
+//        endXorTerm.setNormalized(true);
+//        return endPolicyTerm;
     }
     
     private PrimitiveAssertion getSelfWithoutTerms() {

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/XorCompositeAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/XorCompositeAssertion.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/XorCompositeAssertion.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/XorCompositeAssertion.java Mon
Dec 12 08:09:15 2005
@@ -48,6 +48,8 @@
     public Assertion normalize(PolicyRegistry reg) {
         log.debug("Enter: XorCompositeAssertion::normalize");
         
+        if (isNormalized()) { return this;}
+        
         XorCompositeAssertion XOR = new XorCompositeAssertion();
         
         if (isEmpty()) {

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyUtil.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyUtil.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyUtil.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/util/PolicyUtil.java Mon Dec
12 08:09:15 2005
@@ -94,6 +94,9 @@
                     ? policyTerm2 : (Policy) policyTerm.merge(policyTerm2, reg);
         }
         
+        if (!policyTerm.isNormalized()) {
+            policyTerm = (Policy) policyTerm.normalize();
+        }
         return policyTerm;
     }
     

Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java?rev=356270&r1=356269&r2=356270&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java Mon
Dec 12 08:09:15 2005
@@ -61,7 +61,8 @@
     private void writePolicy(Policy policy, XMLStreamWriter writer)
             throws XMLStreamException {
         writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
-                PolicyConstants.WS_POLICY);
+                PolicyConstants.WS_POLICY,
+                PolicyConstants.WS_POLICY_NAMESPACE_URI);
         writer.writeNamespace(PolicyConstants.WS_POLICY_PREFIX,
                 PolicyConstants.WS_POLICY_NAMESPACE_URI);
 
@@ -132,7 +133,8 @@
 
         String prefix = qname.getPrefix();
         if (prefix != null) {
-            writer.writeStartElement(qname.getPrefix(), qname.getLocalPart());
+            writer.writeStartElement(qname.getPrefix(), qname.getLocalPart(),
+                    qname.getNamespaceURI());
             writer.writeNamespace(qname.getPrefix(), qname.getNamespaceURI());
 
         } else {



Mime
View raw message