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/08 17:25:33 UTC

svn commit: r420118 - in /webservices/commons/trunk/modules/neethi: src/org/apache/neethi/ src/org/apache/neethi/builders/ src/org/apache/ws/policy/ test2/org/apache/ws/policy/

Author: sanka
Date: Sat Jul  8 08:25:32 2006
New Revision: 420118

URL: http://svn.apache.org/viewvc?rev=420118&view=rev
Log:
Added new set of Classes and Interfaces which will probably goes as Neeth2. It
is based on a new architecture and contains significant improvements than
previous versions.

Added:
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/
    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/AssertionBuilderFactory.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/PolicyComponent.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyOperator.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyRegistry.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/
    webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/AssertionBuilder.java
Modified:
    webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/AbstractAssertion.java
    webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/All.java
    webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/Policy.java
    webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionPerm.java
    webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionSet.java
    webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/Test_Driver.java

Added: 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=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AbstractPolicyOperator.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,75 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+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 boolean isEmpty() {
+        return policyComponents.isEmpty();
+    }
+    
+    protected List crossProduct(ArrayList allTerms, int index) {
+
+        ArrayList result = new ArrayList();
+        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);
+        }
+
+        Iterator firstTermIter = firstTerm.getPolicyComponents().iterator();
+        
+        while (firstTermIter.hasNext()) {
+            Assertion assertion = (Assertion) firstTermIter.next();
+            Iterator restTermsItr = restTerms.iterator();
+            
+            while (restTermsItr.hasNext()) {
+                Assertion restTerm = (Assertion) restTermsItr.next();
+                All newTerm = new All();
+                newTerm.addPolicyComponents(((All) assertion).getPolicyComponents());
+                newTerm.addPolicyComponents(((All) restTerm).getPolicyComponents());
+                result.add(newTerm);
+            }
+        }
+        
+        return result;
+    }
+    
+}

Added: 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=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/All.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/All.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,126 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public class All extends AbstractPolicyOperator {
+
+    public PolicyComponent normalize(boolean deep) {
+
+        All all = new All();
+        ExactlyOne exactlyOne = new ExactlyOne();
+
+        ArrayList exactlyOnes = new ArrayList();
+
+        if (isEmpty()) {
+            return all;
+        }
+
+        PolicyComponent component;
+
+        for (Iterator iterator = getPolicyComponents().iterator(); iterator
+                .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();
+            }
+
+            if (type == PolicyComponent.EXACTLYONE) {
+
+                if (((ExactlyOne) component).isEmpty()) {
+                    ExactlyOne anExactlyOne = new ExactlyOne();
+                    return anExactlyOne;
+
+                } else {
+                    exactlyOnes.add(component);
+                }
+
+            } else if (type == PolicyComponent.ALL) {
+                all
+                        .addPolicyComponents(((All) component)
+                                .getPolicyComponents());
+
+            } else {
+                all.addPolicyComponent(component);
+            }
+        }
+
+        // processing child ExactlyOne operators
+        if (exactlyOnes.size() > 1) {
+            exactlyOne.addPolicyComponents(crossProduct(exactlyOnes, 0));
+
+        } else if (exactlyOnes.size() == 1) {
+            ExactlyOne anExactlyOne = (ExactlyOne) exactlyOnes.get(0);
+            exactlyOne.addPolicyComponents(anExactlyOne.getPolicyComponents());
+        }
+
+        if (exactlyOne.isEmpty()) {
+            return all;
+        } else if (all.isEmpty()) {
+            return exactlyOne;
+        } else {
+            All anAll;
+            for (Iterator iterator = exactlyOne.getPolicyComponents()
+                    .iterator(); iterator.hasNext();) {
+                anAll = (All) iterator.next();
+                anAll.addPolicyComponents(all.getPolicyComponents());
+            }
+            return exactlyOne;
+        }
+    }
+
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        String prefix = writer.getPrefix(NAMESPACE);
+
+        if (prefix == null) {
+            writer.writeStartElement(PREFIX, ALL, NAMESPACE);
+            writer.writeNamespace(PREFIX, NAMESPACE);
+            writer.setPrefix(PREFIX, NAMESPACE);
+        } else {
+            writer.writeStartElement(NAMESPACE, ALL);
+        }
+
+        PolicyComponent policyComponent;
+
+        for (Iterator iterator = getPolicyComponents().iterator(); iterator
+                .hasNext();) {
+            policyComponent = (PolicyComponent) iterator.next();
+            policyComponent.serialize(writer);
+        }
+
+        writer.writeEndElement();
+    }
+
+    public final short getType() {
+        return PolicyComponent.ALL;
+    }
+}

