You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/09/26 22:09:20 UTC

svn commit: r450172 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2: description/AxisService2OM.java util/ExternalPolicySerializer.java util/PolicyUtil.java

Author: sanka
Date: Tue Sep 26 13:09:20 2006
New Revision: 450172

URL: http://svn.apache.org/viewvc?view=rev&rev=450172
Log:
1) Added the ExternalPolicySerializer which is used to filter out the 
internal assertions when a Policy is shown to external observers.

TODO : using it to filter out internal assertions from the policies that 
are shown in the WSDL documents of services.


Added:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/ExternalPolicySerializer.java
Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java?view=diff&rev=450172&r1=450171&r2=450172
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService2OM.java Tue Sep 26 13:09:20 2006
@@ -957,7 +957,7 @@
 
             OMNamespace ns = factory.createOMNamespace(
                     org.apache.neethi.Constants.URI_POLICY_NS,
-                    org.apache.neethi.Constants.POLICY_PREFIX);
+                    org.apache.neethi.Constants.ATTR_WSP);
             OMAttribute URIs = factory.createOMAttribute("PolicyURIs", ns,
                     value);
             element.addAttribute(URIs);

Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/ExternalPolicySerializer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/ExternalPolicySerializer.java?view=auto&rev=450172
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/ExternalPolicySerializer.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/ExternalPolicySerializer.java Tue Sep 26 13:09:20 2006
@@ -0,0 +1,125 @@
+/*
+ * 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.axis2.util;
+
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Constants;
+import org.apache.neethi.Policy;
+
+public class ExternalPolicySerializer {
+
+    private List assertions2Filter = new ArrayList();
+
+    public void addAssertionToFilter(QName name) {
+        assertions2Filter.add(name);
+    }
+
+    public void setAssertionsToFilter(List assertions2Filter) {
+        this.assertions2Filter = assertions2Filter;
+    }
+    
+    public List getAssertionsToFilter() {
+        return assertions2Filter;
+    }
+    
+
+    public void serialize(Policy policy, OutputStream os) {
+
+        try {
+            XMLStreamWriter writer = XMLOutputFactory.newInstance()
+                    .createXMLStreamWriter(os);
+            policy = (Policy) policy.normalize(false);
+
+            String prefix = writer.getPrefix(Constants.ATTR_WSP);
+            String wsuPrefix = writer.getPrefix(Constants.URI_WSU_NS);
+
+            if (prefix == null) {
+                prefix = Constants.ATTR_WSP;
+                writer.setPrefix(prefix, Constants.URI_POLICY_NS);
+            }
+
+            if (wsuPrefix == null) {
+                // TODO move this 'wsu' value to Neethi2 constants
+                wsuPrefix = "wsu";
+                writer.setPrefix(wsuPrefix, Constants.URI_WSU_NS);
+            }
+
+            // write <wsp:Policy tag
+
+            writer.writeStartElement(prefix, Constants.ELEM_POLICY,
+                    Constants.URI_POLICY_NS);
+            // write xmlns:wsp=".."
+            writer.writeNamespace(prefix, Constants.URI_POLICY_NS);
+
+            String name = policy.getName();
+            if (name != null) {
+                // write Name=".."
+                writer.writeAttribute(Constants.ATTR_NAME, name);
+            }
+
+            String id = policy.getId();
+            if (id != null) {
+                // write wsu:Id=".."
+                writer.writeAttribute(Constants.ATTR_ID, id);
+            }
+
+            writer.writeStartElement(Constants.ATTR_WSP,
+                    Constants.ELEM_EXACTLYONE, Constants.URI_POLICY_NS);
+            // write <wsp:ExactlyOne>
+
+            List assertionList;
+
+            for (Iterator iterator = policy.getAlternatives(); iterator
+                    .hasNext();) {
+                // write <wsp:All>
+                assertionList = (List) iterator.next();
+
+                Assertion assertion;
+
+                for (Iterator assertions = assertionList.iterator(); assertions
+                        .hasNext();) {
+                    assertion = (Assertion) assertions.next();
+                    if (assertions2Filter.contains(assertion.getName())) {
+                        // since this is an assertion to filter, we will not serialize this
+                        continue;
+                    }
+                    assertion.serialize(writer);
+                }
+            }
+            
+            // write </wsp:ExactlyOne>
+            writer.writeEndElement();
+            // write </wsp:Policy>
+            writer.writeEndElement();
+            
+            writer.flush();
+
+        } catch (Exception ex) {
+            
+            throw new RuntimeException(ex);
+
+        }
+    }
+}

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java?view=diff&rev=450172&r1=450171&r2=450172
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/PolicyUtil.java Tue Sep 26 13:09:20 2006
@@ -18,7 +18,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
 
 import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.stream.XMLInputFactory;
@@ -29,7 +28,6 @@
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
-import org.apache.axis2.description.PolicyInclude;
 import org.apache.neethi.Constants;
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyComponent;
@@ -74,6 +72,31 @@
     }
 
     public static OMElement getPolicyComponentAsOMElement(
+            PolicyComponent policyComponent,
+            ExternalPolicySerializer externalPolicySerializer)
+            throws XMLStreamException, FactoryConfigurationError {
+        
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        if (policyComponent instanceof Policy) {
+            externalPolicySerializer.serialize((Policy) policyComponent, baos);
+
+        } else {
+            XMLStreamWriter writer = XMLOutputFactory.newInstance()
+                    .createXMLStreamWriter(baos);
+            policyComponent.serialize(writer);
+            writer.flush();
+        }
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        return OMXMLBuilderFactory.createStAXOMBuilder(
+                OMAbstractFactory.getOMFactory(),
+                XMLInputFactory.newInstance().createXMLStreamReader(bais))
+                .getDocumentElement();
+
+    }
+
+    public static OMElement getPolicyComponentAsOMElement(
             PolicyComponent component) throws XMLStreamException,
             FactoryConfigurationError {
 
@@ -118,9 +141,8 @@
                 bais = new ByteArrayInputStream(xmlString.getBytes());
 
                 return PolicyEngine.getPolicy(bais);
-                
-            } else if (Constants.ELEM_POLICYREF.equals(element
-                    .getLocalName())) {
+
+            } else if (Constants.ELEM_POLICYREF.equals(element.getLocalName())) {
                 xmlString = DOM2Writer.nodeToString(element);
                 bais = new ByteArrayInputStream(xmlString.getBytes());
 
@@ -138,7 +160,7 @@
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         XMLStreamWriter writer = XMLOutputFactory.newInstance()
                 .createXMLStreamWriter(baos);
-        
+
         policyComponent.serialize(writer);
         writer.flush();
 



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