Author: veithen
Date: Sat Aug  8 14:39:11 2009
New Revision: 802385

URL: http://svn.apache.org/viewvc?rev=802385&view=rev
Log:
Eliminated the isSetPrefixBeforeStartElement hack. This was introduced to work 
around a StAX conformance issue in early versions of IBM's XLXP parser, but it 
causes unnecessary overhead that penalizes parsers that conform to the StAX 
specifications. Since the StAX conformance issue in XLXP is now handled 
properly in the StAX dialect implementation, the hack can be eliminated.

Regression tested with Axis2 trunk.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java?rev=802385&r1=802384&r2=802385&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/serialize/StreamingOMSerializer.java
 Sat Aug  8 14:39:11 2009
@@ -178,18 +178,15 @@
         // Please keep this code in sync with the code in 
OMSerializerUtil.serializeStartpart
 
         // The algorithm is:
+        // ... generate writeStartElement
+        //
         // ... 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 (See NOTE_A)
-        //
         // ... generate writeNamespace/writerDefaultNamespace for the new 
namespace declarations determine during the "set" processing
         // ... generate writeAttribute for each attribute
 
-        // NOTE_A: To confuse matters, some StAX vendors (including woodstox), 
believe that the setPrefix bindings
-        // should occur after the writeStartElement.  If this is the case, the 
writeStartElement is generated first.
-
         ArrayList writePrefixList = null;
         ArrayList writeNSList = null;
 
@@ -200,37 +197,34 @@
         eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : 
eNamespace;
         
         // Write the startElement if required