Added: 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=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Assertion.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,28 @@
+/*
+ * 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.stream.XMLStreamWriter;
+
+public interface Assertion extends PolicyComponent{
+        
+    public Assertion normalize();
+    
+    public Assertion normalize(PolicyRegistry registry);
+    
+    public void serialize(XMLStreamWriter writer);
+    
+}

Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java?rev=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/AssertionBuilderFactory.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,98 @@
+/*
+ * 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.util.HashMap;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.neethi.builders.AssertionBuilder;
+
+/**
+ * AssertionFactory is used to create an Assertion from an OMElement. It uses an
+ * appropriate AssertionBuilder instace to create an Assertion based on the
+ * QName of the given OMElement. Domain Policy authors could right custom
+ * AssertionBuilders to build Assertions for domain specific assertions and
+ * register them.
+ * 
+ */
+public class AssertionBuilderFactory {
+    
+    public static final String POLICY_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+    
+    public static final String POLICY = "Policy";
+    
+    public static final String EXACTLY_ONE = "ExactlyOne";
+    
+    public static final String ALL = "All";
+    
+//    private final QName POLICY_ASSERTION_BUILDER = new QName(
+//            "http://schemas.xmlsoap.org/ws/2004/09/policy", "Policy");
+//
+//    private final QName EXACTLY_ONE_ASSERTION_BUILDER = new QName(
+//            "http://schemas.xmlsoap.org/ws/2004/09/policy", "ExactlyOne");
+//
+//    private final QName ALL_ASSERTION_BUILDER = new QName(
+//            "http://schemas.xmlsoap.org/ws/2004/09/policy", "All");
+
+    private final QName XML_ASSERTION_BUILDER = new QName(
+            "http://test.org/test", "test");
+
+    private HashMap registeredBuilders = new HashMap();
+
+    public AssertionBuilderFactory() {
+//        registerBuilder(POLICY_ASSERTION_BUILDER, new PolicyAssertionBuilder());
+//        registerBuilder(EXACTLY_ONE_ASSERTION_BUILDER,
+//                new ExactlyOneAssertionBuilder());
+//        registerBuilder(ALL_ASSERTION_BUILDER, new AllAssertionBuilder());
+//        registerBuilder(XML_ASSERTION_BUILDER, new XmlAssertionBuilder());
+    }
+
+    public void registerBuilder(QName key, AssertionBuilder builder) {
+        registeredBuilders.put(key, builder);
+    }
+
+    /**
+     * Returns an assertion
+     * @param element
+     * @return
+     */
+    public Assertion build(OMElement element) {
+        OMNamespace namespace = element.getNamespace();
+
+        AssertionBuilder builder;
+
+        if (namespace != null) {
+            QName qname = new QName(namespace.getName(), element.getLocalName());
+            builder = (AssertionBuilder) registeredBuilders.get(qname);
+
+            if (builder != null) {
+                return builder.build(element, this);
+            }
+        }
+
+        builder = (AssertionBuilder) registeredBuilders
+                .get(XML_ASSERTION_BUILDER);
+        return builder.build(element, this);
+    }
+
+    public AssertionBuilder getBuilder(String namespace) {
+        return (AssertionBuilder) registeredBuilders.get(namespace);
+    }
+    
+
+}

Added: 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=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/ExactlyOne.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/ExactlyOne.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,91 @@
+/*
+ * 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.util.Iterator;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public class ExactlyOne extends AbstractPolicyOperator {
+
+    public PolicyComponent normalize(boolean deep) {
+        ExactlyOne exactlyOne = new ExactlyOne();
+
+        if (isEmpty()) {
+            return exactlyOne;
+        }
+        
+        for (Iterator iterator = getPolicyComponents().iterator(); iterator.hasNext();) {
+            PolicyComponent 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(((All) component).getPolicyComponents());
+                
+                component = wrapper.normalize(deep);
+                type = component.getType();
+            }
+            
+            if (type == PolicyComponent.EXACTLYONE) {
+                exactlyOne.addPolicyComponents(((ExactlyOne) component).getPolicyComponents());
+                
+            } else if (type == PolicyComponent.ALL) {
+                exactlyOne.addPolicyComponent(component);
+                
+            } else {
+                All wrapper = new All();
+                wrapper.addPolicyComponent(component);
+                exactlyOne.addPolicyComponent(wrapper);                
+            }
+        }
+        
+        return exactlyOne;
+    }
+    
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        String prefix = writer.getPrefix(NAMESPACE);
+
+        if (prefix == null) {
+            writer.writeStartElement(PREFIX, EXACTLYONE, NAMESPACE);
+            writer.writeNamespace(PREFIX, NAMESPACE);
+            writer.setPrefix(PREFIX, NAMESPACE);
+        } else {
+            writer.writeStartElement(NAMESPACE, EXACTLYONE);
+        }
+        
+        PolicyComponent policyComponent;
+        
+        for (Iterator iterator = getPolicyComponents().iterator(); iterator.hasNext();) {
+            policyComponent = (PolicyComponent) iterator.next();
+            policyComponent.serialize(writer);
+        }
+        
+        writer.writeEndElement();
+
+    }
+    
+    public final short getType() {
+        return PolicyComponent.EXACTLYONE;
+    }
+    
+}

Added: 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=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Policy.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/Policy.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,157 @@
+/*
+ * 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.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public class Policy extends AbstractPolicyOperator {
+
+    public PolicyComponent normalize(boolean deep) {
+        
+        All all = new All();
+        ExactlyOne exactlyOne = new ExactlyOne();
+
+        ArrayList exactlyOnes = new ArrayList();
+
+        if (isEmpty()) {
+            Policy policy = new Policy();
+            policy.addPolicyComponent(exactlyOne);
+            exactlyOne.addPolicyComponent(all);
+            return policy;
+        }
+
+        PolicyComponent component;
+
+        for (Iterator iterator = getPolicyComponents().iterator(); iterator
+                .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();
+            }
+
+            if (type == PolicyComponent.EXACTLYONE) {
+
+                if (((ExactlyOne) component).isEmpty()) {
+                    Policy policy = new Policy();
+                    ExactlyOne anExactlyOne = new ExactlyOne();
+                    
+                    policy.addPolicyComponent(anExactlyOne);
+                    return policy;
+
+                } else {
+                    exactlyOnes.add(component);
+                }
+
+            } else if (type == PolicyComponent.ALL) {
+                all
+                        .addPolicyComponents(((All) component)
+                                .getPolicyComponents());
+
+            } else {
+                all.addPolicyComponent(component);
+            }
+        }
+
+        // processing child ExactlyOne operators
+        if (exactlyOnes.size() > 1) {
+            exactlyOne.addPolicyComponents(crossProduct(exactlyOnes, 0));
+
+        } else if (exactlyOnes.size() == 1) {
+            ExactlyOne anExactlyOne = (ExactlyOne) exactlyOnes.get(0);
+            exactlyOne.addPolicyComponents(anExactlyOne.getPolicyComponents());
+        }
+
+        if (exactlyOne.isEmpty()) {
+            Policy policy = new Policy();
+            ExactlyOne anExactlyOne = new ExactlyOne();
+            
+            policy.addPolicyComponent(anExactlyOne);
+            anExactlyOne.addPolicyComponent(all);
+            return policy;
+            
+        } else if (all.isEmpty()) {
+            Policy policy = new Policy();
+            policy.addPolicyComponent(exactlyOne);
+            
+            return policy;
+            
+        } else {
+            Policy policy = new Policy();
+            
+            All anAll;
+            
+            for (Iterator iterator = exactlyOne.getPolicyComponents()
+                    .iterator(); iterator.hasNext();) {
+                anAll = (All) iterator.next();
+                anAll.addPolicyComponents(all.getPolicyComponents());
+            }
+            
+            policy.addPolicyComponent(exactlyOne);
+            return policy;
+        }
+    }
+    
+    public Policy merge(Policy policy) {
+        throw new UnsupportedOperationException("still not implemented");
+    }
+    
+    public Policy intersect(Policy policy) {
+        throw new UnsupportedOperationException("still not implemented");
+    }
+    
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        String prefix = writer.getPrefix(NAMESPACE);
+
+        if (prefix == null) {
+            writer.writeStartElement(PREFIX, POLICY, NAMESPACE);
+            writer.writeNamespace(PREFIX, NAMESPACE);
+            writer.setPrefix(PREFIX, NAMESPACE);
+            
+        } else {
+            writer.writeStartElement(NAMESPACE, POLICY);
+        }
+        
+        PolicyComponent policyComponent;
+        
+        for (Iterator iterator = getPolicyComponents().iterator(); iterator.hasNext();) {
+            policyComponent = (PolicyComponent) iterator.next();
+            policyComponent.serialize(writer);
+        }
+        
+        writer.writeEndElement();
+
+    }
+    
+    public final short getType() {
+        return PolicyComponent.POLICY;
+    }
+    
+}

Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java?rev=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyComponent.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,36 @@
+/*
+ * 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.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+public interface PolicyComponent {
+    
+    public static final short POLICY = 0x1;
+    
+    public static final short EXACTLYONE = 0x2;
+    
+    public static final short ALL = 0x3;
+    
+    public static final short ASSERTION = 0x4;
+    
+    
+    
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException;
+    
+    public short getType();
+}

Added: 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=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyManager.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,89 @@
+/*
+ * 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.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+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";
+    
+    public static final String EXACTLY_ONE = "ExactlyOne";
+    
+    public static final String ALL = "All";
+    
+    private static AssertionBuilderFactory factory = new AssertionBuilderFactory();
+    
+    
+    public static void registerBuilder(QName qname, AssertionBuilder builder) {
+        factory.registerBuilder(qname, builder);
+    }
+    public static Policy getPolicy(OMElement element) {
+        return getPolicyOperator(element);        
+    }
+    
+    public static Policy getPolicyOperator(OMElement element) {
+        return (Policy) processOperationElement(element, new Policy());        
+    }
+    
+    public static ExactlyOne getExactlyOneOperator(OMElement element) {
+        return (ExactlyOne) processOperationElement(element, new ExactlyOne());
+    }
+    
+    public static All getAllOperator(OMElement element) {
+        return (All) processOperationElement(element, new All());
+    }
+    
+    private static PolicyOperator processOperationElement(OMElement operationElement, PolicyOperator operator) {
+        
+        OMElement childElement;
+        
+        for (Iterator iterator = operationElement.getChildElements(); iterator.hasNext(); ) {
+            childElement = (OMElement) iterator.next();
+            
+            if (PolicyOperator.NAMESPACE.equals(childElement.getNamespace().getName())) {
+                
+                if (PolicyOperator.POLICY.equals(childElement.getLocalName())) {
+                    operator.addPolicyComponent(getPolicyOperator(childElement));
+                    
+                } else if (PolicyOperator.EXACTLYONE.equals(childElement.getLocalName())) {
+                    operator.addPolicyComponent(getExactlyOneOperator(childElement));
+                    
+                } else if (PolicyOperator.ALL.equals(childElement.getLocalName())) {
+                    operator.addPolicyComponent(getAllOperator(childElement));
+                }
+            } else {
+                
+                AssertionBuilder builder = factory.getBuilder(childElement.getNamespace().getName());
+                
+                if (builder == null) {    
+                    XmlPrimtiveAssertion xmlPrimtiveAssertion = new XmlPrimtiveAssertion(childElement);
+                    operator.addPolicyComponent(xmlPrimtiveAssertion);
+                    
+                } else {
+                    operator.addPolicyComponent(builder.build(childElement, factory));
+                }                
+            }
+        }
+        return operator;
+    } 
+}

Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyOperator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyOperator.java?rev=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyOperator.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyOperator.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,32 @@
+/*
+ * 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.util.List;
+
+
+public interface PolicyOperator extends PolicyComponent {
+    
+    public static final String NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+    public static final String PREFIX = "wsp";
+    public static final String POLICY = "Policy";
+    public static final String EXACTLYONE = "ExactlyOne";
+    public static final String ALL = "All";
+    
+    public void addPolicyComponent(PolicyComponent component);
+    public List getPolicyComponents();
+    public PolicyComponent normalize(boolean deep);
+}

Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyRegistry.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyRegistry.java?rev=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyRegistry.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/PolicyRegistry.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public interface PolicyRegistry {
+    
+    public void register(String key, Object policy);
+    
+    public Object lookup(String key);
+
+}

Added: 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=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/XmlPrimtiveAssertion.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,62 @@
+/*
+ * 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.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+
+public class XmlPrimtiveAssertion implements Assertion {
+
+    OMElement element;
+    
+    public XmlPrimtiveAssertion(OMElement element) {
+        setValue(element);
+    }
+
+    public void setValue(OMElement element) {
+        this.element = element;
+    }
+
+    public OMElement getValue() {
+        return element;
+    }
+
+    public Assertion normalize() throws IllegalArgumentException {
+        return normalize(null);
+    }
+
+    public Assertion normalize(PolicyRegistry registry) {
+        return this;
+    }
+
+    public void serialize(XMLStreamWriter writer) {
+        if (element != null) {
+            try {
+                element.serialize(writer);
+            } catch (XMLStreamException ex) {
+                throw new RuntimeException(ex);
+            }
+        } else {
+            // TODO throw an exception??
+        }
+    }
+    
+    public final short getType() {
+        return PolicyComponent.ASSERTION;
+    }
+}

Added: webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/AssertionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/AssertionBuilder.java?rev=420118&view=auto
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/AssertionBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/neethi/builders/AssertionBuilder.java Sat Jul  8 08:25:32 2006
@@ -0,0 +1,37 @@
+/*
+ * 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.builders;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+
+/**
+ * AssertionBuilder is the interface which must implement by any
+ * CustomAssertionBuilder. It defines a single method which takes an OMElement
+ * and an AssertionFactory instace and creates an Assertion from the given
+ * OMElement. Custom AssertionBuilder authors can use the AssertionFactory
+ * specified to build Assertions for any unknown OMElements inside the given
+ * OMElement. They are given the opportunity to control the behaviour of
+ * Assertion operations based on the corresponding domain policy assertion of
+ * the given OMElement and the level of its processing.
+ * 
+ */
+public interface AssertionBuilder {
+
+    public Assertion build(OMElement element, AssertionBuilderFactory factory)
+            throws IllegalArgumentException;
+}

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/AbstractAssertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/AbstractAssertion.java?rev=420118&r1=420117&r2=420118&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/AbstractAssertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/AbstractAssertion.java Sat Jul  8 08:25:32 2006
@@ -202,4 +202,41 @@
     public int getLineNo() {
         return lineNo;
     }
