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/09/18 09:23:41 UTC

svn commit: r447300 - in /webservices/commons/trunk/modules/neethi/src: main/java/org/apache/neethi/ main/java/org/apache/neethi/builders/ main/java/org/apache/neethi/builders/xml/ test/test3/org/apache/neethi/

Author: sanka
Date: Mon Sep 18 00:23:40 2006
New Revision: 447300

URL: http://svn.apache.org/viewvc?view=rev&rev=447300
Log:

(1) Integrated the patch that Amila has submitted.

(2) Modified the PolicyEngine to read implicit /explicit PolicyReferences.

(3) Moved the Constants to the Constants.java class


Added:
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistryImpl.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java
Removed:
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/XmlPrimtiveAssertion.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/XMLPrimitiveAssertionBuilder.java
Modified:
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyComponent.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyOperator.java
    webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistry.java
    webservices/commons/trunk/modules/neethi/src/test/test3/org/apache/neethi/MergeTest.java

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java Mon Sep 18 00:23:40 2006
@@ -47,66 +47,26 @@
     public boolean isEmpty() {
         return policyComponents.isEmpty();
     }
-
-    public PolicyComponent normalize() {
-        return normalize(true);
-    }
-
-    /**
-     * normalized form of the the assertion, all and Exactly one define as
-     * <ExactlyOne>
-     * <All>
-     * <Assertion/>
-     * </All>
-     * <ExactlyOne>
-     *
-     * @param deep - normalize the assertions or not - currently assertion normalization is not implemented
-     * @return the normalize form of this policy commponent
-     */
-
-    public PolicyComponent normalize(boolean deep) {
-        return AbstractPolicyOperator.normalize(this, deep);
+    
+    public boolean equal(PolicyComponent policyComponent) {
+        return PolicyComparator.compare(this, policyComponent);
     }
     
-    /**
-     * here it is assumed that the two arguments passed to the method are not empty arguments
-     * and exactlyOne1 and exactlyOne2 in normal form
-     *
-     * @param exactlyOne1
-     * @param exactlyOne2
-     * @return cross product of the two exactlyones
-     */
-    private static ExactlyOne getCrossProduct(ExactlyOne exactlyOne1, ExactlyOne exactlyOne2) {
-        ExactlyOne crossProduct = new ExactlyOne();
-        All crossProductAll;
-
-        All currentAll1;
-        All currentAll2;
-
-        for (Iterator iter1 = exactlyOne1.getPolicyComponents().iterator(); iter1.hasNext();) {
-            currentAll1 = (All) iter1.next();
-
-            for (Iterator iter2 = exactlyOne2.getPolicyComponents().iterator(); iter2.hasNext();) {
-                currentAll2 = (All) iter2.next();
-                crossProductAll = new All();
-                crossProductAll.addPolicyComponents(currentAll1.getPolicyComponents());
-                crossProductAll.addPolicyComponents(currentAll2.getPolicyComponents());
-                crossProduct.addPolicyComponent(crossProductAll);
-            }
-        }
-
-        return crossProduct;
+    protected static Policy normalize(Policy policy, PolicyRegistry reg, boolean deep) {
+        Policy result = new Policy();
+        result.addPolicyComponent(normalizeOperator(policy,reg, deep));
+        return result;
     }
-        
-    private static PolicyComponent normalize(PolicyOperator operator, boolean deep) {
-                
+    
+    private static PolicyComponent normalizeOperator(PolicyOperator operator, PolicyRegistry reg, boolean deep) {
+                        
         short type = operator.getType();
                 
         
         if (operator.isEmpty()) {
             ExactlyOne exactlyOne = new ExactlyOne();
             
-            if (PolicyComponent.EXACTLYONE != type) {
+            if (Constants.TYPE_EXACTLYONE != type) {
                 exactlyOne.addPolicyComponent(new All());
             }
             return exactlyOne;
@@ -118,13 +78,13 @@
         for (Iterator iterator = operator.getPolicyComponents().iterator(); iterator.hasNext();) {
             policyComponent = (PolicyComponent) iterator.next();
             
-            if (policyComponent.getType() == PolicyComponent.ASSERTION) {
+            if (policyComponent.getType() == Constants.TYPE_ASSERTION) {
                 
                 if (deep) {
                     policyComponent = ((Assertion) policyComponent).normalize();                    
                 }
                 
-                if (policyComponent.getType() == PolicyComponent.POLICY) {
+                if (policyComponent.getType() == Constants.TYPE_POLICY) {
                     childComponentsList.add(((Policy) policyComponent).getFirstPolicyComponent());
                     
                 } else  {
@@ -135,14 +95,21 @@
                     exactlyOne.addPolicyComponent(all);
                     childComponentsList.add(exactlyOne);
                 }
+            } else if (policyComponent.getType() == Constants.TYPE_POLICYREF) {
+                String uri = ((PolicyReference) policyComponent).getURI();
+                policyComponent = reg.lookup(uri);
+                
+                if (policyComponent == null) {
+                    throw new RuntimeException(uri + " can't be resolved");
+                }
                 
-            } else if (policyComponent.getType() == PolicyComponent.POLICY) {
+            } else if (policyComponent.getType() == Constants.TYPE_POLICY) {
                 All all = new All();
                 all.addPolicyComponents(((Policy) policyComponent).getPolicyComponents());
-                childComponentsList.add(all.normalize(deep));
+                childComponentsList.add(AbstractPolicyOperator.normalizeOperator(all, reg, deep));
                 
             } else {
-                childComponentsList.add(((AbstractPolicyOperator) policyComponent).normalize(deep));
+                childComponentsList.add(AbstractPolicyOperator.normalizeOperator((PolicyOperator) policyComponent, reg, deep));
             }            
         }
         
@@ -159,7 +126,7 @@
         
         ExactlyOne exactlyOne = new ExactlyOne();
         
-        if (componentType == PolicyComponent.EXACTLYONE) {            
+        if (componentType == Constants.TYPE_EXACTLYONE) {            
             ExactlyOne innerExactlyOne;
             
             for (Iterator iter = normalizedInnerComponets.iterator(); iter.hasNext();) {
@@ -167,7 +134,7 @@
                 exactlyOne.addPolicyComponents(innerExactlyOne.getPolicyComponents());
             }
             
-        } else if ((componentType == PolicyComponent.POLICY) || (componentType == PolicyComponent.ALL)) {
+        } else if ((componentType == Constants.TYPE_POLICY) || (componentType == Constants.TYPE_ALL)) {
             // if the parent type is All then we have to get the cross product
             if (normalizedInnerComponets.size() > 1) {
                 // then we have to get the cross product with each other to process all elements
@@ -200,8 +167,26 @@
         
         return exactlyOne;
     }
+    
+    private static ExactlyOne getCrossProduct(ExactlyOne exactlyOne1, ExactlyOne exactlyOne2) {
+        ExactlyOne crossProduct = new ExactlyOne();
+        All crossProductAll;
 
-    public boolean equal(PolicyComponent policyComponent) {
-        return PolicyComparator.compare(this, policyComponent);
+        All currentAll1;
+        All currentAll2;
+
+        for (Iterator iter1 = exactlyOne1.getPolicyComponents().iterator(); iter1.hasNext();) {
+            currentAll1 = (All) iter1.next();
+
+            for (Iterator iter2 = exactlyOne2.getPolicyComponents().iterator(); iter2.hasNext();) {
+                currentAll2 = (All) iter2.next();
+                crossProductAll = new All();
+                crossProductAll.addPolicyComponents(currentAll1.getPolicyComponents());
+                crossProductAll.addPolicyComponents(currentAll2.getPolicyComponents());
+                crossProduct.addPolicyComponent(crossProductAll);
+            }
+        }
+
+        return crossProduct;
     }
 }

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java Mon Sep 18 00:23:40 2006
@@ -36,14 +36,14 @@
     }
 
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String prefix = writer.getPrefix(NAMESPACE);
+        String prefix = writer.getPrefix(Constants.URI_POLICY_NS);
 
         if (prefix == null) {
-            writer.writeStartElement(PREFIX, LOCAL_NAME_ALL, NAMESPACE);
-            writer.writeNamespace(PREFIX, NAMESPACE);
-            writer.setPrefix(PREFIX, NAMESPACE);
+            writer.writeStartElement(Constants.POLICY_PREFIX, Constants.ELEM_ALL, Constants.URI_POLICY_NS);
+            writer.writeNamespace(Constants.POLICY_PREFIX, Constants.URI_POLICY_NS);
+            writer.setPrefix(Constants.POLICY_PREFIX, Constants.URI_POLICY_NS);
         } else {
-            writer.writeStartElement(NAMESPACE, LOCAL_NAME_ALL);
+            writer.writeStartElement(Constants.URI_POLICY_NS, Constants.ELEM_ALL);
         }
 
         PolicyComponent policyComponent;
@@ -58,6 +58,6 @@
     }
 
     public short getType() {
-        return PolicyComponent.ALL;
+        return Constants.TYPE_ALL;
     }
 }

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java Mon Sep 18 00:23:40 2006
@@ -45,4 +45,8 @@
      */
     public void serialize(XMLStreamWriter writer) throws XMLStreamException;
     
+    /**
+     * 
+     */
+    public PolicyComponent normalize();
 }

Added: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java?view=auto&rev=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java (added)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java Mon Sep 18 00:23:40 2006
@@ -0,0 +1,51 @@
+/*
+ * 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 class Constants {
+    
+    public static final String ATTR_NAME = "Name";
+    
+    public static final String ATTR_ID = "Id";
+    
+    public static final String POLICY_PREFIX = "wsp";
+    
+    public static final String URI_POLICY_NS = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+    
+    public static final String URI_WSU_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
+    
+    public static final String ELEM_POLICY = "Policy";
+
+    public static final String ELEM_EXACTLYONE = "ExactlyOne";
+
+    public static final String ELEM_ALL = "All";
+    
+    public static final String ELEM_POLICYREF = "PolicyReference";
+    
+    public static final short TYPE_POLICY = 0x1;
+
+    public static final short TYPE_EXACTLYONE = 0x2;
+
+    public static final short TYPE_ALL = 0x3;
+    
+    public static final short TYPE_POLICYREF = 0x4;
+
+    public static final short TYPE_ASSERTION = 0x5;
+    
+    public static final QName Q_ELEM_OPTIONAL_ATTR = new QName(Constants.URI_POLICY_NS, "Optional",Constants.POLICY_PREFIX);    
+}

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java Mon Sep 18 00:23:40 2006
@@ -34,14 +34,14 @@
     }
 
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String prefix = writer.getPrefix(NAMESPACE);
+        String prefix = writer.getPrefix(Constants.URI_POLICY_NS);
 
         if (prefix == null) {
-            writer.writeStartElement(PREFIX, LOCAL_NAME_EXACTLYONE, NAMESPACE);
-            writer.writeNamespace(PREFIX, NAMESPACE);
-            writer.setPrefix(PREFIX, NAMESPACE);
+            writer.writeStartElement(Constants.POLICY_PREFIX, Constants.ELEM_EXACTLYONE, Constants.URI_POLICY_NS);
+            writer.writeNamespace(Constants.POLICY_PREFIX, Constants.URI_POLICY_NS);
+            writer.setPrefix(Constants.POLICY_PREFIX, Constants.URI_POLICY_NS);
         } else {
-            writer.writeStartElement(NAMESPACE, LOCAL_NAME_EXACTLYONE);
+            writer.writeStartElement(Constants.URI_POLICY_NS, Constants.ELEM_EXACTLYONE);
         }
 
         PolicyComponent policyComponent;
@@ -52,12 +52,9 @@
         }
 
         writer.writeEndElement();
-
     }
 
     public final short getType() {
-        return PolicyComponent.EXACTLYONE;
+        return Constants.TYPE_EXACTLYONE;
     }
-
-
 }

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java Mon Sep 18 00:23:40 2006
@@ -15,17 +15,24 @@
  */
 package org.apache.neethi;
 
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
 public class Policy extends All {
 
+    private HashMap attributes = new HashMap();
+
     public PolicyComponent normalize(boolean deep) {
-        Policy policy = new Policy();
-        policy.addPolicyComponent(super.normalize(deep));
-        return policy;
+        return normalize(null, deep);
+    }
+    
+    public PolicyComponent normalize(PolicyRegistry reg, boolean deep) {
+        return normalize(this, reg, deep);
     }
 
     public Policy merge(Policy policy) {
@@ -40,15 +47,15 @@
     }
 
     public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-        String prefix = writer.getPrefix(NAMESPACE);
+        String prefix = writer.getPrefix(Constants.ATTR_NAME);
 
         if (prefix == null) {
-            writer.writeStartElement(PREFIX, LOCAL_NAME_POLICY, NAMESPACE);
-            writer.writeNamespace(PREFIX, NAMESPACE);
-            writer.setPrefix(PREFIX, NAMESPACE);
+            writer.writeStartElement(Constants.POLICY_PREFIX, Constants.ELEM_POLICY, Constants.URI_POLICY_NS);
+            writer.writeNamespace(Constants.POLICY_PREFIX, Constants.URI_POLICY_NS);
+            writer.setPrefix(Constants.POLICY_PREFIX, Constants.URI_POLICY_NS);
 
         } else {
-            writer.writeStartElement(NAMESPACE, LOCAL_NAME_POLICY);
+            writer.writeStartElement(Constants.URI_POLICY_NS, Constants.ELEM_POLICY);
         }
 
         PolicyComponent policyComponent;
@@ -64,9 +71,9 @@
     }
 
     public short getType() {
-        return PolicyComponent.POLICY;
+        return Constants.TYPE_POLICY;
     }
-    
+
     public void addAlternatives(PolicyAlternatives policyAlternatives) {
         policyComponents.add(policyAlternatives);
     }
@@ -97,6 +104,36 @@
             throw new UnsupportedOperationException(
                     "policyAlternative.remove() is not supported");
         }
+    }
+
+    public void addAttribute(QName name, String value) {
+        attributes.put(name, value);
+    }
+
+    public String getAttribute(QName name) {
+        return (String) attributes.get(name);
+    }
+
+    public Map getAttributes() {
+        return attributes;
+    }
+
+    public void setName(String name) {
+        addAttribute(new QName("", Constants.ATTR_NAME), name);
+    }
+
+    public String getName() {
+        return getAttribute(new QName("", Constants.ATTR_NAME));
+    }
+
+    public void setId(String id) {
+        addAttribute(
+                new QName(Constants.URI_WSU_NS, Constants.ATTR_ID),
+                getName());
+    }
 
+    public String getId() {
+        return getAttribute(new QName(Constants.URI_WSU_NS,
+                Constants.ATTR_ID));
     }
 }

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyComponent.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyComponent.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyComponent.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyComponent.java Mon Sep 18 00:23:40 2006
@@ -22,15 +22,7 @@
  * This is an interface which any component of the frame must implement.
  */
 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;
-
+    
     /**
      * Serializes the PolicyComponent using an XMLStreamWriter.
      *
@@ -51,7 +43,5 @@
      */
     public short getType();
 
-    public PolicyComponent normalize();
-    
     public boolean equal(PolicyComponent policyComponent);
 }

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java Mon Sep 18 00:23:40 2006
@@ -25,6 +25,7 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.neethi.builders.AssertionBuilder;
+import org.apache.neethi.builders.xml.XmlPrimtiveAssertion;
 
 import sun.misc.Service;
 
@@ -45,19 +46,22 @@
 
     public static final String ALL = "All";
 
+    public static final String POLICY_REF = "PolicyReference";
+
     private static AssertionBuilderFactory factory = new AssertionBuilderFactory();
-    
+
     static {
         AssertionBuilder builder;
         QName[] knownElements;
-        
-        for (Iterator iterator = Service.providers(AssertionBuilder.class); iterator.hasNext(); ) {
+
+        for (Iterator iterator = Service.providers(AssertionBuilder.class); iterator
+                .hasNext();) {
             builder = (AssertionBuilder) iterator.next();
             knownElements = builder.getKnownElements();
-            
+
             for (int i = 0; i < knownElements.length; i++) {
                 PolicyEngine.registerBuilder(knownElements[i], builder);
-            }   
+            }
         }
     }
 
@@ -91,8 +95,29 @@
         } catch (Exception ex) {
             ex.printStackTrace();
         }
+        
+        // TODO throw an IllegalArgumentException
         return null;
     }
