Author: veithen
Date: Mon Sep  6 20:47:43 2010
New Revision: 993150

URL: http://svn.apache.org/viewvc?rev=993150&view=rev
Log:
Refactored an anonymous class to a named class and increased test coverage.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/ImplicitNamespaceContextWrapper.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextImplicitNamespacesTestCase.java
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/namespace/
    
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/namespace/NamespaceContextTestUtils.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/namespace/ScopedNamespaceContextTest.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java?rev=993150&r1=993149&r2=993150&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java
 Mon Sep  6 20:47:43 2010
@@ -19,14 +19,11 @@
 
 package org.apache.axiom.util.stax.dialect;
 
-import java.util.Iterator;
-
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.ext.stax.DelegatingXMLStreamReader;
-import org.apache.axiom.util.namespace.AbstractNamespaceContext;
 import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
 
 class BEAStreamReaderWrapper extends XMLStreamReaderWrapper implements 
DelegatingXMLStreamReader {
@@ -143,20 +140,7 @@ class BEAStreamReaderWrapper extends XML
         // The NamespaceContext returned by the reference doesn't handle the
         // implicit namespace bindings (for the "xml" and "xmlns" prefixes)
         // correctly
-        final NamespaceContext parent = super.getNamespaceContext();
-        return new AbstractNamespaceContext() {
-            protected String doGetNamespaceURI(String prefix) {
-                return parent.getNamespaceURI(prefix);
-            }
-            
-            protected String doGetPrefix(String namespaceURI) {
-                return parent.getPrefix(namespaceURI);
-            }
-
-            protected Iterator doGetPrefixes(String namespaceURI) {
-                return parent.getPrefixes(namespaceURI);
-            }
-        };
+        return new 
ImplicitNamespaceContextWrapper(super.getNamespaceContext());
     }
 
     public XMLStreamReader getParent() {

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/ImplicitNamespaceContextWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/ImplicitNamespaceContextWrapper.java?rev=993150&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/ImplicitNamespaceContextWrapper.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/ImplicitNamespaceContextWrapper.java
 Mon Sep  6 20:47:43 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+package org.apache.axiom.util.stax.dialect;
+
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+
+import org.apache.axiom.util.namespace.AbstractNamespaceContext;
+
+/**
+ * {...@link NamespaceContext} wrapper that adds support for the implicit 
namespace
+ * bindings for the <tt>xml</tt> and <tt>xmlns</tt> prefixes. This wrapper may
+ * be used to fix the behavior of broken {...@link NamespaceContext}
+ * implementations.
+ */
+class ImplicitNamespaceContextWrapper extends AbstractNamespaceContext {
+    private final NamespaceContext parent;
+    
+    public ImplicitNamespaceContextWrapper(NamespaceContext parent) {
+        this.parent = parent;
+    }
+
+    protected String doGetNamespaceURI(String prefix) {
+        return parent.getNamespaceURI(prefix);
+    }
+    
+    protected String doGetPrefix(String namespaceURI) {
+        return parent.getPrefix(namespaceURI);
+    }
+
+    protected Iterator doGetPrefixes(String namespaceURI) {
+        return parent.getPrefixes(namespaceURI);
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/dialect/ImplicitNamespaceContextWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/namespace/ScopedNamespaceContextTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/namespace/ScopedNamespaceContextTest.java?rev=993150&r1=993149&r2=993150&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/namespace/ScopedNamespaceContextTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/namespace/ScopedNamespaceContextTest.java
 Mon Sep  6 20:47:43 2010
@@ -27,6 +27,8 @@ import java.util.Set;
 
 import javax.xml.namespace.NamespaceContext;
 
+import org.apache.axiom.testutils.namespace.NamespaceContextTestUtils;
+
 import junit.framework.TestCase;
 
 public class ScopedNamespaceContextTest extends TestCase {
@@ -98,4 +100,8 @@ public class ScopedNamespaceContextTest 
         assertEquals("p", nc.getPrefix("urn:ns1"));
         assertEquals(Collections.singleton("p"), getPrefixes(nc, "urn:ns1"));
     }
+    
+    public void testImplicitNamespaces() {
+        NamespaceContextTestUtils.checkImplicitNamespaces(new 
ScopedNamespaceContext());
+    }
 }

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java?rev=993150&r1=993149&r2=993150&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/DialectTest.java
 Mon Sep  6 20:47:43 2010
@@ -51,6 +51,7 @@ public class DialectTest extends TestSui
         addDialectTest(new 
GetEncodingFromDetectionTestCase("UnicodeLittleUnmarked", "UTF-16LE"));
         addDialectTest(new GetEncodingTestCase());
         addDialectTest(new GetEncodingWithCharacterStreamTestCase());
+        addDialectTest(new GetNamespaceContextImplicitNamespacesTestCase());
         addDialectTest(new GetTextInPrologTestCase());
         addDialectTest(new GetVersionTestCase());
         addDialectTest(new IsCharactersOnCDATASectionTestCase());

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextImplicitNamespacesTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextImplicitNamespacesTestCase.java?rev=993150&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextImplicitNamespacesTestCase.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextImplicitNamespacesTestCase.java
 Mon Sep  6 20:47:43 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+package org.apache.axiom.util.stax.dialect;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.testutils.namespace.NamespaceContextTestUtils;
+
+public class GetNamespaceContextImplicitNamespacesTestCase extends 
DialectTestCase {
+    protected void runTest() throws Throwable {
+        XMLInputFactory factory = newNormalizedXMLInputFactory();
+        XMLStreamReader reader = factory.createXMLStreamReader(new 
StringReader("<root/>"));
+        reader.nextTag();
+        
NamespaceContextTestUtils.checkImplicitNamespaces(reader.getNamespaceContext());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/dialect/GetNamespaceContextImplicitNamespacesTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/namespace/NamespaceContextTestUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/namespace/NamespaceContextTestUtils.java?rev=993150&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/namespace/NamespaceContextTestUtils.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/namespace/NamespaceContextTestUtils.java
 Mon Sep  6 20:47:43 2010
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+package org.apache.axiom.testutils.namespace;
+
+import java.util.Iterator;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+
+import junit.framework.Assert;
+
+public final class NamespaceContextTestUtils {
+    private NamespaceContextTestUtils() {}
+    
+    public static void checkImplicitNamespaces(NamespaceContext nc) {
+        Assert.assertEquals(XMLConstants.XML_NS_URI, 
nc.getNamespaceURI(XMLConstants.XML_NS_PREFIX));
+        Assert.assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, 
nc.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE));
+        
+        Assert.assertEquals(XMLConstants.XML_NS_PREFIX, 
nc.getPrefix(XMLConstants.XML_NS_URI));
+        Assert.assertEquals(XMLConstants.XMLNS_ATTRIBUTE, 
nc.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI));
+        
+        Iterator it = nc.getPrefixes(XMLConstants.XML_NS_URI);
+        Assert.assertTrue(it.hasNext());
+        Assert.assertEquals(XMLConstants.XML_NS_PREFIX, it.next());
+        Assert.assertFalse(it.hasNext());
+        
+        it = nc.getPrefixes(XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
+        Assert.assertTrue(it.hasNext());
+        Assert.assertEquals(XMLConstants.XMLNS_ATTRIBUTE, it.next());
+        Assert.assertFalse(it.hasNext());
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-testutils/src/main/java/org/apache/axiom/testutils/namespace/NamespaceContextTestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to