+    
+    /**
+     * @param allTerms
+     *            XorCompositeAssertion to be corssproducted
+     * @param index
+     *            starting point of cross product
+     * @return
+     */
+    protected static ArrayList crossProduct(ArrayList allTerms, int index) {
+
+        ArrayList result = new ArrayList();
+        ExactlyOne firstTerm = (ExactlyOne) allTerms
+                .get(index);
+        ArrayList restTerms;
+
+        if (allTerms.size() == ++index) {
+            restTerms = new ArrayList();
+            All newTerm = new All();
+            restTerms.add(newTerm);
+        } else
+            restTerms = crossProduct(allTerms, index);
+
+        Iterator firstTermIter = firstTerm.getTerms().iterator();
+        while (firstTermIter.hasNext()) {
+            Assertion assertion = (Assertion) firstTermIter.next();
+            Iterator restTermsItr = restTerms.iterator();
+            while (restTermsItr.hasNext()) {
+                Assertion restTerm = (Assertion) restTermsItr.next();
+                All newTerm = new All();
+                newTerm.addTerms(assertion.getTerms());
+                newTerm.addTerms(restTerm.getTerms());
+                result.add(newTerm);
+            }
+        }
+
+        return result;
+    }
 }

Modified: webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/All.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/All.java?rev=420118&r1=420117&r2=420118&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/All.java (original)
+++ webservices/commons/trunk/modules/neethi/src/org/apache/ws/policy/All.java Sat Jul  8 08:25:32 2006
@@ -31,317 +31,310 @@
  * 
  * Sanka Samaranayake (sanka@apache.org)
  */