-        boolean setPrefixFirst = 
OMSerializerUtil.isSetPrefixBeforeStartElement(writer);
-        if (!setPrefixFirst) {
-            if (eNamespace != null) {
-                if (ePrefix == null) {
-                    if (!OMSerializerUtil.isAssociated("", eNamespace, 
writer)) {
-                        
-                        if (writePrefixList == null) {
-                            writePrefixList = new ArrayList();
-                            writeNSList = new ArrayList();
-                        }
-                        writePrefixList.add("");
-                        writeNSList.add(eNamespace);
-                    }   
+        if (eNamespace != null) {
+            if (ePrefix == null) {
+                if (!OMSerializerUtil.isAssociated("", eNamespace, writer)) {
                     
-                    writer.writeStartElement("", reader.getLocalName(), 
eNamespace);    
-                } else {
-                    
-                    if (!OMSerializerUtil.isAssociated(ePrefix, eNamespace, 
writer)) {
-                        if (writePrefixList == null) {
-                            writePrefixList = new ArrayList();
-                            writeNSList = new ArrayList();
-                        }   
-                        writePrefixList.add(ePrefix);
-                        writeNSList.add(eNamespace);
+                    if (writePrefixList == null) {
+                        writePrefixList = new ArrayList();
+                        writeNSList = new ArrayList();
                     }
-                    
-                    writer.writeStartElement(ePrefix, reader.getLocalName(), 
eNamespace);
-                }
+                    writePrefixList.add("");
+                    writeNSList.add(eNamespace);
+                }   
+                
+                writer.writeStartElement("", reader.getLocalName(), 
eNamespace);    
             } else {
-                writer.writeStartElement(reader.getLocalName());
+                
+                if (!OMSerializerUtil.isAssociated(ePrefix, eNamespace, 
writer)) {
+                    if (writePrefixList == null) {
+                        writePrefixList = new ArrayList();
+                        writeNSList = new ArrayList();
+                    }   
+                    writePrefixList.add(ePrefix);
+                    writeNSList.add(eNamespace);
+                }
+                
+                writer.writeStartElement(ePrefix, reader.getLocalName(), 
eNamespace);
             }
+        } else {
+            writer.writeStartElement(reader.getLocalName());
         }
 
         // Generate setPrefix for the namespace declarations
@@ -241,7 +235,7 @@
             String namespace = reader.getNamespaceURI(i);
             namespace = (namespace != null && namespace.length() == 0) ? null 
: namespace;
 
-            String newPrefix = OMSerializerUtil.generateSetPrefix(prefix, 
namespace, writer, false, setPrefixFirst);
+            String newPrefix = OMSerializerUtil.generateSetPrefix(prefix, 
namespace, writer, false);
             // If this is a new association, remember it so that it can 
written out later
             if (newPrefix != null) {
                 if (writePrefixList == null) {
@@ -258,7 +252,7 @@
         // Generate setPrefix for the element
         // If the prefix is not associated with a namespace yet, remember it 
so that we can
         // write out a namespace declaration
-        String newPrefix = OMSerializerUtil.generateSetPrefix(ePrefix, 
eNamespace, writer, false, setPrefixFirst);
+        String newPrefix = OMSerializerUtil.generateSetPrefix(ePrefix, 
eNamespace, writer, false);
         // If this is a new association, remember it so that it can written 
out later
         if (newPrefix != null) {
             if (writePrefixList == null) {
@@ -288,7 +282,7 @@
                         writerPrefix :
                         generateUniquePrefix(writer.getNamespaceContext());
             }
-            newPrefix = OMSerializerUtil.generateSetPrefix(prefix, namespace, 
writer, true, setPrefixFirst);
+            newPrefix = OMSerializerUtil.generateSetPrefix(prefix, namespace, 
writer, true);
             // If the prefix is not associated with a namespace yet, remember 
it so that we can
             // write out a namespace declaration
             if (newPrefix != null) {
@@ -303,19 +297,6 @@
             }
         }
 
-        // Now write the startElement
-        if (setPrefixFirst) {
-            if (eNamespace != null) {
-                if (ePrefix == null) {
-                    writer.writeStartElement("", reader.getLocalName(), 
eNamespace);
-                } else {
-                    writer.writeStartElement(ePrefix, reader.getLocalName(), 
eNamespace);
-                }
-            } else {
-                writer.writeStartElement(reader.getLocalName());
-            }
-        }
-
         // Now write out the list of namespace declarations in this list that 
we constructed
         // while doing the "set" processing.
         if (writePrefixList != null) {

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java?rev=802385&r1=802384&r2=802385&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java
 Sat Aug  8 14:39:11 2009
@@ -43,12 +43,6 @@
     
     static long nsCounter = 0;
     
-    // This property should be used by the parser to indicate whether 
-    // setPrefix should be done before or after the Start Element event.
-    // This property is not yet a standard, but at least one parser.
-    private static final String IS_SET_PREFIX_BEFORE_PROPERTY = 
-        "javax.xml.stream.XMLStreamWriter.isSetPrefixBeforeStartElement";
-
     /**
      * Method serializeEndpart.
      *
@@ -151,67 +145,13 @@
     }
 
     /**
-     * Unfortunately there is disagreement in the user community about the 
semantics of setPrefix on
-     * the XMLStreamWriter.  An example will explain the difference: 
writer.startElement("a")
-     * writer.setPrefix("pre", "urn://sample") writer.startElement("b")
-     * <p/>
-     * Some user communities (woodstox) believe that the setPrefix is 
associate with the scope for
-     * "a" and thus remains in scope until the end of a.  The basis for this 
believe is
-     * XMLStreamWriter javadoc (which some would argue is incomplete).
-     * <p/>
-     * Some user communities believe that the setPrefix is associated with the 
"b" element. These
-     * communities reference an example in the specification and historical 
usage of SAX.
-     * <p/>
-     * This method will return true if the setPrefix is associated with the 
next writeStartElement.
-     *
-     * @param writer
-     * @return true if setPrefix should be generated before startElement
+     * @deprecated This method was used to work around a StAX conformance 
issue in early versions
+     * of the XL XP-J parser. This is now handled by
+     * {...@link org.apache.axiom.util.stax.dialect.StAXDialect}, and this 
method always returns
+     * <code>false</code>.
      */
-    private static boolean cache_isSetPrefixBeforeStartElement;
-    private static XMLStreamWriter cache_isSetPrefixBeforeStartElement_writer 
= null;
-    private static String semifore = "isSetPrefixBeforeStartElement";
     public static boolean isSetPrefixBeforeStartElement(XMLStreamWriter 
writer) {
-        // Try the cached value
-        if (cache_isSetPrefixBeforeStartElement_writer == writer) {
-            synchronized(semifore) {
-                if (cache_isSetPrefixBeforeStartElement_writer == writer) {
-                    return cache_isSetPrefixBeforeStartElement;
-                }
-            }
-        }
-        
-        // There is no cached value for this writer, so try getting 
-        // the property from the writer.
-        boolean ret = false;
-        try {
-            Boolean value = 
(Boolean)writer.getProperty(IS_SET_PREFIX_BEFORE_PROPERTY);
-            // this will always be false if the property is defined
-            if (value != null) {
-                ret = value.booleanValue();
-                // Cache the answer
-                synchronized(semifore) {
-                    cache_isSetPrefixBeforeStartElement_writer = writer;
-                    cache_isSetPrefixBeforeStartElement = ret;
-                }
-                return ret;
-            }
-        }
-        catch (IllegalArgumentException e) {
-            // Some parsers throw an exception for unknown properties.
-        }
-        if (!ret) {
-            // Fallback: Toggle based on sun or woodstox implementation.
-            NamespaceContext nc = writer.getNamespaceContext();
-            ret = (nc == null ||
-                    (nc.getClass().getName().indexOf("xlxp") != -1));
-        }
-        
-        // Cache the answer
-        synchronized(semifore) {
-            cache_isSetPrefixBeforeStartElement_writer = writer;
-            cache_isSetPrefixBeforeStartElement = ret;
-        }
-        return ret;
+        return false;
     }
 
     /**
@@ -242,18 +182,15 @@
         // Please keep this code in sync with the code in 
StreamingOMSerializer.serializeElement
 
         // The algorithm is:
+        // ... generate writeStartElement
+        //
         // ... 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 (See NOTE_A)
-        //
         // ... generate writeNamespace/writerDefaultNamespace for the new 
namespace declarations determine during the "set" processing
         // ... generate writeAttribute for each attribute
 
-        // NOTE_A: To confuse matters, some StAX vendors (including woodstox), 
believe that the setPrefix bindings
-        // should occur after the writeStartElement.  If this is the case, the 
writeStartElement is generated first.
-
         ArrayList writePrefixList = null;
         ArrayList writeNSList = null;
 
@@ -268,44 +205,39 @@
         ePrefix = (ePrefix != null && ePrefix.length() == 0) ? null : ePrefix;
         eNamespace = (eNamespace != null && eNamespace.length() == 0) ? null : 
eNamespace;
 
-        // Write the startElement if required
-        boolean setPrefixFirst = isSetPrefixBeforeStartElement(writer);
-        
-        if (!setPrefixFirst) {
-            if (eNamespace != null) {
-                if (ePrefix == null) {
-                    if (!isAssociated("", eNamespace, writer)) {
-                        if (writePrefixList == null) {
-                            writePrefixList = new ArrayList();
-                            writeNSList = new ArrayList();
-                        }
-                        if (! writePrefixList.contains("")) {
-                            writePrefixList.add("");
-                            writeNSList.add(eNamespace);
-                        }
+        if (eNamespace != null) {
+            if (ePrefix == null) {
+                if (!isAssociated("", eNamespace, writer)) {
+                    if (writePrefixList == null) {
+                        writePrefixList = new ArrayList();
+                        writeNSList = new ArrayList();
                     }
-                    writer.writeStartElement("", localName, eNamespace);
-                } else {
-                    /*
-                     * If 
XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI) associates
-                     * the prefix with the namespace .. 
-                     */
-                    if (!isAssociated(ePrefix, eNamespace, writer)) {
-                        if (writePrefixList == null) {
-                            writePrefixList = new ArrayList();
-                            writeNSList = new ArrayList();
-                        }
-                        if (! writePrefixList.contains(ePrefix)) {
-                            writePrefixList.add(ePrefix);
-                            writeNSList.add(eNamespace);
-                        }
+                    if (! writePrefixList.contains("")) {
+                        writePrefixList.add("");
+                        writeNSList.add(eNamespace);
                     }
-                    
-                    writer.writeStartElement(ePrefix, localName, eNamespace);
                 }
+                writer.writeStartElement("", localName, eNamespace);
             } else {
-                writer.writeStartElement(localName);
+                /*
+                 * If 
XMLStreamWriter.writeStartElement(prefix,localName,namespaceURI) associates
+                 * the prefix with the namespace .. 
+                 */
+                if (!isAssociated(ePrefix, eNamespace, writer)) {
+                    if (writePrefixList == null) {
+                        writePrefixList = new ArrayList();
+                        writeNSList = new ArrayList();
+                    }
+                    if (! writePrefixList.contains(ePrefix)) {
+                        writePrefixList.add(ePrefix);
+                        writeNSList.add(eNamespace);
+                    }
+                }
+                
+                writer.writeStartElement(ePrefix, localName, eNamespace);
             }
+        } else {
+            writer.writeStartElement(localName);
         }
 
         // Generate setPrefix for the namespace declarations
@@ -322,7 +254,7 @@
             namespace = (namespace != null && namespace.length() == 0) ? null 
: namespace;
 
 
-            String newPrefix = generateSetPrefix(prefix, namespace, writer, 
false, setPrefixFirst);
+            String newPrefix = generateSetPrefix(prefix, namespace, writer, 
false);
             // If this is a new association, remember it so that it can 
written out later
             if (newPrefix != null) {
                 if (writePrefixList == null) {
@@ -338,7 +270,7 @@
 
         // Generate setPrefix for the element
         // Get the prefix and namespace of the element.  "" and null are 
identical.
-        String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer, 
false, setPrefixFirst);
+        String newPrefix = generateSetPrefix(ePrefix, eNamespace, writer, 
false);
         // If this is a new association, remember it so that it can written 
out later
         if (newPrefix != null) {
             if (writePrefixList == null) {
@@ -373,7 +305,7 @@
                 prefix = (writerPrefix != null) ?
                         writerPrefix : getNextNSPrefix();
             }
-            newPrefix = generateSetPrefix(prefix, namespace, writer, true, 
setPrefixFirst);
+            newPrefix = generateSetPrefix(prefix, namespace, writer, true);
             // If the prefix is not associated with a namespace yet, remember 
it so that we can
             // write out a namespace declaration
             if (newPrefix != null) {
@@ -388,19 +320,6 @@
             }
         }
 
-        // Write the startElement if required
-        if (setPrefixFirst) {
-            if (eNamespace != null) {
-                if (ePrefix == null) {
-                    writer.writeStartElement("", localName, eNamespace);
-                } else {
-                    writer.writeStartElement(ePrefix, localName, eNamespace);
-                }
-            } else {
-                writer.writeStartElement(localName);
-            }
-        }
-
         // Now write out the list of namespace declarations in this list that 
we constructed
         // while doing the "set" processing.
         if (writePrefixList != null) {
@@ -639,7 +558,7 @@
      * @return prefix name if a setPrefix/setDefaultNamespace is performed
      */
     public static String generateSetPrefix(String prefix, String namespace, 
XMLStreamWriter writer,
-                                           boolean attr, boolean 
isSetPrefixFirst) throws XMLStreamException {
+                                           boolean attr) throws 
XMLStreamException {
         prefix = (prefix == null) ? "" : prefix;
         
         

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java?rev=802385&r1=802384&r2=802385&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/stax/xop/XOPEncodingStreamWriter.java
 Sat Aug  8 14:39:11 2009
@@ -28,7 +28,6 @@
 
 import org.apache.axiom.ext.stax.datahandler.DataHandlerProvider;
 import org.apache.axiom.ext.stax.datahandler.DataHandlerWriter;
-import org.apache.axiom.om.impl.util.OMSerializerUtil;
 import org.apache.axiom.util.stax.XMLStreamWriterUtils;
 
 /**
@@ -71,16 +70,9 @@
         if (writerPrefix != null) {
             parent.writeStartElement(XOPConstants.NAMESPACE_URI, "Include");
         } else {
-            // According to StAX, setPrefix must occur before writeStartElement
-            if (OMSerializerUtil.isSetPrefixBeforeStartElement(parent)) {
-                parent.setPrefix(XOPConstants.DEFAULT_PREFIX, 
XOPConstants.NAMESPACE_URI);
-                parent.writeStartElement(XOPConstants.DEFAULT_PREFIX, 
XOPConstants.INCLUDE,
-                        XOPConstants.NAMESPACE_URI);
-            } else {
-                parent.writeStartElement(XOPConstants.DEFAULT_PREFIX, 
XOPConstants.INCLUDE,
-                        XOPConstants.NAMESPACE_URI);
-                parent.setPrefix(XOPConstants.DEFAULT_PREFIX, 
XOPConstants.NAMESPACE_URI);
-            }
+            parent.writeStartElement(XOPConstants.DEFAULT_PREFIX, 
XOPConstants.INCLUDE,
+                    XOPConstants.NAMESPACE_URI);
+            parent.setPrefix(XOPConstants.DEFAULT_PREFIX, 
XOPConstants.NAMESPACE_URI);
             parent.writeNamespace(XOPConstants.DEFAULT_PREFIX, 
XOPConstants.NAMESPACE_URI);
         }
         parent.writeAttribute(XOPConstants.HREF, "cid:" + contentID); // TODO: 
wrong; need to URI encode


Reply via email to