+    
+    
+    public static PolicyReference getPolicyReferene(InputStream inputStream) {
+        
+        try {
+            OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(
+                    OMAbstractFactory.getOMFactory(),
+                    XMLInputFactory.newInstance().createXMLStreamReader(
+                            inputStream)).getDocumentElement();
+            return getPolicyReference(element);
+
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        
+        // TODO throw an IllegalArgumentException
+        return null;
+        
+    }
 
     /**
      * Creates a Policy object from an OMElement.
@@ -101,22 +126,39 @@
      * @return
      */
     public static Policy getPolicy(OMElement element) {
-        
+
         return getPolicyOperator(element);
     }
+    
+    public static PolicyReference getPolicyReference(OMElement element) {
+
+        if (!(Constants.URI_POLICY_NS.equals(element.getNamespace()
+                .getNamespaceURI()) && Constants.ELEM_POLICYREF
+                .equals(element.getLocalName()))) {
+
+            throw new RuntimeException(
+                    "Specified element is not a <wsp:PolicyReference .. />  element");
+        }
+
+        PolicyReference reference = new PolicyReference();
+        
+        // setting the URI value
+        reference.setURI(element.getAttributeValue(new QName("URI")));
+        return reference;
+    }
 
-    public static Policy getPolicyOperator(OMElement element) {
+    private static Policy getPolicyOperator(OMElement element) {
         return (Policy) processOperationElement(element, new Policy());
     }
 
-    public static ExactlyOne getExactlyOneOperator(OMElement element) {
+    private static ExactlyOne getExactlyOneOperator(OMElement element) {
         return (ExactlyOne) processOperationElement(element, new ExactlyOne());
     }
 
-    public static All getAllOperator(OMElement element) {
+    private static All getAllOperator(OMElement element) {
         return (All) processOperationElement(element, new All());
     }
-
+    
     private static PolicyOperator processOperationElement(
             OMElement operationElement, PolicyOperator operator) {
 
@@ -126,26 +168,32 @@
                 .hasNext();) {
             childElement = (OMElement) iterator.next();
 
-            if (PolicyOperator.NAMESPACE.equals(childElement.getNamespace().getNamespaceURI())) {
+            if (Constants.URI_POLICY_NS.equals(childElement.getNamespace()
+                    .getNamespaceURI())) {
 
-                if (PolicyOperator.LOCAL_NAME_POLICY.equals(childElement.getLocalName())) {
+                if (Constants.ELEM_POLICY.equals(childElement
+                        .getLocalName())) {
                     operator
                             .addPolicyComponent(getPolicyOperator(childElement));
 
-                } else if (PolicyOperator.LOCAL_NAME_EXACTLYONE.equals(childElement
-                        .getLocalName())) {
+                } else if (Constants.ELEM_EXACTLYONE
+                        .equals(childElement.getLocalName())) {
                     operator
                             .addPolicyComponent(getExactlyOneOperator(childElement));
 
-                } else if (PolicyOperator.LOCAL_NAME_ALL.equals(childElement
+                } else if (Constants.ELEM_ALL.equals(childElement
                         .getLocalName())) {
                     operator.addPolicyComponent(getAllOperator(childElement));
+
+                } else if (Constants.ELEM_POLICYREF.equals(childElement
+                        .getLocalName())) {
+                    operator.addPolicyComponent(getPolicyReference(childElement));
                 }
-            } else {
 
+            } else {
 
-                AssertionBuilder builder = factory.getBuilder(childElement.getQName());
-                
+                AssertionBuilder builder = factory.getBuilder(childElement
+                        .getQName());
 
                 if (builder == null) {
                     XmlPrimtiveAssertion xmlPrimtiveAssertion = new XmlPrimtiveAssertion(

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyOperator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyOperator.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyOperator.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyOperator.java Mon Sep 18 00:23:40 2006
@@ -22,17 +22,7 @@
  * 
  */
 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 LOCAL_NAME_POLICY = "Policy";
-
-    public static final String LOCAL_NAME_EXACTLYONE = "ExactlyOne";
-
-    public static final String LOCAL_NAME_ALL = "All";
-
+ 
     /**
      * Add a PolicyComponent to the PolicyOperator.
      * 
@@ -58,7 +48,7 @@
      *            sufficient for most high level processing of Policies will
      * @return
      */
-    public PolicyComponent normalize(boolean deep);
+//    public PolicyComponent normalize(boolean deep);
     
     
     /**

Added: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java?view=auto&rev=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java (added)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java Mon Sep 18 00:23:40 2006
@@ -0,0 +1,60 @@
+/*
+ * 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 class PolicyReference implements PolicyComponent {
+
+    private String uri;
+
+    public void setURI(String uri) {
+        this.uri = uri;
+    }
+
+    public String getURI() {
+        return uri;
+    }
+
+    public boolean equal(PolicyComponent policyComponent) {
+        throw new UnsupportedOperationException("TODO");
+    }
+
+    public short getType() {
+        return Constants.TYPE_POLICYREF;
+    }
+
+    public PolicyComponent normalize() {
+        throw new UnsupportedOperationException("PolicyReference.normalize() is meaningless");
+    }
+    
+    public PolicyComponent normalize(PolicyRegistry reg, boolean deep) {
+        Policy policy = reg.lookup(getURI());
+        
+        if (policy == null) {
+            throw new RuntimeException(getURI() + " can't be resolved" );
+        }
+        
+        return policy.normalize(reg, deep);
+    }
+
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        throw new UnsupportedOperationException();
+
+    }
+
+}

Modified: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistry.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistry.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistry.java (original)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistry.java Mon Sep 18 00:23:40 2006
@@ -17,8 +17,8 @@
 
 public interface PolicyRegistry {
     
-    public void register(String key, Object policy);
+    public void register(String key, Policy policy);
     
-    public Object lookup(String key);
+    public Policy lookup(String key);
 
 }

Added: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistryImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistryImpl.java?view=auto&rev=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistryImpl.java (added)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyRegistryImpl.java Mon Sep 18 00:23:40 2006
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+public class PolicyRegistryImpl implements PolicyRegistry {
+    
+    private PolicyRegistry parent = null;
+    
+    private HashMap reg = new HashMap();
+    
+    public PolicyRegistryImpl() {
+    }
+    
+    public PolicyRegistryImpl(PolicyRegistry parent) {
+        this.parent = parent;
+    }
+    
+    public Policy lookup(String key) {
+        Policy policy = (Policy) reg.get(key);
+        
+        if (policy == null && parent != null) {
+            return parent.lookup(key);
+        }
+        return null;
+    }
+
+    public void register(String key, Policy policy) {
+        reg.put(key, policy);
+    }
+}

Added: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java?view=auto&rev=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java (added)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java Mon Sep 18 00:23:40 2006
@@ -0,0 +1,34 @@
+/*
+ * 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.xml;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.AssertionBuilderFactory;
+import org.apache.neethi.builders.AssertionBuilder;
+
+public class XMLPrimitiveAssertionBuilder implements AssertionBuilder {
+
+    public Assertion build(OMElement element, AssertionBuilderFactory factory) throws IllegalArgumentException {
+        return new XmlPrimtiveAssertion(element);
+    }
+    
+    public QName[] getKnownElements() {
+        return new QName[] {new QName("UnknownElement")};
+    }
+}

Added: webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java?view=auto&rev=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java (added)
+++ webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java Mon Sep 18 00:23:40 2006
@@ -0,0 +1,179 @@
+/*
+ * 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.xml;
+
+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;
+import org.apache.neethi.All;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Constants;
+import org.apache.neethi.ExactlyOne;
+import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.PolicyRegistry;
+
+import java.util.Iterator;
+
+public class XmlPrimtiveAssertion implements Assertion {
+
+    OMElement element;
+
+    boolean isOptional;
+
+    
+    // Assertions can contain policies inside it.
+    Policy policy;
+
+    public XmlPrimtiveAssertion(OMElement element) {
+        setValue(element);
+        setOptionality(element);
+    }
+
+    public QName getName() {
+        return (element != null) ? element.getQName() : null;
+    }
+
+    public void setValue(OMElement element) {
+        this.element = element;
+        // get all the policy namespace children
+        // actually there can only be one nested policy
+        Iterator iter = element.getChildrenWithName(new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY));
+        if (iter.hasNext()) {
+            OMElement policyOMElement = (OMElement) iter.next();
+            this.policy = PolicyEngine.getPolicy(policyOMElement);
+            // detach element from the om tree
+            policyOMElement.detach();
+        }
+
+    }
+
+    public OMElement getValue() {
+        return element;
+    }
+
+    public boolean isOptional() {
+        return isOptional;
+    }
+
+    public PolicyComponent normalize() {
+        if (isOptional) {
+            Policy policy = new Policy();
+            ExactlyOne exactlyOne = new ExactlyOne();
+
+            All all = new All();
+            OMElement omElement = element.cloneOMElement();
+
+            omElement.removeAttribute(omElement.getAttribute(Constants.Q_ELEM_OPTIONAL_ATTR));
+            all.addPolicyComponent(new XmlPrimtiveAssertion(omElement));
+            exactlyOne.addPolicyComponent(all);
+
+            exactlyOne.addPolicyComponent(new All());
+            policy.addPolicyComponent(exactlyOne);
+
+            return policy;
+        }
+
+        return this;
+    }
+
+    public PolicyComponent normalize(boolean isDeep) {
+        throw new UnsupportedOperationException();
+    }
+
+    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(Constants.Q_ELEM_OPTIONAL_ATTR));
+            alternative1.addPolicyComponent(new XmlPrimtiveAssertion(element1));
+            alternatives.addPolicyComponent(alternative1);
+
+            All alternative2 = new All();
+            alternatives.addPolicyComponent(alternative2);
+
+            policy.addPolicyComponent(alternatives);
+            return policy;
+        }
+        return this;
+    }
+
+    public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+        if (element != null) {
+
+            if (policy != null) {
+                // write the start part of the element
+                String prefix = writer.getPrefix(element.getNamespace()
+                        .getNamespaceURI());
+                if (prefix == null) {
+                    writer.writeStartElement(element.getQName().getPrefix(),
+                            element.getQName().getLocalPart(), element
+                                    .getNamespace().getNamespaceURI());
+                    writer.writeNamespace(element.getQName().getPrefix(),
+                            element.getNamespace().getNamespaceURI());
+                    writer.setPrefix(element.getQName().getPrefix(), element
+                            .getNamespace().getNamespaceURI());
+
+                } else {
+                    writer.writeStartElement(element.getNamespace()
+                            .getNamespaceURI(), element.getQName()
+                            .getLocalPart());
+                }
+                // TODO : write attributes and inner elements
+                policy.serialize(writer);
+                writer.writeEndElement();
+            } else {
+                // we can not serialize as follows since OMElement seriali
+                element.serialize(writer);
+            }
+
+        } else {
+            // TODO throw an exception??
+        }
+    }
+
+    public final short getType() {
+        return Constants.TYPE_ASSERTION;
+    }
+
+    private void setOptionality(OMElement element) {
+        OMAttribute attribute = element.getAttribute(Constants.Q_ELEM_OPTIONAL_ATTR);
+        if (attribute != null) {
+            this.isOptional = (new Boolean(attribute.getAttributeValue())
+                    .booleanValue());
+
+        } else {
+            this.isOptional = false;
+        }
+    }
+
+    public boolean equal(PolicyComponent policyComponent) {
+        if (policyComponent.getType() != Constants.TYPE_ASSERTION) {
+            return false;
+        }
+
+        return getName().equals(((Assertion) policyComponent).getName());
+    }
+
+}

Modified: webservices/commons/trunk/modules/neethi/src/test/test3/org/apache/neethi/MergeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/test3/org/apache/neethi/MergeTest.java?view=diff&rev=447300&r1=447299&r2=447300
==============================================================================
--- webservices/commons/trunk/modules/neethi/src/test/test3/org/apache/neethi/MergeTest.java (original)
+++ webservices/commons/trunk/modules/neethi/src/test/test3/org/apache/neethi/MergeTest.java Mon Sep 18 00:23:40 2006
@@ -55,7 +55,7 @@
 
             // result
             p4 = (Policy) p1.merge(p2);
-            p4 = (Policy) p4.normalize();
+            p4 = (Policy) p4.normalize(true);
             
 //            System.out.println("samples2" + File.separator + " Policy" + f1
 //                    + ".merge(Policy" + f2 + ") PASSED");



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