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 ch...@apache.org on 2006/07/24 09:58:25 UTC

svn commit: r424954 - in /webservices/commons/trunk/modules/axiom: src/org/apache/axiom/om/impl/serialize/ test-resources/binary/ test/org/apache/axiom/om/impl/serializer/

Author: chinthaka
Date: Mon Jul 24 00:58:24 2006
New Revision: 424954

URL: http://svn.apache.org/viewvc?rev=424954&view=rev
Log:
Reverting the last commit as the build is failing due to that. PLEASE DO NOT COMMIT ANYTHING WITHOUT TESTING THE BUILD.

Added:
    webservices/commons/trunk/modules/axiom/test-resources/binary/
Removed:
    webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/StreamingOMSerializerTest.java
Modified:
    webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
    webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/NoNamespaceSerializerTest.java

Modified: webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?rev=424954&r1=424953&r2=424954&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java (original)
+++ webservices/commons/trunk/modules/axiom/src/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java Mon Jul 24 00:58:24 2006
@@ -1,6 +1,5 @@
 /*
  * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,8 +16,6 @@
 
 package org.apache.axiom.om.impl.serialize;
 
-import java.util.ArrayList;
-
 import org.apache.axiom.om.OMSerializer;
 
 import javax.xml.namespace.NamespaceContext;
@@ -103,7 +100,6 @@
     }
 
     /**
-     * Write out the start element, its namespace/prefixes and attributes
      * @param reader
      * @param writer
      * @throws XMLStreamException
@@ -111,176 +107,47 @@
     protected void serializeElement(XMLStreamReader reader,
                                     XMLStreamWriter writer)
             throws XMLStreamException {
-        
-    	ArrayList  prefixList = null;
-    	ArrayList  nsList = null;
-    	
-    	// The algorithm is:
-        // ... generate setPrefix/setDefaultNamespace for each namespace declaration if the prefix is unassociated.
-    	// ... generate setPrefix/setDefaultNamespace if the prefix of the element is unassociated
-    	// ... generate setPrefix/setDefaultNamespace for each unassociated prefix of the attributes.
-    	//
-    	// ... generate writeStartElement
-    	//
-    	// ... generate writeNamespace/writerDefaultNamespace for each namespace declaration on the element
-    	// ... generate writeNamespace/writeDefaultNamespace for any new "autogen" namespace/prefixes
-    	// ... generate writeAttribute for each attribute
-    	
-        // Generate setPrefix for the namespace declarations
-        int count = reader.getNamespaceCount();
-        for (int i = 0; i < count; i++) {
-        	String prefix = reader.getNamespacePrefix(i);
-        	prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
-        	String namespace = reader.getNamespaceURI(i);
-        	namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-        	
-        	generateSetPrefix(prefix, namespace, writer);
-        }
-        
-    	// Generate setPrefix for the element
-    	// Get the prefix and namespace of the element.  "" and null are identical.
-        String ePrefix = reader.getPrefix();
-    	ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
-    	String eNamespace = reader.getNamespaceURI();
-    	eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : eNamespace;
-    	String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer);
-    	// If the prefix is not associated with a namespace yet, remember it so that we can
-    	// write out a namespace declaration
-    	if (newPrefix != null) {
-    		if (prefixList == null) {
-    			prefixList= new ArrayList();
-    			nsList = new ArrayList();
-    		}
-    		prefixList.add(newPrefix);
-    		nsList.add(eNamespace);
-    	}
-    
-        // Now write the namespaces for each attribute
-        count = reader.getAttributeCount();
-        for (int i = 0; i < count; i++) {
-            String prefix = reader.getAttributePrefix(i);
-            prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
-            String namespace = reader.getAttributeNamespace(i);
-            namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-            
-            // Default prefix referencing is not allowed on an attribute
-            if (prefix == null && namespace != null) {
-            	String writerPrefix = writer.getPrefix(namespace);
-            	writerPrefix = (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
-            	prefix = (writerPrefix != null) ? 
-            			writerPrefix :
-            	        generateUniquePrefix(writer.getNamespaceContext());
+        String prefix = reader.getPrefix();
+        String nameSpaceName = reader.getNamespaceURI();
+        if (nameSpaceName != null) {
+            String writer_prefix = writer.getPrefix(nameSpaceName);
+            if (writer_prefix != null) {
+                writer.writeStartElement(nameSpaceName, reader.getLocalName());
+            } else {
+                if (prefix != null) {
+                    writer.writeStartElement(prefix, reader.getLocalName(),
+                            nameSpaceName);
+                    writer.writeNamespace(prefix, nameSpaceName);
+                    writer.setPrefix(prefix, nameSpaceName);
+                } else {
+                    writer.writeStartElement(nameSpaceName,
+                            reader.getLocalName());
+                    writer.writeDefaultNamespace(nameSpaceName);
+                    writer.setDefaultNamespace(nameSpaceName);
+                }
             }
-            newPrefix = generateSetPrefix(prefix, namespace, writer);
-            // If the prefix is not associated with a namespace yet, remember it so that we can
-        	// write out a namespace declaration
-        	if (newPrefix != null) {
-        		if (prefixList == null) {
-        			prefixList= new ArrayList();
-        			nsList = new ArrayList();
-        		}
-        		prefixList.add(newPrefix);
-        		nsList.add(eNamespace);
-        	}
-        }
-        
-        // Now write the startElement
-        if (eNamespace != null) {
-        	writer.writeStartElement(ePrefix, reader.getLocalName(), eNamespace);
         } else {
-        	writer.writeStartElement(reader.getLocalName());
-        }
-        
-        // Now write the namespace declarations
-        count = reader.getNamespaceCount();
-        for (int i = 0; i < count; i++) {
-        	String prefix = reader.getNamespacePrefix(i);
-        	prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
-        	String namespace = reader.getNamespaceURI(i);
-        	if (prefix != null) {
-        		writer.writeNamespace(prefix, namespace);
-        	} else {
-        		writer.writeDefaultNamespace(namespace);
-        	}
+            writer.writeStartElement(reader.getLocalName());
         }
-        
-        // Now write out the namespaces that for prefixes that are not associated
-        if (prefixList != null) {
-        	for (int i=0; i<prefixList.size(); i++) {
-        		String prefix = (String) prefixList.get(i);
-        		String namespace = (String) nsList.get(i);
-        		if (prefix != null) {
-            		writer.writeNamespace(prefix, namespace);
-            	} else {
-            		writer.writeDefaultNamespace(namespace);
-            	}
-        	}
-        }
-        
-        // Now write the attributes
-        count = reader.getAttributeCount();
+
+
+        // add the namespaces
+        int count = reader.getNamespaceCount();
+        String namespacePrefix;
         for (int i = 0; i < count; i++) {
-            String prefix = reader.getAttributePrefix(i);
-            prefix = (prefix != null && prefix.length() == 0) ? null : prefix;
-            String namespace = reader.getAttributeNamespace(i);
-            namespace = (namespace != null && namespace.length() == 0) ? null : namespace;
-            
-            
-            if (prefix == null && namespace != null) {
-            	// Default namespaces are not allowed on an attribute reference.
-                // Earlier in this code, a unique prefix was added for this case...now obtain and use it
-            	prefix = writer.getPrefix(namespace);
-            } else if (namespace != null) {
-            	// Use the writer's prefix if it is different
-            	String writerPrefix = writer.getPrefix(namespace);
-            	if (!prefix.equals(writerPrefix)) {
-            		prefix = writerPrefix;
-            	}
-            }
-            if (namespace != null) {
-            	// Qualified attribute
-            	writer.writeAttribute(prefix, namespace,
-                    reader.getAttributeLocalName(i),
-                    reader.getAttributeValue(i));
-            } else {
-            	// Unqualified attribute
-            	writer.writeAttribute(reader.getAttributeLocalName(i),
-                        reader.getAttributeValue(i));
-            }
-        }
-    }
+            namespacePrefix = reader.getNamespacePrefix(i);
+            if(namespacePrefix != null && namespacePrefix.length()==0)
+                continue;
 
-    /**
-     * Generate setPrefix/setDefaultNamespace if the prefix is not associated
-     * @param prefix
-     * @param namespace
-     * @param writer
-     * @return prefix name if a setPrefix/setDefaultNamespace is performed
-     */
-    private String generateSetPrefix(String prefix, String namespace, XMLStreamWriter writer) throws XMLStreamException {
-    	// Generate setPrefix/setDefaultNamespace if the prefix is not associated.
-        if (namespace != null) {
-        	String writerPrefix = writer.getPrefix(namespace);
-        	writerPrefix = (writerPrefix != null && writerPrefix.length() == 0) ? null : writerPrefix;
-        	// Qualified Name
-        	if (writerPrefix == prefix ||
-        	    (writerPrefix != null && writerPrefix.equals(prefix))) {
-        		// Already associated...a setPrefix is not needed
-        		return null;
-        	} else {
-        		if (prefix == null) {
-        			writer.setDefaultNamespace(namespace);
-        		} else {
-        			writer.setPrefix(prefix, namespace);
-        		}
-        		return prefix;
-        	}
-        } else {
-        	// Disable the default namespace
-        	writer.setDefaultNamespace("");
+            serializeNamespace(namespacePrefix,
+                    reader.getNamespaceURI(i), writer);
         }
-        return null;
+
+        // add attributes
+        serializeAttributes(reader, writer);
+
     }
