You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/02/24 11:01:34 UTC

svn commit: r1293152 - in /webservices/axiom/branches/namespaceURIInterning/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/ axiom-testsuite/src/main/java/org/apache/axiom/ts/ axiom-...

Author: veithen
Date: Fri Feb 24 10:01:33 2012
New Revision: 1293152

URL: http://svn.apache.org/viewvc?rev=1293152&view=rev
Log:
Committing some unfinished work.

Added:
    webservices/axiom/branches/namespaceURIInterning/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/NamespaceURIInterningXMLStreamReaderWrapper.java   (with props)
    webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithNamespaceURIInterning.java   (with props)
Modified:
    webservices/axiom/branches/namespaceURIInterning/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLStreamReaderConfiguration.java
    webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java

Modified: webservices/axiom/branches/namespaceURIInterning/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLStreamReaderConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/namespaceURIInterning/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLStreamReaderConfiguration.java?rev=1293152&r1=1293151&r2=1293152&view=diff
==============================================================================
--- webservices/axiom/branches/namespaceURIInterning/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLStreamReaderConfiguration.java (original)
+++ webservices/axiom/branches/namespaceURIInterning/modules/axiom-api/src/main/java/org/apache/axiom/om/OMXMLStreamReaderConfiguration.java Fri Feb 24 10:01:33 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.axiom.om;
 
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamReader;
 
@@ -27,9 +28,10 @@ import javax.xml.stream.XMLStreamReader;
  */
 public class OMXMLStreamReaderConfiguration {
     private boolean preserveNamespaceContext;
+    private boolean namespaceURIInterning;
 
     /**
-     * Determines whether strict namespace preservation is enabled. See
+     * Determine whether strict namespace preservation is enabled. See
      * {@link #setPreserveNamespaceContext(boolean)} for more information about this option.
      * 
      * @return the current value of this option
@@ -88,4 +90,33 @@ public class OMXMLStreamReaderConfigurat
     public void setPreserveNamespaceContext(boolean preserveNamespaceContext) {
         this.preserveNamespaceContext = preserveNamespaceContext;
     }
+
+    /**
+     * Determine whether namespace URIs returned by the {@link XMLStreamReader} should be interned.
+     * 
+     * @return the current value of this option
+     */
+    public boolean isNamespaceURIInterning() {
+        return namespaceURIInterning;
+    }
+
+    /**
+     * Specify whether namespace URIs returned by the {@link XMLStreamReader} should be interned.
+     * This applies to the return values of the following methods:
+     * <ul>
+     * <li>{@link XMLStreamReader#getAttributeNamespace(int)}
+     * <li>{@link XMLStreamReader#getNamespaceURI()}
+     * <li>{@link XMLStreamReader#getNamespaceURI(int)}
+     * <li>{@link XMLStreamReader#getNamespaceURI(String)}
+     * <li>{@link NamespaceContext#getNamespaceURI(String)} of the {@link NamespaceContext} instance
+     * returned by {@link XMLStreamReader#getNamespaceContext()}
+     * </ul>
+     * 
+     * @param namespaceURIInterning
+     *            the value to set for this option
+     * @see String#intern()
+     */
+    public void setNamespaceURIInterning(boolean namespaceURIInterning) {
+        this.namespaceURIInterning = namespaceURIInterning;
+    }
 }

Added: webservices/axiom/branches/namespaceURIInterning/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/NamespaceURIInterningXMLStreamReaderWrapper.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/namespaceURIInterning/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/NamespaceURIInterningXMLStreamReaderWrapper.java?rev=1293152&view=auto
==============================================================================
--- webservices/axiom/branches/namespaceURIInterning/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/NamespaceURIInterningXMLStreamReaderWrapper.java (added)
+++ webservices/axiom/branches/namespaceURIInterning/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/NamespaceURIInterningXMLStreamReaderWrapper.java Fri Feb 24 10:01:33 2012
@@ -0,0 +1,36 @@
+/*
+ * 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.om.impl.common;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
+import org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper;
+
+/**
+ * {@link XMLStreamReader} wrapper that interns namespace URIs. It is used to implement the
+ * {@link OMXMLStreamReaderConfiguration#isNamespaceURIInterning()} option.
+ */
+public class NamespaceURIInterningXMLStreamReaderWrapper extends XMLStreamReaderWrapper {
+
+    public NamespaceURIInterningXMLStreamReaderWrapper(XMLStreamReader parent) {
+        super(parent);
+    }
+
+}

Propchange: webservices/axiom/branches/namespaceURIInterning/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/NamespaceURIInterningXMLStreamReaderWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java?rev=1293152&r1=1293151&r2=1293152&view=diff
==============================================================================
--- webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/OMTestSuiteBuilder.java Fri Feb 24 10:01:33 2012
@@ -196,6 +196,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderNextTag(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderOnNonRootElement(metaFactory, true));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderOnNonRootElement(metaFactory, false));
+        addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithNamespaceURIInterning(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithoutCachingPartiallyBuilt(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithPreserveNamespaceContext(metaFactory));

Added: webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithNamespaceURIInterning.java
URL: http://svn.apache.org/viewvc/webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithNamespaceURIInterning.java?rev=1293152&view=auto
==============================================================================
--- webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithNamespaceURIInterning.java (added)
+++ webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithNamespaceURIInterning.java Fri Feb 24 10:01:33 2012
@@ -0,0 +1,68 @@
+/*
+ * 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.ts.om.element;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of
+ * {@link OMElement#getXMLStreamReader(boolean, OMXMLStreamReaderConfiguration)} with
+ * {@link OMXMLStreamReaderConfiguration#isNamespaceURIInterning()} set to <code>true</code>.
+ */
+public class TestGetXMLStreamReaderWithNamespaceURIInterning extends AxiomTestCase {
+    public TestGetXMLStreamReaderWithNamespaceURIInterning(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory factory = metaFactory.getOMFactory();
+        // Use "new String" to create String objects that are not interned
+        OMNamespace ns1 = factory.createOMNamespace(new String("urn:ns1"), "p");
+        OMNamespace ns2 = factory.createOMNamespace(new String("urn:ns2"), "q");
+        OMElement root = factory.createOMElement("root", ns1);
+        root.addAttribute("attr", "value", ns2);
+        factory.createOMElement("child", ns2, root);
+        
+        OMXMLStreamReaderConfiguration configuration = new OMXMLStreamReaderConfiguration();
+        configuration.setNamespaceURIInterning(true);
+        XMLStreamReader reader = root.getXMLStreamReader(true, configuration);
+        reader.nextTag();
+        assertInterned(reader.getNamespaceURI());
+        assertInterned(reader.getAttributeNamespace(0));
+        for (int i=0; i<reader.getNamespaceCount(); i++) {
+            assertInterned(reader.getNamespaceURI(i));
+        }
+        reader.nextTag();
+        assertInterned(reader.getNamespaceURI("p"));
+        NamespaceContext nc = reader.getNamespaceContext();
+        assertInterned(nc.getNamespaceURI("p"));
+    }
+    
+    private static void assertInterned(String s) {
+        assertSame("String not interned", s.intern(), s);
+    }
+}

Propchange: webservices/axiom/branches/namespaceURIInterning/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestGetXMLStreamReaderWithNamespaceURIInterning.java
------------------------------------------------------------------------------
    svn:eol-style = native