You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2008/01/16 12:46:31 UTC

svn commit: r612427 - in /incubator/cxf/trunk/rt/ws/policy/src: main/java/org/apache/cxf/ws/policy/ main/resources/META-INF/cxf/ test/java/org/apache/cxf/ws/policy/ test/java/org/apache/cxf/ws/policy/builder/primitive/ test/resources/normalized/ test/r...

Author: ningjiang
Date: Wed Jan 16 03:46:29 2008
New Revision: 612427

URL: http://svn.apache.org/viewvc?rev=612427&view=rev
Log:
CXF-1393 patch applied with thanks to Sergey

Added:
    incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml   (with props)
Modified:
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java
    incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/primitive/NestedPrimitiveAssertionTest.java

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java?rev=612427&r1=612426&r2=612427&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyBuilderImpl.java Wed Jan 16 03:46:29 2008
@@ -32,6 +32,7 @@
 
 import org.xml.sax.SAXException;
 
+import org.apache.cxf.Bus;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.extension.BusExtension;
@@ -45,6 +46,8 @@
 import org.apache.neethi.PolicyReference;
 
 
+
+
 /**
  * PolicyBuilderImpl is an implementation of the PolicyBuilder interface,
  * provides methods to create Policy and PolicyReferenceObjects
@@ -55,11 +58,20 @@
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(PolicyBuilderImpl.class);
  
     private AssertionBuilderRegistry assertionBuilderRegistry;
+    private Bus bus;
    
     public Class<?> getRegistrationType() {
         return PolicyBuilder.class;
     }
  
+    public void setBus(Bus theBus) {
+        bus = theBus;
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
     public void setAssertionBuilderRegistry(AssertionBuilderRegistry abr) {
         assertionBuilderRegistry = abr;        
     }
@@ -157,6 +169,10 @@
             }            
         }
 
+        String policyNsURI = 
+            bus == null ? PolicyConstants.NAMESPACE_WS_POLICY
+                        : bus.getExtension(PolicyConstants.class).getNamespace();
+        
         Element childElement;
         for (Node n = operationElement.getFirstChild(); n != null; n = n.getNextSibling()) {
             if (Node.ELEMENT_NODE != n.getNodeType()) {
@@ -166,7 +182,7 @@
             String namespaceURI = childElement.getNamespaceURI();
             String localName = childElement.getLocalName();
 
-            if (Constants.URI_POLICY_NS.equals(namespaceURI)) {
+            if (policyNsURI.equals(namespaceURI)) {
 
                 if (Constants.ELEM_POLICY.equals(localName)) {
                     operator.addPolicyComponent(getPolicyOperator(childElement));

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml?rev=612427&r1=612426&r2=612427&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/resources/META-INF/cxf/cxf-extension-policy.xml Wed Jan 16 03:46:29 2008
@@ -55,6 +55,7 @@
     <bean class="org.apache.cxf.ws.policy.attachment.external.EndpointReferenceDomainExpressionBuilder"/> 
     
     <bean id="org.apache.cxf.ws.policy.PolicyBuilder" class="org.apache.cxf.ws.policy.PolicyBuilderImpl">
+        <property name="bus" ref="cxf"/>
         <property name="assertionBuilderRegistry" ref="org.apache.cxf.ws.policy.AssertionBuilderRegistry"/>
     </bean>
   

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java?rev=612427&r1=612426&r2=612427&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java Wed Jan 16 03:46:29 2008
@@ -50,13 +50,31 @@
     }
     
     @Test
-    public void testNormalise() throws Exception {
-        Bus bus = control.createMock(Bus.class);
-        PolicyConstants constants = new PolicyConstants();
-        constants.setNamespace(PolicyConstants.NAMESPACE_XMLSOAP_200409);
-        EasyMock.expect(bus.getExtension(PolicyConstants.class)).andReturn(constants).anyTimes();
-        control.replay();
+    public void testNormalize() throws Exception {
+        Bus bus = createBus(PolicyConstants.NAMESPACE_XMLSOAP_200409);
+        PolicyBuilderImpl builder = createBuilder(bus);
+        
+        int n = 26;
+        for (int i = 1; i < n; i++) {
+            String sample = "/samples/test" + i + ".xml";
+            String normalized = "/normalized/test" + i + ".xml";
+            doTestNormalize(builder, sample, normalized);
+        }       
+    }
+    
+    @Test
+    public void testNormalizeDefaultNs() throws Exception {
+        Bus bus = createBus(PolicyConstants.NAMESPACE_WS_POLICY);
+        PolicyBuilderImpl builder = createBuilder(bus);
+        
+        String sample = "/samples/test1DefaultNs.xml";
+        String normalized = "/normalized/test1DefaultNs.xml";
+        doTestNormalize(builder, sample, normalized);
+    }
+    
+    private PolicyBuilderImpl createBuilder(Bus bus) {
         PolicyBuilderImpl builder = new PolicyBuilderImpl();
+        builder.setBus(bus);
         AssertionBuilderRegistry abr = new AssertionBuilderRegistryImpl();
         builder.setAssertionBuilderRegistry(abr);
         XMLPrimitiveAssertionBuilder ab = new XMLPrimitiveAssertionBuilder();
@@ -68,25 +86,33 @@
         abr.register(new QName("http://sample.org/Assertions", "A"), ab);
         abr.register(new QName("http://sample.org/Assertions", "B"), ab);
         abr.register(new QName("http://sample.org/Assertions", "C"), ab);
+        return builder;
+    }
+    
+    private Bus createBus(String policyNamespace) {
+        Bus bus = control.createMock(Bus.class);
+        PolicyConstants constants = new PolicyConstants();
+        constants.setNamespace(policyNamespace);
+        EasyMock.expect(bus.getExtension(PolicyConstants.class)).andReturn(constants).anyTimes();
+        control.replay();
+        return bus;
+    }
+    
+    private void doTestNormalize(
+        PolicyBuilderImpl builder, String sample, String normalized) throws Exception {
         
-        int n = 26;
-        for (int i = 1; i < n; i++) {
-            String sample = "/samples/test" + i + ".xml";
-            String normalised = "/normalized/test" + i + ".xml";
-            
-            InputStream sampleIn = NormalizeTest.class.getResourceAsStream(sample);
-            assertNotNull("Could not get input stream for resource " + sample, sampleIn);
-            InputStream normalisedIn = NormalizeTest.class.getResourceAsStream(normalised);
-            assertNotNull("Could not get input stream for resource " + normalised, normalisedIn);
-                        
-            Policy samplePolicy = builder.getPolicy(sampleIn);
-            Policy normalisedPolicy = builder.getPolicy(normalisedIn);
-            assertNotNull(samplePolicy);
-            assertNotNull(normalisedPolicy);
-            
-            Policy normalisedSamplePolicy = (Policy)samplePolicy.normalize(true);
-            assertTrue(PolicyComparator.compare(normalisedPolicy, normalisedSamplePolicy));
-            
-        }       
+        InputStream sampleIn = NormalizeTest.class.getResourceAsStream(sample);
+        assertNotNull("Could not get input stream for resource " + sample, sampleIn);
+        InputStream normalisedIn = NormalizeTest.class.getResourceAsStream(normalized);
+        assertNotNull("Could not get input stream for resource " + normalized, normalisedIn);
+                    
+        Policy samplePolicy = builder.getPolicy(sampleIn);
+        Policy normalisedPolicy = builder.getPolicy(normalisedIn);
+        assertNotNull(samplePolicy);
+        assertNotNull(normalisedPolicy);
+        
+        Policy normalisedSamplePolicy = (Policy)samplePolicy.normalize(true);
+        assertTrue(PolicyComparator.compare(normalisedPolicy, normalisedSamplePolicy));
     }
+    
 }

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/primitive/NestedPrimitiveAssertionTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/primitive/NestedPrimitiveAssertionTest.java?rev=612427&r1=612426&r2=612427&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/primitive/NestedPrimitiveAssertionTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/primitive/NestedPrimitiveAssertionTest.java Wed Jan 16 03:46:29 2008
@@ -70,6 +70,7 @@
         
         AssertionBuilderRegistry abr = new AssertionBuilderRegistryImpl();
         builder = new PolicyBuilderImpl();
+        builder.setBus(bus);
         builder.setAssertionBuilderRegistry(abr);
         
         NestedPrimitiveAssertionBuilder npab = new NestedPrimitiveAssertionBuilder();

Added: incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml?rev=612427&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml Wed Jan 16 03:46:29 2008
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you 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.
+-->
+<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy"><wsp:ExactlyOne /></wsp:Policy>

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/resources/normalized/test1DefaultNs.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml?rev=612427&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml Wed Jan 16 03:46:29 2008
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you 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.
+-->
+<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy">
+	<wsp:ExactlyOne />
+</wsp:Policy>

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/resources/samples/test1DefaultNs.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml