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/03/15 13:32:31 UTC

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

Author: scheu
Date: Sat Mar 15 05:32:31 2008
New Revision: 637401

URL: http://svn.apache.org/viewvc?rev=637401&view=rev
Log:
Contributor: Rich Scheuerle
Tester: Doug Larson
Added trace to the getNextNSPrefix code to make it easier to track how the user entered the code.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
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=637401&r1=637400&r2=637401&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 Mar 15 05:32:31 2008
@@ -25,6 +25,7 @@
 import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMConstants;
 import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.om.util.CommonUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -37,6 +38,9 @@
 
 public class OMSerializerUtil {
     private static Log log = LogFactory.getLog(OMSerializerUtil.class);
+    private static boolean DEBUG_ENABLED = log.isDebugEnabled();
+    private static boolean ADV_DEBUG_ENABLED = true;
+    
     static long nsCounter = 0;
     
     // This property should be used by the parser to indicate whether 
@@ -546,8 +550,45 @@
         }
     }
 
+    /**
+     * Get the next prefix name
+     * @return next prefix name
+     */
     public static String getNextNSPrefix() {
-        return "axis2ns" + ++nsCounter % Long.MAX_VALUE;
+        
+        String prefix = "axis2ns" + ++nsCounter % Long.MAX_VALUE;
+        
+        /**
+         * Calling getNextNSPrefix is "a last gasp" approach
+         * for obtaining a prefix.  In almost all cases, the
+         * OM element should be provided a prefix by the source parser
+         * or programatically by the user.  We only get to this
+         * spot if one was not supplied.
+         * 
+         * The debug information is two-fold.  
+         * (1) It helps users determine at what point in the code this default
+         * prefix is getting built.  This will help them identify
+         * where to change their code if they don't want a default
+         * prefix.
+         * 
+         * (2) It identifies this place in the code as suspect.
+         * Do we really want to keep generating new prefixes (?).
+         * This could result in lots of symbol table entries for the
+         * subsequent parser that reads this data.  This could hamper
+         * extremely long run usages.
+         * This could be a point where we want a plugin so that users can
+         * decide their own strategy.  Examples from other products
+         * include generating a prefix number from the namespace
+         * string.
+         * 
+         */
+        if (DEBUG_ENABLED) {
+            log.debug("Obtained next prefix:" + prefix);
+            if (ADV_DEBUG_ENABLED) {
+                log.debug(CommonUtils.callStackToString());
+            }
+        }
+        return prefix;
     }
 
     public static String getNextNSPrefix(XMLStreamWriter writer) {
@@ -659,7 +700,7 @@
                     return true;
                 }
             } catch (Throwable t) {
-                if (log.isDebugEnabled()) {
+                if (DEBUG_ENABLED) {
                     log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
                 }
             }

Added: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java?rev=637401&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/CommonUtils.java Sat Mar 15 05:32:31 2008
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */package org.apache.axiom.om.util;
+
+/**
+ * Common Utilities
+ */
+public class CommonUtils {
+
+    /**
+     * Private constructor.  All methods of this class are static.
+     */
+    private CommonUtils() {}
+
+    /**
+     * replace: Like String.replace except that the old and new items are strings.
+     *
+     * @param name string
+     * @param oldT old text to replace
+     * @param newT new text to use
+     * @return replacement string
+     */
+    public static final String replace(String name,
+                                       String oldT, String newT) {
+
+        if (name == null) return "";
+
+        // Create a string buffer that is twice initial length.
+        // This is a good starting point.
+        StringBuffer sb = new StringBuffer(name.length() * 2);
+
+        int len = oldT.length();
+        try {
+            int start = 0;
+            int i = name.indexOf(oldT, start);
+
+            while (i >= 0) {
+                sb.append(name.substring(start, i));
+                sb.append(newT);
+                start = i + len;
+                i = name.indexOf(oldT, start);
+            }
+            if (start < name.length())
+                sb.append(name.substring(start));
+        } catch (NullPointerException e) {
+            // No FFDC code needed
+        }
+
+        return new String(sb);
+    }
+    /**
+     * Get a string containing the stack of the current location
+     *
+     * @return String
+     */
+    public static String callStackToString() {
+        return stackToString(new RuntimeException());
+    }
+
+    /**
+     * Get a string containing the stack of the specified exception
+     *
+     * @param e
+     * @return
+     */
+    public static String stackToString(Throwable e) {
+        java.io.StringWriter sw = new java.io.StringWriter();
+        java.io.BufferedWriter bw = new java.io.BufferedWriter(sw);
+        java.io.PrintWriter pw = new java.io.PrintWriter(bw);
+        e.printStackTrace(pw);
+        pw.close();
+        String text = sw.getBuffer().toString();
+        // Jump past the throwable
+        text = text.substring(text.indexOf("at"));
+        text = replace(text, "at ", "DEBUG_FRAME = ");
+        return text;
+    }
+}



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