You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2007/02/03 22:11:40 UTC

svn commit: r503313 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java

Author: scheu
Date: Sat Feb  3 13:11:39 2007
New Revision: 503313

URL: http://svn.apache.org/viewvc?view=rev&rev=503313
Log:
WSCOMMONS-161
Contributor: Rich Scheuerle
Fix to OMSourcedElementImpl.  Force expansion now updates the prefix of the element.  Also supplied validation tests.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?view=diff&rev=503313&r1=503312&r2=503313
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Sat Feb  3 13:11:39 2007
@@ -54,9 +54,6 @@
     
     /** Namespace for element, needed in order to bypass base class handling. */
     private OMNamespace definedNamespace = null;
-    
-    /** Namespace for element, needed in order to bypass base class handling. */
-    private QName definedQName = null;
 
     /** Flag for parser provided to base element class. */
     private boolean isParserSet;
@@ -90,7 +87,7 @@
         //create a namespace
         super(qName.getLocalPart(), null, factory);
         dataSource = source;
-        definedQName = qName;
+        definedNamespace = new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
     }
     
     /**
@@ -153,7 +150,7 @@
                     e.getMessage());
             }
             
-            // make sure element name matches what was expected
+            // make sure element local name and namespace matches what was expected
             if (!reader.getLocalName().equals(getLocalName())) {
                 log.error("forceExpand: expected element name " +
                     getLocalName() + ", found " + reader.getLocalName());
@@ -170,10 +167,27 @@
                     readerURI + ", not the expected " + uri);
             }
             
+            // Get the current prefix and the reader's prefix
+            String readerPrefix = reader.getPrefix();
+            readerPrefix = (readerPrefix == null) ? "" : readerPrefix;
+            String prefix = getNamespace().getPrefix();
+            
             // set the builder for this element
             isParserSet = true;
             super.setBuilder(new StAXOMBuilder(getOMFactory(), reader, this));
             setComplete(false);
+            
+            // Update the prefix if necessary.  This must be done after
+            // isParserSet to avoid a recursive call
+            
+            if (!readerPrefix.equals(prefix) || 
+                    getNamespace() == null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("forceExpand: changing prefix from " + prefix + " to " + readerPrefix);
+                }
+                setNamespace(new OMNamespaceImpl(readerURI, readerPrefix));
+            }
+            
         }
     }
     
@@ -420,8 +434,8 @@
      * @see org.apache.axiom.om.OMElement#getNamespace()
      */
     public OMNamespace getNamespace() throws OMException {
-        if(definedNamespace == null && definedQName != null) {
-            definedNamespace = factory.createOMNamespace(definedQName.getNamespaceURI(), definedQName.getPrefix());
+        if (isExpanded()) {
+            return super.getNamespace();
         }
         return definedNamespace;
     }
@@ -450,7 +464,7 @@
             return super.getQName();
         } else if (getNamespace() != null) {
             // always ignore prefix on name from sourced element
-            return new QName(definedNamespace.getNamespaceURI(), getLocalName());
+            return new QName(getNamespace().getNamespaceURI(), getLocalName());
         } else {
             return new QName(getLocalName());
         }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java?view=diff&rev=503313&r1=503312&r2=503313
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java Sat Feb  3 13:11:39 2007
@@ -61,6 +61,26 @@
         "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
         "<price>29.95</price></book></library>";
     
+    // Same as testDocument except that an non-default prefix is used
+    private static String testDocument2 =
+        "<pre:library xmlns:pre=\"http://www.sosnoski.com/uwjws/library\" books=\"1\">" +
+        "<pre:type id=\"java\" category=\"professional\" deductable=\"true\">"+
+        "<pre:name>Java Reference</pre:name></pre:type><pre:type id=\"xml\" "+
+        "category=\"professional\" deductable=\"true\"><pre:name>XML Reference</pre:name>" +
+        "</pre:type><pre:book isbn=\"1930110111\" type=\"xml\"><pre:title>XSLT Quickly</pre:title>" +
+        "<pre:author>DuCharme, Bob</pre:author><pre:publisher>Manning</pre:publisher>" +
+        "<pre:price>29.95</pre:price></pre:book></pre:library>";
+    
+    // Same as testDocument exception that the elements are unqualified
+    private static String testDocument3 =
+        "<library books=\"1\">" +
+        "<type id=\"java\" category=\"professional\" deductable=\"true\">"+
+        "<name>Java Reference</name></type><type id=\"xml\" "+
+        "category=\"professional\" deductable=\"true\"><name>XML Reference</name>" +
+        "</type><book isbn=\"1930110111\" type=\"xml\"><title>XSLT Quickly</title>" +
+        "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
+        "<price>29.95</price></book></library>";
+    
     private OMSourcedElementImpl element;
     private OMElement root;
 
@@ -121,8 +141,6 @@
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         element.serialize(bos);
         String newText = new String(bos.toByteArray());
-        System.out.println(testDocument);
-        System.out.println(newText);
         assertEquals("Serialized text error", testDocument, newText);
         assertTrue("Element not expanded when serializing", element.isExpanded());
         
@@ -235,6 +253,609 @@
     }
     
     /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument (which uses the default namespace)
