ws-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r345757 - in /webservices/commons/trunk/policy/src/org/apache/policy: model/ util/
Date Sun, 20 Nov 2005 16:05:51 GMT
Author: sanka
Date: Sun Nov 20 08:05:29 2005
New Revision: 345757

URL: http://svn.apache.org/viewcvs?rev=345757&view=rev
Log:
Some refactoring and few bug fixes ..

Added:
    webservices/commons/trunk/policy/src/org/apache/policy/model/PolicyConstants.java
      - copied, changed from r345752, webservices/commons/trunk/policy/src/org/apache/policy/model/WSPConstants.java
    webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyUtil.java
Removed:
    webservices/commons/trunk/policy/src/org/apache/policy/model/WSPConstants.java
Modified:
    webservices/commons/trunk/policy/src/org/apache/policy/model/PrimitiveAssertion.java
    webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyAttachmentUtil.java
    webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyReader.java
    webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyWriter.java

Copied: webservices/commons/trunk/policy/src/org/apache/policy/model/PolicyConstants.java
(from r345752, webservices/commons/trunk/policy/src/org/apache/policy/model/WSPConstants.java)
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/policy/model/PolicyConstants.java?p2=webservices/commons/trunk/policy/src/org/apache/policy/model/PolicyConstants.java&p1=webservices/commons/trunk/policy/src/org/apache/policy/model/WSPConstants.java&r1=345752&r2=345757&rev=345757&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/policy/model/WSPConstants.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/policy/model/PolicyConstants.java Sun
Nov 20 08:05:29 2005
@@ -20,7 +20,7 @@
  * entier framework.
  * 
  */
-public interface WSPConstants {
+public interface PolicyConstants {
     
     /** */
     public static final String AND_COMPOSITE_ASSERTION = "All";

Modified: webservices/commons/trunk/policy/src/org/apache/policy/model/PrimitiveAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/policy/model/PrimitiveAssertion.java?rev=345757&r1=345756&r2=345757&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/policy/model/PrimitiveAssertion.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/policy/model/PrimitiveAssertion.java Sun
Nov 20 08:05:29 2005
@@ -23,7 +23,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.policy.util.PolicyRegistry;
-import org.apache.policy.util.WSPolicyUtil;
+import org.apache.policy.util.PolicyUtil;
 
 /**
  * PrimitiveAssertion wraps an assertion which is indivisible. Such assertion 
@@ -92,7 +92,7 @@
         List argChildTerms;
         if (arg.getTerms().get(0) instanceof Policy) {
             argChildTerms 
-                = WSPolicyUtil.getPrimTermsList((Policy) arg.getTerms().get(0));
+                = PolicyUtil.getPrimTermsList((Policy) arg.getTerms().get(0));
         } else {
             argChildTerms = arg.getTerms();
         }
@@ -100,12 +100,12 @@
         List selfChildTerms;
         if (self.getTerms().get(0) instanceof Policy) {
             selfChildTerms 
-                = WSPolicyUtil.getPrimTermsList((Policy) self.getTerms().get(0));
+                = PolicyUtil.getPrimTermsList((Policy) self.getTerms().get(0));
         } else {
             selfChildTerms = self.getTerms();
         }
         
-        if (WSPolicyUtil.matchByQName(argChildTerms, selfChildTerms)) {
+        if (PolicyUtil.matchByQName(argChildTerms, selfChildTerms)) {
                  
             AndCompositeAssertion andCompositeAssertion 
                 = new AndCompositeAssertion();
@@ -185,7 +185,7 @@
             return primitiveAssertion;           
         }
         
-        Policy policyTerm = WSPolicyUtil.getSinglePolicy(policyTerms, reg);
+        Policy policyTerm = PolicyUtil.getSinglePolicy(policyTerms, reg);
         CompositeAssertion xorTerm = (XorCompositeAssertion) 
                 policyTerm.getTerms().get(0);
         
@@ -225,7 +225,7 @@
         
         termsForAnEndAnd.addAll(childNonPolicyTerms);
         termsForAnEndAnd.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
-        self.addTerm(WSPolicyUtil.getPolicy(termsForAnEndAnd));
+        self.addTerm(PolicyUtil.getPolicy(termsForAnEndAnd));
         anEndAndTerm.addTerm(self);
         endAndTerms.add(anEndAndTerm);
                
@@ -236,7 +236,7 @@
             termsForAnEndAnd.clear();
             termsForAnEndAnd.addAll(childNonPolicyTerms);
             termsForAnEndAnd.addAll(((AndCompositeAssertion) iterator2.next()).getTerms());
-            self.addTerm(WSPolicyUtil.getPolicy(termsForAnEndAnd));
+            self.addTerm(PolicyUtil.getPolicy(termsForAnEndAnd));
             
             anEndAndTerm.addTerm(self);
             endAndTerms.add(anEndAndTerm);            

Modified: webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyAttachmentUtil.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyAttachmentUtil.java?rev=345757&r1=345756&r2=345757&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyAttachmentUtil.java
(original)
+++ webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyAttachmentUtil.java
Sun Nov 20 08:05:29 2005
@@ -33,7 +33,7 @@
 import org.apache.axis2.wsdl.builder.WOMBuilderFactory;
 import org.apache.policy.model.Assertion;
 import org.apache.policy.model.Policy;
-import org.apache.policy.model.WSPConstants;
+import org.apache.policy.model.PolicyConstants;
 import org.apache.wsdl.Component;
 import org.apache.wsdl.MessageReference;
 import org.apache.wsdl.WSDLBinding;
@@ -57,21 +57,21 @@
  * @author Sanka Samaranayake <ssanka@gmail.com>
  *
  */
-public class WSPolicyAttachmentUtil {
+public class PolicyAttachmentUtil {
     
     private WSDLDescription wsdlDescription = null;
     //private HashMap loadedPolicies = new HashMap();
     private PolicyRegistry reg = new PolicyRegistry();
     
-    public WSPolicyAttachmentUtil() {
+    public PolicyAttachmentUtil() {
     }
 
-    public WSPolicyAttachmentUtil(WSDLDescription wsdlDescription) {
+    public PolicyAttachmentUtil(WSDLDescription wsdlDescription) {
         this.wsdlDescription = wsdlDescription;
         populatePolicyRegistry();
     }
     
-    public WSPolicyAttachmentUtil(InputStream wsdlInputStream) {
+    public PolicyAttachmentUtil(InputStream wsdlInputStream) {
         try {
             WSDLVersionWrapper build = WOMBuilderFactory.
                 getBuilder(WSDLConstants.WSDL_1_1).build(wsdlInputStream);
@@ -396,7 +396,7 @@
                 = (WSDLExtensibilityAttribute) iterator.next();
             QName qname = exAttribute.getKey();
             
-            if (qname.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI) &&
+            if (qname.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI) &&
                     qname.getLocalPart().equals("PolicyURIs")) {
                 String value = exAttribute.getValue().toString();
                 String[] uriStrings = value.split(" ");
@@ -430,11 +430,11 @@
                     = (DefaultExtensibilityElement) extensibilityElement;
                 Element element = defaultExtensibilityElement.getElement();
                 
-                if (element.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI)

+                if (element.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI)

                         && element.getLocalName().equals("PolicyReference")) {
                     policies.add(getPolicyFromPolicyRef(element));
                     
-                } else if (element.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI)

+                } else if (element.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI)

                         && element.getLocalName().equals("Policy")) {
                     policies.add(getPolicyFromElement(element));
                 }
@@ -599,7 +599,7 @@
                     = (DefaultExtensibilityElement) extensibilityElement;
                 Element element = defaultExtensibilityElement.getElement();
                 
-                if (element.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI)

+                if (element.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI)

                         && element.getLocalName().equals("PolicyReference")) {
                     String uriString = element.getAttribute("URI");
                     
@@ -609,7 +609,7 @@
                 } 
                 
                 String policyID 
-                    = element.getAttributeNS(WSPConstants.WSU_NAMESPACE_URI, "Id");
+                    = element.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI, "Id");
     
                 if (policyID.length() != 0) {
                     registerPolicyElement(element);
@@ -626,7 +626,7 @@
                 = (WSDLExtensibilityAttribute) iterator.next();
             QName qname = wsdlExtensibilityAttribute.getKey();
             
-            if (qname.getNamespaceURI().equals(WSPConstants.WS_POLICY_NAMESPACE_URI) &&
+            if (qname.getNamespaceURI().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI) &&
                     qname.getLocalPart().equals("PolicyURIs")) {
                 String value = wsdlExtensibilityAttribute.getValue().toString();
                 String[] policyURIs = value.split(" ");

Modified: webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyReader.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyReader.java?rev=345757&r1=345756&r2=345757&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyReader.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyReader.java Sun Nov
20 08:05:29 2005
@@ -37,7 +37,7 @@
 import org.apache.policy.model.Policy;
 import org.apache.policy.model.PolicyReference;
 import org.apache.policy.model.PrimitiveAssertion;
-import org.apache.policy.model.WSPConstants;
+import org.apache.policy.model.PolicyConstants;
 import org.apache.policy.model.XorCompositeAssertion;
 
 /**
@@ -67,20 +67,20 @@
 		String namespace = element.getNamespace().getName();
 		String localName = element.getLocalName();
 		
-		if (!(namespace.equals(WSPConstants.WSU_NAMESPACE_URI))) {
+		if (!(namespace.equals(PolicyConstants.WSU_NAMESPACE_URI))) {
 			return readPrimitiveAssertion(element);
 		}
 		
-		if (localName.equals(WSPConstants.WS_POLICY)) {
+		if (localName.equals(PolicyConstants.WS_POLICY)) {
 			return readPolicy(element);
 			
-		} else if (localName.equals(WSPConstants.AND_COMPOSITE_ASSERTION)) {
+		} else if (localName.equals(PolicyConstants.AND_COMPOSITE_ASSERTION)) {
 			return readAndComposite(element);
 			
-		} else if (localName.equals(WSPConstants.XOR_COMPOSITE_ASSERTION)) {
+		} else if (localName.equals(PolicyConstants.XOR_COMPOSITE_ASSERTION)) {
 			return readXorComposite(element);
 			
-		} else if (localName.equals(WSPConstants.WS_POLICY_REFERENCE)) {
+		} else if (localName.equals(PolicyConstants.WS_POLICY_REFERENCE)) {
 			return readPolicyReference(element);
 			
 		} else {
@@ -130,8 +130,8 @@
         while (childElements.hasNext()) {
             OMElement childElement = (OMElement) childElements.next();
             
-            if (childElement.getNamespace().getName().equals(WSPConstants.WS_POLICY_NAMESPACE_URI)
-                    && childElement.getLocalName().equals(WSPConstants.WS_POLICY))
{
+            if (childElement.getNamespace().getName().equals(PolicyConstants.WS_POLICY_NAMESPACE_URI)
+                    && childElement.getLocalName().equals(PolicyConstants.WS_POLICY))
{
                 Policy policy = readPolicy(childElement);
                 result.addTerm(policy);
         

Added: webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyUtil.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyUtil.java?rev=345757&view=auto
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyUtil.java (added)
+++ webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyUtil.java Sun Nov 20
08:05:29 2005
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.policy.util;
+
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.policy.model.AndCompositeAssertion;
+import org.apache.policy.model.Policy;
+import org.apache.policy.model.PrimitiveAssertion;
+import org.apache.policy.model.XorCompositeAssertion;
+
+/**
+ * WSPolicyUtil contains several utility methods for policy manipulations.
+ * 
+ * @author Sanka Samaranayake (sanka@apache.org)
+ */
+public class PolicyUtil {
+    
+    public static boolean matchByQName(PrimitiveAssertion primTermA, 
+            PrimitiveAssertion primTermB) {
+        return primTermA.getName().equals(primTermB.getName());
+    }
+    
+    public static boolean matchByQName(List primTermsA,List primTermsB) {
+        List larger = (primTermsA.size() > primTermsB.size()) 
+                ? primTermsA :primTermsB;
+        List smaller = (primTermsA.size() < primTermsB.size()) 
+                ? primTermsA : primTermsB;
+    
+        Iterator iterator = larger.iterator();
+        PrimitiveAssertion primTerm;
+        QName qname;
+        Iterator iterator2;
+        while (iterator.hasNext()) {
+            primTerm = (PrimitiveAssertion) iterator.next();
+            qname = primTerm.getName();
+            iterator2 = smaller.iterator();
+            
+            boolean match = false;
+            PrimitiveAssertion primTerm2;
+            while (iterator2.hasNext()) {
+                primTerm2 = (PrimitiveAssertion) iterator2.next();
+                if (primTerm2.getName().equals(qname)) {
+                    match = true;
+                    break;
+                }
+            }
+            if (!match) {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    
+    public static List getPrimTermsList(Policy policy) {
+        if (!policy.isNormalized()) {
+            policy = (Policy) policy.normalize();
+        }
+        
+        XorCompositeAssertion xorTerm 
+            = (XorCompositeAssertion) policy.getTerms().get(0);
+        AndCompositeAssertion andTerm 
+            = (AndCompositeAssertion) xorTerm.getTerms().get(0);
+        
+        return andTerm.getTerms();
+    }
+    
+    public static Policy getSinglePolicy(List policyList, PolicyRegistry reg) {
+        Policy policyTerm = null;
+        Iterator iterator = policyList.iterator();
+        
+        Policy policyTerm2;
+        while (iterator.hasNext()) {
+            policyTerm2 = (Policy) iterator.next();
+            policyTerm = (policyTerm == null) 
+                    ? policyTerm2 : (Policy) policyTerm.merge(policyTerm2, reg);
+        }
+        
+        return policyTerm;
+    }
+    
+    public static Policy getPolicy(List terms) {
+        Policy policyTerm = new Policy();
+        XorCompositeAssertion xorTerm = new XorCompositeAssertion();
+        AndCompositeAssertion andTerm = new AndCompositeAssertion();
+        
+        andTerm.addTerms(terms);
+        xorTerm.addTerm(andTerm);
+        policyTerm.addTerm(xorTerm);
+        
+        return policyTerm;
+    }
+}

Modified: webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyWriter.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyWriter.java?rev=345757&r1=345756&r2=345757&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyWriter.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/policy/util/PolicyWriter.java Sun Nov
20 08:05:29 2005
@@ -30,9 +30,9 @@
 import org.apache.policy.model.AndCompositeAssertion;
 import org.apache.policy.model.Assertion;
 import org.apache.policy.model.Policy;
+import org.apache.policy.model.PolicyConstants;
 import org.apache.policy.model.PolicyReference;
 import org.apache.policy.model.PrimitiveAssertion;
-import org.apache.policy.model.WSPConstants;
 import org.apache.policy.model.XorCompositeAssertion;
 
 /**
@@ -58,8 +58,8 @@
 	}
 	
 	private void writePolicy(Policy policy, XMLStreamWriter writer) throws XMLStreamException
{
-		writer.writeStartElement(WSPConstants.WS_POLICY_PREFIX, WSPConstants.WS_POLICY, 
-				WSPConstants.WSU_NAMESPACE_URI);
+		writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX, PolicyConstants.WS_POLICY, 
+				PolicyConstants.WSU_NAMESPACE_URI);
 		
 		Iterator iterator = policy.getTerms().iterator();
 		while (iterator.hasNext()) {
@@ -93,8 +93,8 @@
 	
 	private void writeAndCompositeAssertion(AndCompositeAssertion assertion, 
 			XMLStreamWriter writer) throws XMLStreamException {
-		writer.writeStartElement(WSPConstants.WS_POLICY_PREFIX, 
-				WSPConstants.AND_COMPOSITE_ASSERTION, WSPConstants.WS_POLICY_NAMESPACE_URI);
+		writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX, 
+				PolicyConstants.AND_COMPOSITE_ASSERTION, PolicyConstants.WS_POLICY_NAMESPACE_URI);
 		
 		List terms = assertion.getTerms();
 		writeTerms(terms, writer);
@@ -104,8 +104,8 @@
 	
 	private void writeXorCompositeAssertion(XorCompositeAssertion assertion,
 			XMLStreamWriter writer) throws XMLStreamException {
-		writer.writeStartElement(WSPConstants.WS_POLICY_PREFIX, 
-				WSPConstants.XOR_COMPOSITE_ASSERTION, WSPConstants.WS_POLICY_NAMESPACE_URI);
+		writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX, 
+				PolicyConstants.XOR_COMPOSITE_ASSERTION, PolicyConstants.WS_POLICY_NAMESPACE_URI);
 		
 		List terms = assertion.getTerms();
 		writeTerms(terms, writer);



Mime
View raw message