+
     /**
      * Method serializeEndElement.
      *
@@ -344,14 +211,14 @@
         for (int i = 0; i < count; i++) {
             prefix = reader.getAttributePrefix(i);
             namespaceName = reader.getAttributeNamespace(i);
-            //
-            //   Due to parser implementations returning null as the namespace URI
-            //  (for the empty namespace) we need to make sure that we deal with
-            //  a namespace name that is not null. The best way to work around this
-            //  issue is to set the namespace uri to "" if it is null
-           
+            /*
+               Due to parser implementations returning null as the namespace URI
+              (for the empty namespace) we need to make sure that we deal with
+              a namespace name that is not null. The best way to work around this
+              issue is to set the namespace uri to "" if it is null
+            */
             if (namespaceName==null) namespaceName="";
-            
+
             writerPrefix =writer.getNamespaceContext().getPrefix(namespaceName);
 
             if (!"".equals(namespaceName)){
@@ -405,5 +272,22 @@
         }
 
         return prefix;
+    }
+    /**
+     * Method serializeNamespace.
+     * @param prefix
+     * @param URI
+     * @param writer
+     * @throws XMLStreamException
+     */
+    private void serializeNamespace(String prefix,
+                                    String URI,
+                                    XMLStreamWriter writer)
+            throws XMLStreamException {
+        String prefix1 = writer.getPrefix(URI);
+        if (prefix1 == null) {
+            writer.writeNamespace(prefix, URI);
+            writer.setPrefix(prefix, URI);
+        }
     }
 }

Modified: webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/NoNamespaceSerializerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/NoNamespaceSerializerTest.java?rev=424954&r1=424953&r2=424954&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/NoNamespaceSerializerTest.java (original)
+++ webservices/commons/trunk/modules/axiom/test/org/apache/axiom/om/impl/serializer/NoNamespaceSerializerTest.java Mon Jul 24 00:58:24 2006
@@ -19,19 +19,16 @@
 import junit.framework.TestCase;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.InputStreamReader;
 
 public class NoNamespaceSerializerTest extends TestCase {
@@ -108,7 +105,7 @@
 
     }
 
-    public void testsubmitPurchaseOrder()
+    public void submitPurchaseOrderTest()
             throws Exception {
         SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory();
         SOAPEnvelope env = omFactory.getDefaultEnvelope();



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