+     *   Type of Serialization: Serialize and cache
+     *   Prefix test
+     * @throws Exception
+     */
+    public void testName1DefaultPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
+        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        
+        // Serialize and cache.  This should cause expansion.  The prefix should be updated to match the testDocument string
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(element.getDefaultNamespace() != null);
+        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        // Serialize again
+        writer = new StringWriter();
+        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(element.getDefaultNamespace() != null);
+        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument (which uses the default namespace)
+     *   Type of Serialization: Serialize and consume
+     *   Tests update of prefix
+     * @throws Exception
+     */
+    public void testName2DefaultPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
+        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        
+        // Serialize and consume.  This should not cause expansion and currently won't update
+        // the name of the element.
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serializeAndConsume(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument (which uses the default namespace)
+     *   Type of Serialization: Serialize and cache
+     *   Tests attempt to rename namespace and localpart, which is not allowed
+     * @throws Exception
+     */
+    public void testName3DefaultPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
+        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        
+        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        
+        try {
+            root.serialize(writer);
+        } catch (Exception e) {
+            // Current Behavior
+            // The current OMSourceElementImpl ensures that the namespace and localName
+            // are consistent with the original setting.
+            return;
+        } 
+       
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        // Serialize again
+        writer = new StringWriter();
+        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        
+        
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument (which uses the default namespace)
+     *   Type of Serialization: Serialize and consume
+     *   Tests that the namespace and localName are not affected by the serializeAndConsume
+     * @throws Exception
+     */
+    public void testName4DefaultPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
+        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        
+        // Serialize and consume.  This should not cause expansion and currently won't update
+        // the name of the element.
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serializeAndConsume(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument2 (which uses a qualified prefix)
+     *   Type of Serialization: Serialize and cache
+     *   Prefix test
+     * @throws Exception
+     */
+    public void testName1QualifiedPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "");
+        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument2));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        
+        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals("pre"));
+        assertTrue(element.getDefaultNamespace() == null);
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        // Serialize again
+        writer = new StringWriter();
+        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals("pre"));
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
+        assertTrue(element.getDefaultNamespace() == null);
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument2 (which uses a qualified prefix)
+     *   Type of Serialization: Serialize and consume
+     *   Tests update of prefix
+     * @throws Exception
+     */
+    public void testName2QualifiedPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "");
+        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument2));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        
+        // Serialize and consume.  This should not cause expansion and currently won't update
+        // the name of the element.
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serializeAndConsume(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument2 (which uses a qualified prefix)
+     *   Type of Serialization: Serialize and cache
+     *   Tests attempt to rename namespace and localpart, which is not allowed
+     * @throws Exception
+     */
+    public void testName3QualifiedPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
+        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument2));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        
+        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        
+        try {
+            root.serialize(writer);
+        } catch (Exception e) {
+            // Current Behavior
+            // The current OMSourceElementImpl ensures that the namespace and localName
+            // are consistent with the original setting.
+            return;
+        } 
+        
+       
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        // Serialize again
+        writer = new StringWriter();
+        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        
+        
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument2 (which uses a qualified prefix)
+     *   Type of Serialization: Serialize and cache
+     *   Tests attempt to rename namespace and localpart, which is not allowed
+     * @throws Exception
+     */
+    public void testName4QualifiedPrefix() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "");
+        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument2));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        
+        // Serialize and consume.  This should not cause expansion and currently won't update
+        // the name of the element.
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serializeAndConsume(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain the default prefix declaration
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument3 (which uses unqualified names)
+     *   Type of Serialization: Serialize and cache
+     *   Prefix test
+     * @throws Exception
+     */
+    public void testName1Unqualified() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("", "");
+        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument3));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        
+        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(element.getDefaultNamespace() == null || element.getDefaultNamespace().getNamespaceURI().length() == 0);
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        // Serialize again
+        writer = new StringWriter();
+        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
+        assertTrue(element.getDefaultNamespace() == null || element.getDefaultNamespace().getNamespaceURI().length() == 0);
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument3 (which uses unqualified names)
+     *   Type of Serialization: Serialize and consume
+     *   Tests update of prefix
+     * @throws Exception
+     */
+    public void testName2Unqualified() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("", "");
+        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument3));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        
+        // Serialize and consume.  This should not cause expansion and currently won't update
+        // the name of the element.
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serializeAndConsume(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument3 (which uses unqualified names)
+     *   Type of Serialization: Serialize and cache
+     *   Tests attempt to rename namespace and localpart, which is not allowed
+     * @throws Exception
+     */
+    public void testName3Unqualified() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
+        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument3));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
+        
+        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        
+        try {
+            root.serialize(writer);
+        } catch (Exception e) {
+            // Current Behavior
+            // The current OMSourceElementImpl ensures that the namespace and localName
+            // are consistent with the original setting.
+            return;
+        } 
+        
+       
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        // Serialize again
+        writer = new StringWriter();
+        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serialize(writer);
+        xmlwriter.flush();
+        result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("library"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+        
+        
+        
+    }
+    
+    /**
+     * Tests the OMSourcedElement localName, namespace and prefix settings
+     * before and after serialization
+     *   Document: testDocument3 (which uses unqualified names)
+     *   Type of Serialization: Serialize and cache
+     *   Tests attempt to rename namespace and localpart, which is not allowed
+     * @throws Exception
+     */
+    public void testName4Unqualified() throws Exception {
+        
+        OMFactory f = new OMLinkedListImplFactory();
+        
+        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
+        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
+        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "");
+        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument3));
+        OMElement root = f.createOMElement("root", rootNS);
+        root.addChild(element);
+        
+        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        
+        // Serialize and consume.  This should not cause expansion and currently won't update
+        // the name of the element.
+        StringWriter writer = new StringWriter();
+        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
+        root.serializeAndConsume(writer);
+        xmlwriter.flush();
+        String result = writer.toString();
+        
+        assertTrue(element.getLocalName().equals("DUMMYNAME"));
+        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
+        assertTrue(element.getNamespace().getPrefix().equals(""));
+        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
+        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain the default prefix declaration
+        
+        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
+    }
+    
+    
+    
+    /**
      * Tests OMSourcedElement serialization when the root (parent) is serialized.
      * @throws Exception
      */
