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 2008/04/23 20:25:29 UTC

svn commit: r650980 - /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/util/OMSerializerUtil.java

Author: scheu
Date: Wed Apr 23 11:25:27 2008
New Revision: 650980

URL: http://svn.apache.org/viewvc?rev=650980&view=rev
Log:
WSCOMMONS-325
Contributor:Rich Scheuerle
Added some simple caching for the check.

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

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=650980&r1=650979&r2=650980&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 Wed Apr 23 11:25:27 2008
@@ -167,22 +167,46 @@
      * @param writer
      * @return true if setPrefix should be generated before startElement
      */
+    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) {
-                return value.booleanValue();
+                ret = value.booleanValue();
             }
         }
         catch (IllegalArgumentException e) {
             // Some parsers throw an exception for unknown properties.
         }
-        // Fallback: Toggle based on sun or woodstox implementation.
-        NamespaceContext nc = writer.getNamespaceContext();
-        return (nc == null || 
-                (nc.getClass().getName().indexOf("wstx") == -1 && 
-                 nc.getClass().getName().indexOf("sun") == -1));
+        if (!ret) {
+            // Fallback: Toggle based on sun or woodstox implementation.
+            NamespaceContext nc = writer.getNamespaceContext();
+            ret = (nc == null || 
+                    (nc.getClass().getName().indexOf("wstx") == -1 && 
+                            nc.getClass().getName().indexOf("sun") == -1));
+        }
+        
+        // Cache the answer
+        synchronized(semifore) {
+            cache_isSetPrefixBeforeStartElement_writer = writer;
+            cache_isSetPrefixBeforeStartElement = ret;
+        }
+        return ret;
     }
 
     /**