You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sa...@apache.org on 2006/07/19 11:10:06 UTC

svn commit: r423410 - in /webservices/commons/trunk/modules/neethi: src/org/apache/neethi/ src/org/apache/ws/policy/ test3/ test3/org/ test3/org/apache/ test3/org/apache/neethi/ test3/org/apache/neethi/util/

Author: sanka
Date: Wed Jul 19 02:10:05 2006
New Revision: 423410

URL: http://svn.apache.org/viewvc?rev=423410&view=rev
Log:
Completed the implementation of merge(...) and intersection(...) operations.
Also added the first test suite for normalization operation.


Added:
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PrimitiveAssertion.java
    webservices/commons/trunk/modules/neethi/test3/
    webservices/commons/trunk/modules/neethi/test3/org/
    webservices/commons/trunk/modules/neethi/test3/org/apache/
    webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/
    webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java
    webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/PolicyTestCase.java
    webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/
    webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java
Modified:
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/All.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/ExactlyOne.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Policy.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java
    webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java?rev=423410&r1=423409&r2=423410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java Wed Jul 19 02:10:05 2006
@@ -19,57 +19,116 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.xml.namespace.QName;
+
 public abstract class AbstractPolicyOperator implements PolicyOperator {
     protected ArrayList policyComponents = new ArrayList();
-    
+
     public void addPolicyComponent(PolicyComponent component) {
         policyComponents.add(component);
     }
-    
+
     public void addPolicyComponents(List components) {
         policyComponents.addAll(components);
     }
-    
+
     public List getPolicyComponents() {
         return policyComponents;
     }
-    
+
+    public PolicyComponent getFirstPolicyComponent() {
+        return (PolicyComponent) policyComponents.get(0);
+    }
+
     public boolean isEmpty() {
         return policyComponents.isEmpty();
     }
-    
-    protected List crossProduct(ArrayList allTerms, int index) {
+
+    protected List crossProduct(ArrayList allTerms, int index,
+            boolean matchVacabulary) {
 
         ArrayList result = new ArrayList();
-        ExactlyOne firstTerm = (ExactlyOne) allTerms
-                .get(index);
-        
+        ExactlyOne firstTerm = (ExactlyOne) allTerms.get(index);
+
         List restTerms;
-        
+
         if (allTerms.size() == ++index) {
             restTerms = new ArrayList();
             All newTerm = new All();
             restTerms.add(newTerm);
         } else {
-            restTerms = crossProduct(allTerms, index);
+            restTerms = crossProduct(allTerms, index, matchVacabulary);
         }
 
         Iterator firstTermIter = firstTerm.getPolicyComponents().iterator();
-        
+
         while (firstTermIter.hasNext()) {
-            Assertion assertion = (Assertion) firstTermIter.next();
-            Iterator restTermsItr = restTerms.iterator();
             
+            All assertion = (All) firstTermIter.next();
+            Iterator restTermsItr = restTerms.iterator();
+
             while (restTermsItr.hasNext()) {
-                Assertion restTerm = (Assertion) restTermsItr.next();
+                All restTerm = (All) restTermsItr.next();
                 All newTerm = new All();
-                newTerm.addPolicyComponents(((All) assertion).getPolicyComponents());
-                newTerm.addPolicyComponents(((All) restTerm).getPolicyComponents());
-                result.add(newTerm);
+
+                if (matchVacabulary) {
+                    if (matchVocabulary(
+                            ((All) assertion).getPolicyComponents(),
+                            ((All) restTerm).getPolicyComponents())) {
+                        newTerm.addPolicyComponents(((All) assertion)
+                                .getPolicyComponents());
+                        newTerm.addPolicyComponents(((All) restTerm)
+                                .getPolicyComponents());
+                        result.add(newTerm);
+                    }
+
+                } else {
+                    newTerm.addPolicyComponents(((All) assertion)
+                            .getPolicyComponents());
+                    newTerm.addPolicyComponents(((All) restTerm)
+                            .getPolicyComponents());
+                    result.add(newTerm);
+                }
             }
         }
-        
+
         return result;
     }
-    
+
+    private boolean matchVocabulary(List assertions1, List assertions2) {
+
+        Iterator S, L;
+
+        if (assertions1.size() < assertions2.size()) {
+            S = assertions1.iterator();
+            L = assertions2.iterator();
+        } else {
+            S = assertions2.iterator();
+            L = assertions1.iterator();
+        }
+
+        QName Sq, Lq;
+        boolean found;
+
+        for (; L.hasNext();) {
+            Lq = ((PrimitiveAssertion) L.next()).getName();
+
+            found = false;
+
+            for (; S.hasNext();) {
+                Sq = ((PrimitiveAssertion) S.next()).getName();
+
+                if (Lq.equals(Sq)) {
+                    found = true;
+                    break;
+                }
+
+            }
+
+            if (!found) {
+                return false;
+            }
+        }
+        return true;
+    }
 }

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/All.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/All.java?rev=423410&r1=423409&r2=423410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/All.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/All.java Wed Jul 19 02:10:05 2006
@@ -52,6 +52,9 @@
                         .getPolicyComponents());
                 component = wrapper.normalize(deep);
                 type = component.getType();