@@ -244,6 +865,7 @@
         root.serializeAndConsume(writer);
         xmlwriter.flush();
         String result = writer.toString();
+        
         // We can't test for equivalence because the underlying OMSourceElement is 
         // streamed as it is serialized.  So I am testing for an internal value.
         assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
@@ -268,6 +890,7 @@
         
         xmlwriter.flush();
         String result = writer.toString();
+        
         // We can't test for equivalence because the underlying OMSourceElement is 
         // changed as it is serialized.  So I am testing for an internal value.
         assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);



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


Re: svn commit: r503313 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java

Posted by Thilina Gunarathne <cs...@gmail.com>.
Fixed in http://svn.apache.org/viewvc?view=rev&rev=506432

~Thilina

On 2/9/07, Thilina Gunarathne <cs...@gmail.com> wrote:
> Rich,
> Seems like this commit has some JDK1.5 specific stuff [1]... Today I
> switched to 1.4  and build was failing..
>
> Thanks
> ~Thilina
>
> [1] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#contains(java.lang.CharSequence)
>
> On 2/4/07, scheu@apache.org <sc...@apache.org> wrote:
> > Author: scheu
> > Date: Sat Feb  3 13:11:39 2007
> > New Revision: 503313
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=503313
> > Log:
> > WSCOMMONS-161
> > Contributor: Rich Scheuerle
> > Fix to OMSourcedElementImpl.  Force expansion now updates the prefix of the element.  Also supplied validation tests.
> >
> > Modified:
> >     webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
> >     webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
> >
> > Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
> > URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?view=diff&rev=503313&r1=503312&r2=503313
> > ==============================================================================
> > --- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
> > +++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Sat Feb  3 13:11:39 2007
> > @@ -54,9 +54,6 @@
> >
> >      /** Namespace for element, needed in order to bypass base class handling. */
> >      private OMNamespace definedNamespace = null;
> > -
> > -    /** Namespace for element, needed in order to bypass base class handling. */
> > -    private QName definedQName = null;
> >
> >      /** Flag for parser provided to base element class. */
> >      private boolean isParserSet;
> > @@ -90,7 +87,7 @@
> >          //create a namespace
> >          super(qName.getLocalPart(), null, factory);
> >          dataSource = source;
> > -        definedQName = qName;
> > +        definedNamespace = new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
> >      }
> >
> >      /**
> > @@ -153,7 +150,7 @@
> >                      e.getMessage());
> >              }
> >
> > -            // make sure element name matches what was expected
> > +            // make sure element local name and namespace matches what was expected
> >              if (!reader.getLocalName().equals(getLocalName())) {
> >                  log.error("forceExpand: expected element name " +
> >                      getLocalName() + ", found " + reader.getLocalName());
> > @@ -170,10 +167,27 @@
> >                      readerURI + ", not the expected " + uri);
> >              }
> >
> > +            // Get the current prefix and the reader's prefix
> > +            String readerPrefix = reader.getPrefix();
> > +            readerPrefix = (readerPrefix == null) ? "" : readerPrefix;
> > +            String prefix = getNamespace().getPrefix();
> > +
> >              // set the builder for this element
> >              isParserSet = true;
> >              super.setBuilder(new StAXOMBuilder(getOMFactory(), reader, this));
> >              setComplete(false);
> > +
> > +            // Update the prefix if necessary.  This must be done after
> > +            // isParserSet to avoid a recursive call
> > +
> > +            if (!readerPrefix.equals(prefix) ||
> > +                    getNamespace() == null) {
> > +                if (log.isDebugEnabled()) {
> > +                    log.debug("forceExpand: changing prefix from " + prefix + " to " + readerPrefix);
> > +                }
> > +                setNamespace(new OMNamespaceImpl(readerURI, readerPrefix));
> > +            }
> > +
> >          }
> >      }
> >
> > @@ -420,8 +434,8 @@
> >       * @see org.apache.axiom.om.OMElement#getNamespace()
> >       */
> >      public OMNamespace getNamespace() throws OMException {
> > -        if(definedNamespace == null && definedQName != null) {
> > -            definedNamespace = factory.createOMNamespace(definedQName.getNamespaceURI(), definedQName.getPrefix());
> > +        if (isExpanded()) {
> > +            return super.getNamespace();
> >          }
> >          return definedNamespace;
> >      }
> > @@ -450,7 +464,7 @@
> >              return super.getQName();
> >          } else if (getNamespace() != null) {
> >              // always ignore prefix on name from sourced element
> > -            return new QName(definedNamespace.getNamespaceURI(), getLocalName());
> > +            return new QName(getNamespace().getNamespaceURI(), getLocalName());
> >          } else {
> >              return new QName(getLocalName());
> >          }
> >
> > Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
> > URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java?view=diff&rev=503313&r1=503312&r2=503313
> > ==============================================================================
> > --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java (original)
> > +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java Sat Feb  3 13:11:39 2007
> > @@ -61,6 +61,26 @@
> >          "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
> >          "<price>29.95</price></book></library>";
> >
> > +    // Same as testDocument except that an non-default prefix is used
> > +    private static String testDocument2 =
> > +        "<pre:library xmlns:pre=\"http://www.sosnoski.com/uwjws/library\" books=\"1\">" +
> > +        "<pre:type id=\"java\" category=\"professional\" deductable=\"true\">"+
> > +        "<pre:name>Java Reference</pre:name></pre:type><pre:type id=\"xml\" "+
> > +        "category=\"professional\" deductable=\"true\"><pre:name>XML Reference</pre:name>" +
> > +        "</pre:type><pre:book isbn=\"1930110111\" type=\"xml\"><pre:title>XSLT Quickly</pre:title>" +
> > +        "<pre:author>DuCharme, Bob</pre:author><pre:publisher>Manning</pre:publisher>" +
> > +        "<pre:price>29.95</pre:price></pre:book></pre:library>";
> > +
> > +    // Same as testDocument exception that the elements are unqualified
> > +    private static String testDocument3 =
> > +        "<library books=\"1\">" +
> > +        "<type id=\"java\" category=\"professional\" deductable=\"true\">"+
> > +        "<name>Java Reference</name></type><type id=\"xml\" "+
> > +        "category=\"professional\" deductable=\"true\"><name>XML Reference</name>" +
> > +        "</type><book isbn=\"1930110111\" type=\"xml\"><title>XSLT Quickly</title>" +
> > +        "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
> > +        "<price>29.95</price></book></library>";
> > +
> >      private OMSourcedElementImpl element;
> >      private OMElement root;
> >
> > @@ -121,8 +141,6 @@
> >          ByteArrayOutputStream bos = new ByteArrayOutputStream();
> >          element.serialize(bos);
> >          String newText = new String(bos.toByteArray());
> > -        System.out.println(testDocument);
> > -        System.out.println(newText);
> >          assertEquals("Serialized text error", testDocument, newText);
> >          assertTrue("Element not expanded when serializing", element.isExpanded());
> >
> > @@ -235,6 +253,609 @@
> >      }
> >
> >      /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument (which uses the default namespace)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Prefix test
> > +     * @throws Exception
> > +     */
> > +    public void testName1DefaultPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
> > +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +
> > +        // Serialize and cache.  This should cause expansion.  The prefix should be updated to match the testDocument string
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(element.getDefaultNamespace() != null);
> > +        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +        // Serialize again
> > +        writer = new StringWriter();
> > +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(element.getDefaultNamespace() != null);
> > +        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument (which uses the default namespace)
> > +     *   Type of Serialization: Serialize and consume
> > +     *   Tests update of prefix
> > +     * @throws Exception
> > +     */
> > +    public void testName2DefaultPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
> > +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +
> > +        // Serialize and consume.  This should not cause expansion and currently won't update
> > +        // the name of the element.
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serializeAndConsume(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument (which uses the default namespace)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Tests attempt to rename namespace and localpart, which is not allowed
> > +     * @throws Exception
> > +     */
> > +    public void testName3DefaultPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> > +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +
> > +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +
> > +        try {
> > +            root.serialize(writer);
> > +        } catch (Exception e) {
> > +            // Current Behavior
> > +            // The current OMSourceElementImpl ensures that the namespace and localName
> > +            // are consistent with the original setting.
> > +            return;
> > +        }
> > +
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +        // Serialize again
> > +        writer = new StringWriter();
> > +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +
> > +
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument (which uses the default namespace)
> > +     *   Type of Serialization: Serialize and consume
> > +     *   Tests that the namespace and localName are not affected by the serializeAndConsume
> > +     * @throws Exception
> > +     */
> > +    public void testName4DefaultPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> > +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +
> > +        // Serialize and consume.  This should not cause expansion and currently won't update
> > +        // the name of the element.
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serializeAndConsume(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument2 (which uses a qualified prefix)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Prefix test
> > +     * @throws Exception
> > +     */
> > +    public void testName1QualifiedPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "");
> > +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument2));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +
> > +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("pre"));
> > +        assertTrue(element.getDefaultNamespace() == null);
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +        // Serialize again
> > +        writer = new StringWriter();
> > +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("pre"));
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> > +        assertTrue(element.getDefaultNamespace() == null);
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument2 (which uses a qualified prefix)
> > +     *   Type of Serialization: Serialize and consume
> > +     *   Tests update of prefix
> > +     * @throws Exception
> > +     */
> > +    public void testName2QualifiedPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "");
> > +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument2));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +
> > +        // Serialize and consume.  This should not cause expansion and currently won't update
> > +        // the name of the element.
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serializeAndConsume(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument2 (which uses a qualified prefix)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Tests attempt to rename namespace and localpart, which is not allowed
> > +     * @throws Exception
> > +     */
> > +    public void testName3QualifiedPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> > +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument2));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +
> > +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +
> > +        try {
> > +            root.serialize(writer);
> > +        } catch (Exception e) {
> > +            // Current Behavior
> > +            // The current OMSourceElementImpl ensures that the namespace and localName
> > +            // are consistent with the original setting.
> > +            return;
> > +        }
> > +
> > +
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +        // Serialize again
> > +        writer = new StringWriter();
> > +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +
> > +
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument2 (which uses a qualified prefix)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Tests attempt to rename namespace and localpart, which is not allowed
> > +     * @throws Exception
> > +     */
> > +    public void testName4QualifiedPrefix() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "");
> > +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument2));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +
> > +        // Serialize and consume.  This should not cause expansion and currently won't update
> > +        // the name of the element.
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serializeAndConsume(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain the default prefix declaration
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument3 (which uses unqualified names)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Prefix test
> > +     * @throws Exception
> > +     */
> > +    public void testName1Unqualified() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("", "");
> > +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument3));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +
> > +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(element.getDefaultNamespace() == null || element.getDefaultNamespace().getNamespaceURI().length() == 0);
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +        // Serialize again
> > +        writer = new StringWriter();
> > +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> > +        assertTrue(element.getDefaultNamespace() == null || element.getDefaultNamespace().getNamespaceURI().length() == 0);
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument3 (which uses unqualified names)
> > +     *   Type of Serialization: Serialize and consume
> > +     *   Tests update of prefix
> > +     * @throws Exception
> > +     */
> > +    public void testName2Unqualified() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("", "");
> > +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument3));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +
> > +        // Serialize and consume.  This should not cause expansion and currently won't update
> > +        // the name of the element.
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serializeAndConsume(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument3 (which uses unqualified names)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Tests attempt to rename namespace and localpart, which is not allowed
> > +     * @throws Exception
> > +     */
> > +    public void testName3Unqualified() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> > +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument3));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> > +
> > +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +
> > +        try {
> > +            root.serialize(writer);
> > +        } catch (Exception e) {
> > +            // Current Behavior
> > +            // The current OMSourceElementImpl ensures that the namespace and localName
> > +            // are consistent with the original setting.
> > +            return;
> > +        }
> > +
> > +
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +        // Serialize again
> > +        writer = new StringWriter();
> > +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serialize(writer);
> > +        xmlwriter.flush();
> > +        result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("library"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +
> > +
> > +
> > +    }
> > +
> > +    /**
> > +     * Tests the OMSourcedElement localName, namespace and prefix settings
> > +     * before and after serialization
> > +     *   Document: testDocument3 (which uses unqualified names)
> > +     *   Type of Serialization: Serialize and cache
> > +     *   Tests attempt to rename namespace and localpart, which is not allowed
> > +     * @throws Exception
> > +     */
> > +    public void testName4Unqualified() throws Exception {
> > +
> > +        OMFactory f = new OMLinkedListImplFactory();
> > +
> > +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> > +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> > +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "");
> > +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument3));
> > +        OMElement root = f.createOMElement("root", rootNS);
> > +        root.addChild(element);
> > +
> > +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +
> > +        // Serialize and consume.  This should not cause expansion and currently won't update
> > +        // the name of the element.
> > +        StringWriter writer = new StringWriter();
> > +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> > +        root.serializeAndConsume(writer);
> > +        xmlwriter.flush();
> > +        String result = writer.toString();
> > +
> > +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> > +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> > +        assertTrue(element.getNamespace().getPrefix().equals(""));
> > +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> > +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain the default prefix declaration
> > +
> > +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > +    }
> > +
> > +
> > +
> > +    /**
> >       * Tests OMSourcedElement serialization when the root (parent) is serialized.
> >       * @throws Exception
> >       */
> > @@ -244,6 +865,7 @@
> >          root.serializeAndConsume(writer);
> >          xmlwriter.flush();
> >          String result = writer.toString();
> > +
> >          // We can't test for equivalence because the underlying OMSourceElement is
> >          // streamed as it is serialized.  So I am testing for an internal value.
> >          assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> > @@ -268,6 +890,7 @@
> >
> >          xmlwriter.flush();
> >          String result = writer.toString();
> > +
> >          // We can't test for equivalence because the underlying OMSourceElement is
> >          // changed as it is serialized.  So I am testing for an internal value.
> >          assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
> > For additional commands, e-mail: commons-dev-help@ws.apache.org
> >
> >
>
>
> --
> Thilina Gunarathne
> WSO2, Inc.; http://www.wso2.com/
> Home page: http://webservices.apache.org/~thilina/
> Blog: http://thilinag.blogspot.com/
>