-public class All extends AbstractAssertion implements
-		CompositeAssertion {
+public class All extends AbstractAssertion implements CompositeAssertion {
 
-	private Log log = LogFactory.getLog(this.getClass().getName());
+    private Log log = LogFactory.getLog(this.getClass().getName());
 
-	public All() {
-	}
+    public All() {
+    }
 
-	/**
-	 * Adds an Assertion to its terms list
-	 * 
-	 * @param assertion
-	 *            Assertion to be added
-	 */
-	public void addTerm(Assertion assertion) {
-		if (!(isNormalized() && (assertion instanceof PrimitiveAssertion))) {
-			setNormalized(false);
-		}
-		super.addTerm(assertion);
-	}
-
-	/**
-	 * Returns the intersection of self and argument against a specified Policy
-	 * Registry.
-	 * 
-	 * @param assertion
-	 *            the assertion to intersect with self
-	 * @param reg
-	 *            a sepcified policy registry
-	 * @return assertion the assertion which is equivalent to intersection
-	 *         between self and the argument
-	 */
-	public Assertion intersect(Assertion assertion, PolicyRegistry reg) {
-		log.debug("Enter: All::intersect");
-
-		Assertion normalizedMe = ((isNormalized()) ? this : normalize(reg));
-
-		if (!(normalizedMe instanceof All)) {
-			return normalizedMe.intersect(assertion, reg);
-		}
-
-		Assertion target = (assertion.isNormalized()) ? assertion : assertion
-				.normalize(reg);
-		short type = target.getType();
-
-		switch (type) {
-
-		case Assertion.POLICY: {
-			Policy newPolicy = new Policy();
-			newPolicy
-					.addTerm(normalizedMe
-							.intersect((ExactlyOne) target
-									.getTerms().get(0)));
-			return newPolicy;
-		}
-
-		case Assertion.EXACTLY_ONE: {
-			ExactlyOne newExactlyOne = new ExactlyOne();
-
-			for (Iterator iterator = target.getTerms().iterator(); iterator
-					.hasNext();) {
-				Assertion asser = normalizedMe
-						.intersect((All) iterator.next());
-                
-				if (Assertion.ALL == asser.getType()) {
-					newExactlyOne.addTerm(asser);
-				}
-			}
-			return newExactlyOne;
-		}
-
-		case Assertion.ALL: {
-			List primitives_A = ((normalizedMe.size() > target.size()) ? normalizedMe
-					.getTerms()
-					: target.getTerms());
-			List primtives_B = ((normalizedMe.size() > target.size()) ? target
-					.getTerms() : normalizedMe.getTerms());
-
-			boolean isMatch = true;
-			PrimitiveAssertion primitive_A, primitive_B = null;
-			//				QName name_A, name_B;
-
-			for (int i = 0; i < primitives_A.size(); i++) {
-				primitive_A = (PrimitiveAssertion) primitives_A.get(i);
-				//					name_A = PRIMITIVE_A.getName();
-
-				boolean flag = false;
-
-				for (int j = 0; j < primtives_B.size(); j++) {
-					primitive_B = (PrimitiveAssertion) primtives_B.get(j);
-					//						name_B = PRIMTIVE_B.getName();
-
-					if (primitive_A.getName().equals(primitive_B.getName())) {
-						flag = true;
-						break;
-					}
-				}
-
-				if (!flag) {
-					return new ExactlyOne();
-				}
-
-				Assertion a = primitive_A.intersect(primitive_B);
-
-				if (a instanceof ExactlyOne) {
-					return new ExactlyOne();
-				}
-			}
-			All result = new All();
-			result.addTerms(primitives_A);
-			result.addTerms(primtives_B);
-			return result;
-		}
-
-		case Assertion.PRIMITIVE: {
-			QName name = ((PrimitiveAssertion) target).getName();
-			boolean isMatch = false;
-
-			QName targetName;
-			for (Iterator iterator = normalizedMe.getTerms().iterator(); iterator
-					.hasNext();) {
-				targetName = ((PrimitiveAssertion) iterator.next()).getName();
-
-				if (name.getNamespaceURI().equals(targetName.getNamespaceURI())) {
-					isMatch = true;
-					break;
-				}
-			}
-
-			if (isMatch) {
-				All newAll = new All();
-				newAll.addTerms(normalizedMe.getTerms());
-				newAll.addTerm(target);
-				return newAll;
-			}
-
-			return new ExactlyOne();
-		}
-
-		default: {
-			throw new IllegalArgumentException("intersect is not defined for "
-					+ target.getClass().getName() + "type assertions");
-		}
-
-		}
-	}
-
-	/**
-	 * Returns an assertion which is equivalent to merge of self and the
-	 * argument.
-	 * 
-	 * @param assertion
-	 *            the assertion to be merged with
-	 * @param reg
-	 *            the policy registry which the is used resolve external policy
-	 *            references
-	 * @return assertion the resultant assertion which is equivalent to merge of
-	 *         self and argument
-	 */
-	public Assertion merge(Assertion assertion, PolicyRegistry reg) {
-		log.debug("Enter: All::merge");
-
-		Assertion normalizedMe = (isNormalized()) ? this : normalize(reg);
-
-		if (!(normalizedMe instanceof All)) {
-			return normalizedMe.merge(assertion, reg);
-		}
-
-		Assertion target = (assertion.isNormalized()) ? assertion : assertion
-				.normalize(reg);
-
-		switch (target.getType()) {
-
-		case Assertion.POLICY: {
-			Policy newPolicy = new Policy();
-			newPolicy.addTerm(normalizedMe.merge((ExactlyOne) target
-					.getTerms().get(0)));
-			return newPolicy;
-		}
-
-		case Assertion.EXACTLY_ONE: {
-
-			ExactlyOne newExactlyOne = new ExactlyOne();
-
-			for (Iterator iterator = target.getTerms().iterator(); iterator
-					.hasNext();) {
-				All all = (All) iterator
-						.next();
-				newExactlyOne.addTerm(normalizedMe.merge(all));
-			}
-
-			return newExactlyOne;
-		}
-
-		case Assertion.ALL: {
-			All newAll = new All();
-
-			newAll.addTerms(normalizedMe.getTerms());
-			newAll.addTerms(target.getTerms());
-
-			return newAll;
-		}
-
-		case Assertion.PRIMITIVE: {
-			All newAll = new All();
-
-			newAll.addTerms(normalizedMe.getTerms());
-			newAll.addTerm(target);
-
-			return newAll;
-		}
-
-		default: {
-			throw new IllegalArgumentException("merge is not defined for");
-		}
-		}
-	}
-
-	/**
-	 * Returns an Assertion which is normalized using a specified policy
-	 * registry.
-	 * 
-	 * @param reg
-	 *            the policy registry used to resolve policy references
-	 * @return an Assertion which is the normalized form of self
-	 */
-	public Assertion normalize(PolicyRegistry reg) {
-		log.debug("Enter: All::normalize");
-
-		if (isNormalized()) {
-			return this;
-		}
-
-		All all = new All();
-		ExactlyOne exactlyOne = new ExactlyOne();
-
-		ArrayList exactlyOnes = new ArrayList();
-
-		if (isEmpty()) {
-			all.setNormalized(true);
-			return all;
-		}
-
-		Iterator terms = getTerms().iterator();
-
-		while (terms.hasNext()) {
-			Assertion term = (Assertion) terms.next();
-			term = (term instanceof Policy) ? term : term.normalize(reg);
-
-			if (term instanceof Policy) {
-				Assertion wrapper = new All();
-				((All) wrapper).addTerms(((Policy) term)
-						.getTerms());
-				term = wrapper.normalize(reg);
-			}
-
-			if (term instanceof ExactlyOne) {
-
-				if (((ExactlyOne) term).isEmpty()) {
-
-					/*  */
-					ExactlyOne anExactlyOne = new ExactlyOne();
-					anExactlyOne.setNormalized(true);
-					return anExactlyOne;
-				}
-				exactlyOnes.add(term);
-				continue;
-
-			}
-
-			if (term instanceof All) {
-				all.addTerms(((All) term).getTerms());
-				continue;
-			}
-
-			all.addTerm(term);
-		}
-
-		// processing child-XORCompositeAssertions
-		if (exactlyOnes.size() > 1) {
-            exactlyOne.addTerms(Policy.crossProduct(exactlyOnes, 0));
-            
-		} else if (exactlyOnes.size() == 1) {
-			Assertion XORterm = (Assertion) exactlyOnes.get(0);
-			exactlyOne.addTerms(XORterm.getTerms());
-		}
-
-		if (exactlyOne.isEmpty()) {
-			all.setNormalized(true);
-			return all;
-		}
-
-		if (all.isEmpty()) {
-			exactlyOne.setNormalized(true);
-			return exactlyOne;
-		}
-
-		List primTerms = all.getTerms();
-		Iterator interator = exactlyOne.getTerms().iterator();
-
-		while (interator.hasNext()) {
-			Assertion newAll = (Assertion) interator.next();
-			newAll.addTerms(primTerms);
-		}
-
-		exactlyOne.setNormalized(true);
-		return exactlyOne;
-	}
-
-	public final short getType() {
-		return Assertion.ALL;
-	}
+    /**
+     * Adds an Assertion to its terms list
+     * 
+     * @param assertion
+     *            Assertion to be added
+     */
+    public void addTerm(Assertion assertion) {
+        if (!(isNormalized() && (assertion instanceof PrimitiveAssertion))) {
+            setNormalized(false);
+        }
+        super.addTerm(assertion);
+    }
+
+    /**
+     * Returns the intersection of self and argument against a specified Policy
+     * Registry.
+     * 
+     * @param assertion
+     *            the assertion to intersect with self
+     * @param reg
+     *            a sepcified policy registry
+     * @return assertion the assertion which is equivalent to intersection
+     *         between self and the argument
+     */
+    public Assertion intersect(Assertion assertion, PolicyRegistry reg) {
+        log.debug("Enter: All::intersect");
+
+        Assertion normalizedMe = ((isNormalized()) ? this : normalize(reg));
+
+        if (!(normalizedMe instanceof All)) {
+            return normalizedMe.intersect(assertion, reg);
+        }
+
+        Assertion target = (assertion.isNormalized()) ? assertion : assertion
+                .normalize(reg);
+        short type = target.getType();
+
+        switch (type) {
+
+        case Assertion.POLICY: {
+            Policy newPolicy = new Policy();
+            newPolicy.addTerm(normalizedMe.intersect((ExactlyOne) target
+                    .getTerms().get(0)));
+            return newPolicy;
+        }
+
+        case Assertion.EXACTLY_ONE: {
+            ExactlyOne newExactlyOne = new ExactlyOne();
+
+            for (Iterator iterator = target.getTerms().iterator(); iterator
+                    .hasNext();) {
+                Assertion asser = normalizedMe.intersect((All) iterator.next());
+
+                if (Assertion.ALL == asser.getType()) {
+                    newExactlyOne.addTerm(asser);
+                }
+            }
+            return newExactlyOne;
+        }
+
+        case Assertion.ALL: {
+            List primitives_A = ((normalizedMe.size() > target.size()) ? normalizedMe
+                    .getTerms()
+                    : target.getTerms());
+            List primtives_B = ((normalizedMe.size() > target.size()) ? target
+                    .getTerms() : normalizedMe.getTerms());
+
+            PrimitiveAssertion primitive_A, primitive_B = null;
+            //				QName name_A, name_B;
+
+            for (int i = 0; i < primitives_A.size(); i++) {
+                primitive_A = (PrimitiveAssertion) primitives_A.get(i);
+                //					name_A = PRIMITIVE_A.getName();
+
+                boolean flag = false;
+
+                for (int j = 0; j < primtives_B.size(); j++) {
+                    primitive_B = (PrimitiveAssertion) primtives_B.get(j);
+                    //						name_B = PRIMTIVE_B.getName();
+
+                    if (primitive_A.getName().equals(primitive_B.getName())) {
+                        flag = true;
+                        break;
+                    }
+                }
+
+                if (!flag) {
+                    return new ExactlyOne();
+                }
+
+                Assertion a = primitive_A.intersect(primitive_B);
+
+                if (a instanceof ExactlyOne) {
+                    return new ExactlyOne();
+                }
+            }
+            All result = new All();
+            result.addTerms(primitives_A);
+            result.addTerms(primtives_B);
+            return result;
+        }
+
+        case Assertion.PRIMITIVE: {
+            QName name = ((PrimitiveAssertion) target).getName();
+            boolean isMatch = false;
+
+            QName targetName;
+            for (Iterator iterator = normalizedMe.getTerms().iterator(); iterator
+                    .hasNext();) {
+                targetName = ((PrimitiveAssertion) iterator.next()).getName();
+
+                if (name.getNamespaceURI().equals(targetName.getNamespaceURI())) {
+                    isMatch = true;
+                    break;
+                }
+            }
+
+            if (isMatch) {
+                All newAll = new All();
+                newAll.addTerms(normalizedMe.getTerms());
+                newAll.addTerm(target);
+                return newAll;
+            }
+
+            return new ExactlyOne();
+        }
+
+        default: {
+            throw new IllegalArgumentException("intersect is not defined for "
+                    + target.getClass().getName() + "type assertions");
+        }
+
+        }
+    }
+
+    /**
+     * Returns an assertion which is equivalent to merge of self and the
+     * argument.
+     * 
+     * @param assertion
+     *            the assertion to be merged with
+     * @param reg
+     *            the policy registry which the is used resolve external policy
+     *            references
+     * @return assertion the resultant assertion which is equivalent to merge of
+     *         self and argument
+     */
+    public Assertion merge(Assertion assertion, PolicyRegistry reg) {
+        log.debug("Enter: All::merge");
+
+        Assertion normalizedMe = (isNormalized()) ? this : normalize(reg);
+
+        if (!(normalizedMe instanceof All)) {
+            return normalizedMe.merge(assertion, reg);
+        }
+
+        Assertion target = (assertion.isNormalized()) ? assertion : assertion
+                .normalize(reg);
+
+        switch (target.getType()) {
+
+        case Assertion.POLICY: {
+            Policy newPolicy = new Policy();
+            newPolicy.addTerm(normalizedMe.merge((ExactlyOne) target.getTerms()
+                    .get(0)));
+            return newPolicy;
+        }
+
+        case Assertion.EXACTLY_ONE: {
+
+            ExactlyOne newExactlyOne = new ExactlyOne();
+
+            for (Iterator iterator = target.getTerms().iterator(); iterator
+                    .hasNext();) {
+                All all = (All) iterator.next();
+                newExactlyOne.addTerm(normalizedMe.merge(all));
+            }
+
+            return newExactlyOne;
+        }
+
+        case Assertion.ALL: {
+            All newAll = new All();
+
+            newAll.addTerms(normalizedMe.getTerms());
+            newAll.addTerms(target.getTerms());
+
+            return newAll;
+        }
+
+        case Assertion.PRIMITIVE: {
+            All newAll = new All();
+
+            newAll.addTerms(normalizedMe.getTerms());
+            newAll.addTerm(target);
+
+            return newAll;
+        }
+
+        default: {
+            throw new IllegalArgumentException("merge is not defined for");
+        }
+        }
+    }
+
+    /**
+     * Returns an Assertion which is normalized using a specified policy
+     * registry.
+     * 
+     * @param reg
+     *            the policy registry used to resolve policy references
+     * @return an Assertion which is the normalized form of self
+     */
+    public Assertion normalize(PolicyRegistry reg) {
+        log.debug("Enter: All::normalize");
+
+        if (isNormalized()) {
+            return this;
+        }
+
+        All all = new All();
+        ExactlyOne exactlyOne = new ExactlyOne();
+
+        ArrayList exactlyOnes = new ArrayList();
+
+        if (isEmpty()) {
+            all.setNormalized(true);
+            return all;
+        }
+
+        Iterator terms = getTerms().iterator();
+
+        while (terms.hasNext()) {
+            Assertion term = (Assertion) terms.next();
+            term = (term instanceof Policy) ? term : term.normalize(reg);
+
+            if (term instanceof Policy) {
+                Assertion wrapper = new All();
+                ((All) wrapper).addTerms(((Policy) term).getTerms());
+                term = wrapper.normalize(reg);
+            }
+
+            if (term instanceof ExactlyOne) {
+
+                if (((ExactlyOne) term).isEmpty()) {
+
+                    /*  */
+                    ExactlyOne anExactlyOne = new ExactlyOne();
+                    anExactlyOne.setNormalized(true);
+                    return anExactlyOne;
+                }
+                exactlyOnes.add(term);
+                continue;
+
+            }
+
+            if (term instanceof All) {
+                all.addTerms(((All) term).getTerms());
+                continue;
+            }
+
+            all.addTerm(term);
+        }
+
+        // processing child-XORCompositeAssertions
+        if (exactlyOnes.size() > 1) {
+            exactlyOne.addTerms(AbstractAssertion.crossProduct(exactlyOnes, 0));
+
+        } else if (exactlyOnes.size() == 1) {
+            Assertion XORterm = (Assertion) exactlyOnes.get(0);
+            exactlyOne.addTerms(XORterm.getTerms());
+        }
+
+        if (exactlyOne.isEmpty()) {
+            all.setNormalized(true);
+            return all;
+        }
+
+        if (all.isEmpty()) {
+            exactlyOne.setNormalized(true);
+            return exactlyOne;
+        }
+
+        List primTerms = all.getTerms();
+        Iterator interator = exactlyOne.getTerms().iterator();
+
+        while (interator.hasNext()) {
+            Assertion newAll = (Assertion) interator.next();
+            newAll.addTerms(primTerms);
+        }
+
+        exactlyOne.setNormalized(true);
+        return exactlyOne;
+    }
+
+    public final short getType() {
+        return Assertion.ALL;
+    }
 
 }

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=420118&r1=420117&r2=420118&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 Sat Jul  8 08:25:32 2006
@@ -167,7 +167,6 @@
         All all = new All();
         ExactlyOne exactlyOne = new ExactlyOne();
 
-        ArrayList childAndTermList = new ArrayList();
         ArrayList childXorTermList = new ArrayList();
 
         Iterator terms = getTerms().iterator();
@@ -225,7 +224,7 @@
         // processing child-XORCompositeAssertions
         if (childXorTermList.size() > 1) {
 
-            exactlyOne.addTerms(Policy.crossProduct(childXorTermList, 0));
+            exactlyOne.addTerms(AbstractAssertion.crossProduct(childXorTermList, 0));
 
         } else if (childXorTermList.size() == 1) {
             Assertion tmpExactlyOne = (Assertion) childXorTermList.get(0);
@@ -422,6 +421,8 @@
     }
 
     /**
+<<<<<<< .mine
+=======
      * @param allTerms
      *            ExactlyOne to be corssproducted
      * @param index
@@ -459,6 +460,7 @@
     }
 
     /**
+>>>>>>> .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.

Modified: webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionPerm.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionPerm.java?rev=420118&r1=420117&r2=420118&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionPerm.java (original)
+++ webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionPerm.java Sat Jul  8 08:25:32 2006
@@ -18,8 +18,8 @@
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
+
 import javax.xml.namespace.QName;
-import org.apache.ws.policy.*;
 
 /**
  * <p>Class to represent an Assertion permutation.

Modified: webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionSet.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionSet.java?rev=420118&r1=420117&r2=420118&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionSet.java (original)
+++ webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/AssertionSet.java Sat Jul  8 08:25:32 2006
@@ -18,8 +18,6 @@
 import java.util.List;
 import java.util.Vector;
 
-import org.apache.ws.policy.*;
-
 /**
  * <p>
  * Class to represent a collection of PermValues.

Modified: webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/Test_Driver.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/Test_Driver.java?rev=420118&r1=420117&r2=420118&view=diff
==============================================================================
--- webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/Test_Driver.java (original)
+++ webservices/commons/trunk/modules/neethi/test2/org/apache/ws/policy/Test_Driver.java Sat Jul  8 08:25:32 2006
@@ -29,8 +29,8 @@
   public static void main(String[] args) {
     WSPTestSuite suite = new WSPTestSuite(Test_Driver.class);
 
-//    suite.addTestSuite(Test_JIRA14.class);
-//    suite.addTestSuite(Test_Policy.class);
+    suite.addTestSuite(Test_JIRA14.class);
+    suite.addTestSuite(Test_Policy.class);
     suite.addTestSuite(Test_EffectivePolicy.class);
 
     suite.run();



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