+                
+            } else if (!(type == PolicyComponent.ASSERTION)) {
+                component = ((PolicyOperator) component).normalize(deep);
             }
 
             if (type == PolicyComponent.EXACTLYONE) {
@@ -76,7 +79,7 @@
 
         // processing child ExactlyOne operators
         if (exactlyOnes.size() > 1) {
-            exactlyOne.addPolicyComponents(crossProduct(exactlyOnes, 0));
+            exactlyOne.addPolicyComponents(crossProduct(exactlyOnes, 0, false));
 
         } else if (exactlyOnes.size() == 1) {
             ExactlyOne anExactlyOne = (ExactlyOne) exactlyOnes.get(0);

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java?rev=423410&r1=423409&r2=423410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java Wed Jul 19 02:10:05 2006
@@ -17,11 +17,11 @@
 
 import javax.xml.stream.XMLStreamWriter;
 
-public interface Assertion extends PolicyComponent{
+public interface Assertion extends PolicyComponent {
         
-    public Assertion normalize();
+    public PolicyComponent normalize();
     
-    public Assertion normalize(PolicyRegistry registry);
+    public PolicyComponent normalize(PolicyRegistry registry);
     
     public void serialize(XMLStreamWriter writer);
     

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/ExactlyOne.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/ExactlyOne.java?rev=423410&r1=423409&r2=423410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/ExactlyOne.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/ExactlyOne.java Wed Jul 19 02:10:05 2006
@@ -35,14 +35,18 @@
             
             if (type == PolicyComponent.ASSERTION && deep) {
                 component = ((Assertion) component).normalize();
-                type = component.getType();
-            }
+                type = component.getType();       
+            } 
             
             if (type == PolicyComponent.POLICY) {
                 All wrapper = new All();
-                wrapper.addPolicyComponents(((All) component).getPolicyComponents());
+                wrapper.addPolicyComponents(((Policy) component).getPolicyComponents());
                 
                 component = wrapper.normalize(deep);
+                type = component.getType();
+                
+            } else if (type != PolicyComponent.ASSERTION) {
+                component = ((PolicyOperator) component).normalize(deep);
                 type = component.getType();
             }
             

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Policy.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Policy.java?rev=423410&r1=423409&r2=423410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Policy.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Policy.java Wed Jul 19 02:10:05 2006
@@ -43,20 +43,24 @@
                 .hasNext();) {
             component = (PolicyComponent) iterator.next();
             short type = component.getType();
-
+            
             if (type == PolicyComponent.ASSERTION && deep) {
                 component = ((Assertion) component).normalize();
                 type = component.getType();
             }
-
+            
             if (type == PolicyComponent.POLICY) {
                 All wrapper = new All();
                 wrapper.addPolicyComponents(((Policy) component)
                         .getPolicyComponents());
                 component = wrapper.normalize(deep);
                 type = component.getType();
+                
+            } else if (type != PolicyComponent.ASSERTION) {
+                component = ((PolicyOperator) component).normalize(deep);
+                type = component.getType();
             }
-
+            
             if (type == PolicyComponent.EXACTLYONE) {
 
                 if (((ExactlyOne) component).isEmpty()) {
@@ -82,7 +86,7 @@
 
         // processing child ExactlyOne operators
         if (exactlyOnes.size() > 1) {
-            exactlyOne.addPolicyComponents(crossProduct(exactlyOnes, 0));
+            exactlyOne.addPolicyComponents(crossProduct(exactlyOnes, 0, false));
 
         } else if (exactlyOnes.size() == 1) {
             ExactlyOne anExactlyOne = (ExactlyOne) exactlyOnes.get(0);
@@ -120,10 +124,25 @@
     }
     
     public Policy merge(Policy policy) {
-        throw new UnsupportedOperationException("still not implemented");
+        
+        Policy result = new Policy();
+        ExactlyOne alternative = new ExactlyOne();
+        result.addPolicyComponent(alternative);
+        
+        ArrayList alternatives = new ArrayList();
+        policy = (Policy) policy.normalize(false);
+        
+        alternatives.add(this.getFirstPolicyComponent());
+        alternatives.add(policy.getFirstPolicyComponent());
+        
+        alternative.addPolicyComponents(crossProduct(alternatives, 0, false));
+        
+        return result;
     }
     
     public Policy intersect(Policy policy) {
+        
+        
         throw new UnsupportedOperationException("still not implemented");
     }
     
@@ -152,6 +171,33 @@
     
     public final short getType() {
         return PolicyComponent.POLICY;
+    }
+    
+    public Iterator getAlternatives() {
+        return new PolicyIterator(this);
+    }
+    
+    private class PolicyIterator implements Iterator {
+        Iterator alternatives = null;
+        
+        public PolicyIterator(Policy policy) {
+            policy = (Policy) policy.normalize(false);
+            ExactlyOne exactlyOne = (ExactlyOne) policy.getFirstPolicyComponent();
+            alternatives = exactlyOne.getPolicyComponents().iterator();
+        }
+
+        public boolean hasNext() {
+            return alternatives.hasNext();
+        }
+
+        public Object next() {
+            return ((All) alternatives.next()).getPolicyComponents();
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException("policyAlternative.remove() is not supported");
+        }
+        
     }
     
 }

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java?rev=423410&r1=423409&r2=423410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java Wed Jul 19 02:10:05 2006
@@ -23,6 +23,7 @@
 import org.apache.neethi.builders.AssertionBuilder;
 
 public class PolicyManager {
+    
     public static final String POLICY_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy";
     
     public static final String POLICY = "Policy";

Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PrimitiveAssertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PrimitiveAssertion.java?rev=423410&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PrimitiveAssertion.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PrimitiveAssertion.java Wed Jul 19 02:10:05 2006
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+package org.apache.neethi;
+
+import javax.xml.namespace.QName;
+
+public interface PrimitiveAssertion extends Assertion {
+    
+    public QName getName();
+    
+    public boolean isOptional();
+
+}

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java?rev=423410&r1=423409&r2=423410&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java Wed Jul 19 02:10:05 2006
@@ -15,17 +15,27 @@
  */
 package org.apache.neethi;
 
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 
-public class XmlPrimtiveAssertion implements Assertion {
+public class XmlPrimtiveAssertion implements PrimitiveAssertion {
 
     OMElement element;
+    boolean isOptional;
+    QName optionalAttri = new QName(PolicyOperator.NAMESPACE, "Optional", PolicyOperator.PREFIX);
+    
     
     public XmlPrimtiveAssertion(OMElement element) {
         setValue(element);
+        setOptionality(element);        
+    }
+    
+    public QName getName() {
+        return (element != null) ? element.getQName() : null;
     }
 
     public void setValue(OMElement element) {
@@ -35,12 +45,33 @@
     public OMElement getValue() {
         return element;
     }
-
-    public Assertion normalize() throws IllegalArgumentException {
+    
+    public boolean isOptional() {
+        return isOptional;
+    }
+    
+    public PolicyComponent normalize() throws IllegalArgumentException {
         return normalize(null);
     }
 
-    public Assertion normalize(PolicyRegistry registry) {
+    public PolicyComponent normalize(PolicyRegistry registry) {
+        
+        if (isOptional) {
+            Policy policy = new Policy();
+            ExactlyOne alternatives = new ExactlyOne();
+            
+            All alternative1 = new All();
+            OMElement element1 = element.cloneOMElement();
+            element1.removeAttribute(element1.getAttribute(optionalAttri));
+            alternative1.addPolicyComponent(new XmlPrimtiveAssertion(element1));
+            alternatives.addPolicyComponent(alternative1);
+            
+            All alternative2 = new All();
+            alternatives.addPolicyComponent(alternative2);
+            
+            policy.addPolicyComponent(alternatives);
+            return policy;
+        }
         return this;
     }
 
@@ -58,5 +89,15 @@
     
     public final short getType() {
         return PolicyComponent.ASSERTION;
+    }
+    
+    private void setOptionality(OMElement element) {
+        OMAttribute attribute = element.getAttribute(optionalAttri);
+        if (attribute != null) {
+            this.isOptional = (new Boolean(attribute.getAttributeValue()).booleanValue());
+            
+        } else {
+            this.isOptional = false;            
+        }        
     }
 }

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java?rev=423410&r1=423409&r2=423410&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 Wed Jul 19 02:10:05 2006
@@ -420,9 +420,7 @@
         attributes.clear();
     }
 
-    /**
-<<<<<<< .mine
-=======
+    /**
      * @param allTerms
      *            ExactlyOne to be corssproducted
      * @param index
@@ -460,7 +458,6 @@
     }
 
     /**
->>>>>>> .r407730
      * Returns an Iterator to track the Alternatives within this Policy. This
      * iterator will again return an iterator which points to the set of
      * primitives in an alternative.

Added: webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java?rev=423410&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java (added)
+++ webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/NormalizeTest.java Wed Jul 19 02:10:05 2006
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+package org.apache.neethi;
+
+import java.io.File;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.neethi.util.PolicyComparator;
+
+public class NormalizeTest extends PolicyTestCase {
+    
+    PolicyManager mgr;
+
+    public NormalizeTest() {
+        super("NormalizeTest");
+    }
+
+    public void test() throws Exception {
+        String r1, r2;
+        Policy p1, p2, test;
+
+        for (int i = 1; i < 26; i++) {
+
+            r1 = "samples" + File.separator + "test" + i + ".xml";
+            r2 = "normalized" + File.separator + "test" + i + ".xml";
+
+            p1 = PolicyManager.getPolicy(getResource(r1));
+            test = p1;
+            p1 = (Policy) p1.normalize(true);
+            p2 = PolicyManager.getPolicy(getResource(r2));
+            
+            if (!PolicyComparator.compare(p1, p2)) {
+                XMLStreamWriter writer;
+                
+                writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
+                test.serialize(writer);
+                writer.flush();
+                
+                System.out.println("----");
+                
+                writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
+                p1.serialize(writer);
+                writer.flush();
+                
+                System.out.println("----");
+                
+                writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
+                p2.serialize(writer);
+                writer.flush();
+                
+                fail("test" + i + " normalize() FAILED");
+            }
+        }
+    }
+}
\ No newline at end of file

Added: webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/PolicyTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/PolicyTestCase.java?rev=423410&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/PolicyTestCase.java (added)
+++ webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/PolicyTestCase.java Wed Jul 19 02:10:05 2006
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.neethi;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import javax.xml.stream.XMLInputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
+
+public class PolicyTestCase extends TestCase {
+	protected String baseDir = System.getProperty("basedir");
+	protected String testDir = "test" + File.separator;
+	protected String testResourceDir = "test-resources";
+	
+	public PolicyTestCase(String name) {
+		super(name);
+		if (baseDir == null) {
+			baseDir = (String) (new File(".")).getAbsolutePath();
+		}
+		testDir = (String) (new File(baseDir, testDir).getAbsolutePath());	
+	}	
+	
+	public OMElement getResource(String name) {
+		String filePath = (new File(testResourceDir, name)).getAbsolutePath(); 
+		try {
+            
+			FileInputStream fis = new FileInputStream(filePath);
+            OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), XMLInputFactory.newInstance().createXMLStreamReader(fis)).getDocumentElement();
+            return element;
+            
+		} catch (Exception e) {
+			fail("Cannot get resource: " + e.getMessage());
+			throw new RuntimeException();
+		}
+	}
+}
+

Added: webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java?rev=423410&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java (added)
+++ webservices/commons/trunk/modules/neethi/test3/org/apache/neethi/util/PolicyComparator.java Wed Jul 19 02:10:05 2006
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.
+ */
+package org.apache.neethi.util;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.neethi.All;
+import org.apache.neethi.ExactlyOne;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.PrimitiveAssertion;
+
+public class PolicyComparator {
+
+    public static boolean compare(Policy arg1, Policy arg2) {
+        return compare(arg1.getPolicyComponents(), arg2.getPolicyComponents());
+    }
+    
+    public static boolean compare(PolicyComponent arg1, PolicyComponent arg2) {
+        if (! arg1.getClass().equals(arg2.getClass())) {
+            return false;
+        }
+
+        if (arg1 instanceof Policy) {
+            return compare((Policy) arg1, (Policy) arg2);
+
+        } else if (arg1 instanceof All) {
+            return compare((All) arg1,(All) arg2);
+
+        } else if (arg1 instanceof ExactlyOne) {
+            return compare((ExactlyOne) arg1,
+                    (ExactlyOne) arg2);
+
+        } else if (arg1 instanceof PrimitiveAssertion) {
+            return compare((PrimitiveAssertion) arg1, (PrimitiveAssertion) arg2);
+
+        } else {
+            // TODO should I throw an exception ..
+        }
+
+        return false;
+    }
+
+    public static boolean compare(All arg1,
+            All arg2) {
+        return compare(arg1.getPolicyComponents(), arg2.getPolicyComponents());
+    }
+
+    public static boolean compare(ExactlyOne arg1,
+            ExactlyOne arg2) {
+        return compare(arg1.getPolicyComponents(), arg2.getPolicyComponents());
+    }
+
+    public static boolean compare(PrimitiveAssertion arg1,
+            PrimitiveAssertion arg2) {
+        if (!(arg1.getName().equals(arg2.getName()))) {
+            return false;
+        }
+        return true;
+    }
+
+    private static boolean compare(List arg1, List arg2) {
+        if (arg1.size() != arg2.size()) {
+            return false;
+        }
+        
+        Iterator iterator = arg1.iterator();
+        PolicyComponent assertion1;
+
+        while (iterator.hasNext()) {
+            assertion1 = (PolicyComponent) iterator.next();
+
+            Iterator iterator2 = arg2.iterator();
+            boolean match = false;
+            PolicyComponent assertion2;
+
+            while (iterator2.hasNext()) {
+                assertion2 = (PolicyComponent) iterator2.next();
+                if (compare(assertion1, assertion2)) {
+                    match = true;
+                    break;
+                }
+            }
+
+            if (!match) {
+                return false;
+            }
+        }
+        return true;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org