-- 
Thilina Gunarathne
WSO2, Inc.; http://www.wso2.com/
Home page: http://webservices.apache.org/~thilina/
Blog: http://thilinag.blogspot.com/

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


Re: svn commit: r503313 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java

Posted by Thilina Gunarathne <cs...@gmail.com>.
Rich,
Seems like this commit has some JDK1.5 specific stuff [1]... Today I
switched to 1.4  and build was failing..

Thanks
~Thilina

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#contains(java.lang.CharSequence)

On 2/4/07, scheu@apache.org <sc...@apache.org> wrote:
> Author: scheu
> Date: Sat Feb  3 13:11:39 2007
> New Revision: 503313
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=503313
> Log:
> WSCOMMONS-161
> Contributor: Rich Scheuerle
> Fix to OMSourcedElementImpl.  Force expansion now updates the prefix of the element.  Also supplied validation tests.
>
> Modified:
>     webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
>     webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
>
> Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
> URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?view=diff&rev=503313&r1=503312&r2=503313
> ==============================================================================
> --- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
> +++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Sat Feb  3 13:11:39 2007
> @@ -54,9 +54,6 @@
>
>      /** Namespace for element, needed in order to bypass base class handling. */
>      private OMNamespace definedNamespace = null;
> -
> -    /** Namespace for element, needed in order to bypass base class handling. */
> -    private QName definedQName = null;
>
>      /** Flag for parser provided to base element class. */
>      private boolean isParserSet;
> @@ -90,7 +87,7 @@
>          //create a namespace
>          super(qName.getLocalPart(), null, factory);
>          dataSource = source;
> -        definedQName = qName;
> +        definedNamespace = new OMNamespaceImpl(qName.getNamespaceURI(), qName.getPrefix());
>      }
>
>      /**
> @@ -153,7 +150,7 @@
>                      e.getMessage());
>              }
>
> -            // make sure element name matches what was expected
> +            // make sure element local name and namespace matches what was expected
>              if (!reader.getLocalName().equals(getLocalName())) {
>                  log.error("forceExpand: expected element name " +
>                      getLocalName() + ", found " + reader.getLocalName());
> @@ -170,10 +167,27 @@
>                      readerURI + ", not the expected " + uri);
>              }
>
> +            // Get the current prefix and the reader's prefix
> +            String readerPrefix = reader.getPrefix();
> +            readerPrefix = (readerPrefix == null) ? "" : readerPrefix;
> +            String prefix = getNamespace().getPrefix();
> +
>              // set the builder for this element
>              isParserSet = true;
>              super.setBuilder(new StAXOMBuilder(getOMFactory(), reader, this));
>              setComplete(false);
> +
> +            // Update the prefix if necessary.  This must be done after
> +            // isParserSet to avoid a recursive call
> +
> +            if (!readerPrefix.equals(prefix) ||
> +                    getNamespace() == null) {
> +                if (log.isDebugEnabled()) {
> +                    log.debug("forceExpand: changing prefix from " + prefix + " to " + readerPrefix);
> +                }
> +                setNamespace(new OMNamespaceImpl(readerURI, readerPrefix));
> +            }
> +
>          }
>      }
>
> @@ -420,8 +434,8 @@
>       * @see org.apache.axiom.om.OMElement#getNamespace()
>       */
>      public OMNamespace getNamespace() throws OMException {
> -        if(definedNamespace == null && definedQName != null) {
> -            definedNamespace = factory.createOMNamespace(definedQName.getNamespaceURI(), definedQName.getPrefix());
> +        if (isExpanded()) {
> +            return super.getNamespace();
>          }
>          return definedNamespace;
>      }
> @@ -450,7 +464,7 @@
>              return super.getQName();
>          } else if (getNamespace() != null) {
>              // always ignore prefix on name from sourced element
> -            return new QName(definedNamespace.getNamespaceURI(), getLocalName());
> +            return new QName(getNamespace().getNamespaceURI(), getLocalName());
>          } else {
>              return new QName(getLocalName());
>          }
>
> Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java
> URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java?view=diff&rev=503313&r1=503312&r2=503313
> ==============================================================================
> --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java (original)
> +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMSourcedElementTest.java Sat Feb  3 13:11:39 2007
> @@ -61,6 +61,26 @@
>          "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
>          "<price>29.95</price></book></library>";
>
> +    // Same as testDocument except that an non-default prefix is used
> +    private static String testDocument2 =
> +        "<pre:library xmlns:pre=\"http://www.sosnoski.com/uwjws/library\" books=\"1\">" +
> +        "<pre:type id=\"java\" category=\"professional\" deductable=\"true\">"+
> +        "<pre:name>Java Reference</pre:name></pre:type><pre:type id=\"xml\" "+
> +        "category=\"professional\" deductable=\"true\"><pre:name>XML Reference</pre:name>" +
> +        "</pre:type><pre:book isbn=\"1930110111\" type=\"xml\"><pre:title>XSLT Quickly</pre:title>" +
> +        "<pre:author>DuCharme, Bob</pre:author><pre:publisher>Manning</pre:publisher>" +
> +        "<pre:price>29.95</pre:price></pre:book></pre:library>";
> +
> +    // Same as testDocument exception that the elements are unqualified
> +    private static String testDocument3 =
> +        "<library books=\"1\">" +
> +        "<type id=\"java\" category=\"professional\" deductable=\"true\">"+
> +        "<name>Java Reference</name></type><type id=\"xml\" "+
> +        "category=\"professional\" deductable=\"true\"><name>XML Reference</name>" +
> +        "</type><book isbn=\"1930110111\" type=\"xml\"><title>XSLT Quickly</title>" +
> +        "<author>DuCharme, Bob</author><publisher>Manning</publisher>" +
> +        "<price>29.95</price></book></library>";
> +
>      private OMSourcedElementImpl element;
>      private OMElement root;
>
> @@ -121,8 +141,6 @@
>          ByteArrayOutputStream bos = new ByteArrayOutputStream();
>          element.serialize(bos);
>          String newText = new String(bos.toByteArray());
> -        System.out.println(testDocument);
> -        System.out.println(newText);
>          assertEquals("Serialized text error", testDocument, newText);
>          assertTrue("Element not expanded when serializing", element.isExpanded());
>
> @@ -235,6 +253,609 @@
>      }
>
>      /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument (which uses the default namespace)
> +     *   Type of Serialization: Serialize and cache
> +     *   Prefix test
> +     * @throws Exception
> +     */
> +    public void testName1DefaultPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
> +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +
> +        // Serialize and cache.  This should cause expansion.  The prefix should be updated to match the testDocument string
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(element.getDefaultNamespace() != null);
> +        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +        // Serialize again
> +        writer = new StringWriter();
> +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(element.getDefaultNamespace() != null);
> +        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument (which uses the default namespace)
> +     *   Type of Serialization: Serialize and consume
> +     *   Tests update of prefix
> +     * @throws Exception
> +     */
> +    public void testName2DefaultPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "DUMMYPREFIX");
> +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +
> +        // Serialize and consume.  This should not cause expansion and currently won't update
> +        // the name of the element.
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serializeAndConsume(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +        assertTrue(!result.contains("DUMMYPREFIX"));  // Make sure that the serialized string does not contain DUMMYPREFIX
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument (which uses the default namespace)
> +     *   Type of Serialization: Serialize and cache
> +     *   Tests attempt to rename namespace and localpart, which is not allowed
> +     * @throws Exception
> +     */
> +    public void testName3DefaultPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +
> +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +
> +        try {
> +            root.serialize(writer);
> +        } catch (Exception e) {
> +            // Current Behavior
> +            // The current OMSourceElementImpl ensures that the namespace and localName
> +            // are consistent with the original setting.
> +            return;
> +        }
> +
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +        // Serialize again
> +        writer = new StringWriter();
> +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +
> +
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument (which uses the default namespace)
> +     *   Type of Serialization: Serialize and consume
> +     *   Tests that the namespace and localName are not affected by the serializeAndConsume
> +     * @throws Exception
> +     */
> +    public void testName4DefaultPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +
> +        // Serialize and consume.  This should not cause expansion and currently won't update
> +        // the name of the element.
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serializeAndConsume(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument2 (which uses a qualified prefix)
> +     *   Type of Serialization: Serialize and cache
> +     *   Prefix test
> +     * @throws Exception
> +     */
> +    public void testName1QualifiedPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "");
> +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument2));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +
> +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals("pre"));
> +        assertTrue(element.getDefaultNamespace() == null);
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +        // Serialize again
> +        writer = new StringWriter();
> +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals("pre"));
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> +        assertTrue(element.getDefaultNamespace() == null);
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument2 (which uses a qualified prefix)
> +     *   Type of Serialization: Serialize and consume
> +     *   Tests update of prefix
> +     * @throws Exception
> +     */
> +    public void testName2QualifiedPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://www.sosnoski.com/uwjws/library", "");
> +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument2));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +
> +        // Serialize and consume.  This should not cause expansion and currently won't update
> +        // the name of the element.
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serializeAndConsume(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument2 (which uses a qualified prefix)
> +     *   Type of Serialization: Serialize and cache
> +     *   Tests attempt to rename namespace and localpart, which is not allowed
> +     * @throws Exception
> +     */
> +    public void testName3QualifiedPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument2));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +
> +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +
> +        try {
> +            root.serialize(writer);
> +        } catch (Exception e) {
> +            // Current Behavior
> +            // The current OMSourceElementImpl ensures that the namespace and localName
> +            // are consistent with the original setting.
> +            return;
> +        }
> +
> +
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +        // Serialize again
> +        writer = new StringWriter();
> +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +
> +
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument2 (which uses a qualified prefix)
> +     *   Type of Serialization: Serialize and cache
> +     *   Tests attempt to rename namespace and localpart, which is not allowed
> +     * @throws Exception
> +     */
> +    public void testName4QualifiedPrefix() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "");
> +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument2));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +
> +        // Serialize and consume.  This should not cause expansion and currently won't update
> +        // the name of the element.
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serializeAndConsume(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain the default prefix declaration
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument3 (which uses unqualified names)
> +     *   Type of Serialization: Serialize and cache
> +     *   Prefix test
> +     * @throws Exception
> +     */
> +    public void testName1Unqualified() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("", "");
> +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument3));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +
> +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(element.getDefaultNamespace() == null || element.getDefaultNamespace().getNamespaceURI().length() == 0);
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +        // Serialize again
> +        writer = new StringWriter();
> +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> +        assertTrue(element.getDefaultNamespace() == null || element.getDefaultNamespace().getNamespaceURI().length() == 0);
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument3 (which uses unqualified names)
> +     *   Type of Serialization: Serialize and consume
> +     *   Tests update of prefix
> +     * @throws Exception
> +     */
> +    public void testName2Unqualified() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("", "");
> +        OMElement element = new OMSourcedElementImpl("library", ns, f, new TestDataSource(testDocument3));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +
> +        // Serialize and consume.  This should not cause expansion and currently won't update
> +        // the name of the element.
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serializeAndConsume(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain default prefix declaration
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument3 (which uses unqualified names)
> +     *   Type of Serialization: Serialize and cache
> +     *   Tests attempt to rename namespace and localpart, which is not allowed
> +     * @throws Exception
> +     */
> +    public void testName3Unqualified() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "DUMMYPREFIX");
> +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument3));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals("DUMMYPREFIX"));
> +
> +        // Serialize and cache.  This should cause expansion and update the name to match the testDocument string
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +
> +        try {
> +            root.serialize(writer);
> +        } catch (Exception e) {
> +            // Current Behavior
> +            // The current OMSourceElementImpl ensures that the namespace and localName
> +            // are consistent with the original setting.
> +            return;
> +        }
> +
> +
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals(""));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +        // Serialize again
> +        writer = new StringWriter();
> +        xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serialize(writer);
> +        xmlwriter.flush();
> +        result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("library"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://www.sosnoski.com/uwjws/library"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +
> +
> +
> +    }
> +
> +    /**
> +     * Tests the OMSourcedElement localName, namespace and prefix settings
> +     * before and after serialization
> +     *   Document: testDocument3 (which uses unqualified names)
> +     *   Type of Serialization: Serialize and cache
> +     *   Tests attempt to rename namespace and localpart, which is not allowed
> +     * @throws Exception
> +     */
> +    public void testName4Unqualified() throws Exception {
> +
> +        OMFactory f = new OMLinkedListImplFactory();
> +
> +        // Create OMSE with a DUMMYPREFIX prefix even though the underlying element uses the default prefix
> +        OMNamespace rootNS = new OMNamespaceImpl("http://sampleroot", "rootPrefix");
> +        OMNamespace ns = new OMNamespaceImpl("http://DUMMYNS", "");
> +        OMElement element = new OMSourcedElementImpl("DUMMYNAME", ns, f, new TestDataSource(testDocument3));
> +        OMElement root = f.createOMElement("root", rootNS);
> +        root.addChild(element);
> +
> +        // Test getting the namespace, localpart and prefix.  This should used not result in expansion
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +
> +        // Serialize and consume.  This should not cause expansion and currently won't update
> +        // the name of the element.
> +        StringWriter writer = new StringWriter();
> +        XMLStreamWriter xmlwriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
> +        root.serializeAndConsume(writer);
> +        xmlwriter.flush();
> +        String result = writer.toString();
> +
> +        assertTrue(element.getLocalName().equals("DUMMYNAME"));
> +        assertTrue(element.getNamespace().getNamespaceURI().equals("http://DUMMYNS"));
> +        assertTrue(element.getNamespace().getPrefix().equals(""));
> +        assertTrue(!result.contains("DUMMY"));  // Make sure that the serialized string does not contain the DUMMY values
> +        assertTrue(!result.contains("xmlns="));  // Make sure that the serialized string does not contain the default prefix declaration
> +
> +        assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> +    }
> +
> +
> +
> +    /**
>       * Tests OMSourcedElement serialization when the root (parent) is serialized.
>       * @throws Exception
>       */
> @@ -244,6 +865,7 @@
>          root.serializeAndConsume(writer);
>          xmlwriter.flush();
>          String result = writer.toString();
> +
>          // We can't test for equivalence because the underlying OMSourceElement is
>          // streamed as it is serialized.  So I am testing for an internal value.
>          assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
> @@ -268,6 +890,7 @@
>
>          xmlwriter.flush();
>          String result = writer.toString();
> +
>          // We can't test for equivalence because the underlying OMSourceElement is
>          // changed as it is serialized.  So I am testing for an internal value.
>          assertTrue("Serialized text error" + result, result.indexOf("1930110111") > 0);
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: commons-dev-help@ws.apache.org
>
>


-- 
Thilina Gunarathne
WSO2, Inc.; http://www.wso2.com/
Home page: http://webservices.apache.org/~thilina/
Blog: http://thilinag.blogspot.com/

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