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 da...@apache.org on 2008/11/08 11:40:15 UTC

svn commit: r712373 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ds/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/

Author: davidillsley
Date: Sat Nov  8 02:40:14 2008
New Revision: 712373

URL: http://svn.apache.org/viewvc?rev=712373&view=rev
Log:
Update logging for OMSourcedElement to make it easier to debug when unexpected things happen


Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/OMDataSourceExtBase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java?rev=712373&r1=712372&r2=712373&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/ByteArrayDataSource.java Sat Nov  8 02:40:14 2008
@@ -20,6 +20,8 @@
 
 import org.apache.axiom.om.OMDataSourceExt;
 import org.apache.axiom.om.util.StAXUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -35,6 +37,9 @@
  */
 public class ByteArrayDataSource extends OMDataSourceExtBase {
 
+    private static final Log log = LogFactory.getLog(ByteArrayDataSource.class);
+    private static boolean DEBUG_ENABLED = log.isDebugEnabled();
+	
     ByteArray byteArray = null;
     
     /**
@@ -50,6 +55,9 @@
    
  
     public XMLStreamReader getReader() throws XMLStreamException {
+        if (DEBUG_ENABLED) {
+            log.debug("getReader");
+        }
         return StAXUtils.createXMLStreamReader(new ByteArrayInputStream(byteArray.bytes),
                                                byteArray.encoding);                                                                       
     }
@@ -69,7 +77,9 @@
     }
 
     public byte[] getXMLBytes(String encoding) throws UnsupportedEncodingException {
-        
+        if (DEBUG_ENABLED) {
+            log.debug("getXMLBytes encoding="+encoding);
+        }
         // Return the byte array directly if it is the same encoding
         // Otherwise convert the bytes to the proper encoding
         if (!byteArray.encoding.equalsIgnoreCase(encoding)) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/OMDataSourceExtBase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/OMDataSourceExtBase.java?rev=712373&r1=712372&r2=712373&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/OMDataSourceExtBase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/ds/OMDataSourceExtBase.java Sat Nov  8 02:40:14 2008
@@ -18,17 +18,6 @@
  */
 package org.apache.axiom.om.ds;
 
-import org.apache.axiom.om.OMDataSourceExt;
-import org.apache.axiom.om.OMDocument;
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -38,12 +27,28 @@
 import java.util.HashMap;
 import java.util.Iterator;
 
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMDataSourceExt;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * OMDataSourceExtBase is a convenient base class that can be extended
  * by other OMDataSourceExt implementations.
  */
 public abstract class OMDataSourceExtBase implements OMDataSourceExt {
 
+    private static final Log log = LogFactory.getLog(OMDataSourceExtBase.class);
+    private static boolean DEBUG_ENABLED = log.isDebugEnabled();
+	
     HashMap map = null;  // Map of properties
 
     public Object getProperty(String key) {
@@ -69,10 +74,16 @@
    
     public InputStream getXMLInputStream(String encoding)  throws 
         UnsupportedEncodingException{
+        if (DEBUG_ENABLED) {
+            log.debug("getXMLInputStream encoding="+encoding);
+        }
         return new ByteArrayInputStream(getXMLBytes(encoding));
     }
 
     public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {
+        if (DEBUG_ENABLED) {
+            log.debug("serialize output="+output+" format="+format);
+        }
         try {
             // Write bytes to the output stream
             output.write(getXMLBytes(format.getCharSetEncoding()));
@@ -82,6 +93,9 @@
     }
 
     public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
+        if (DEBUG_ENABLED) {
+            log.debug("serialize writer="+writer+" format="+format);
+        }
         try {
             // Convert the bytes into a String and write it to the Writer
             String text = new String(getXMLBytes(format.getCharSetEncoding()));
@@ -94,16 +108,25 @@
     }
 
     public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+        if (DEBUG_ENABLED) {
+            log.debug("serialize xmlWriter="+xmlWriter);
+        }
         // Some XMLStreamWriters (e.g. MTOMXMLStreamWriter) 
         // provide direct access to the OutputStream.  
         // This allows faster writing.
         OutputStream os = getOutputStream(xmlWriter);
         if (os != null) {
+        	if (DEBUG_ENABLED) {
+                log.debug("serialize OutputStream optimisation: true");
+            }
             String encoding = getCharacterEncoding(xmlWriter);
             OMOutputFormat format = new OMOutputFormat();
             format.setCharSetEncoding(encoding);
             serialize(os, format);
         } else {
+        	if (DEBUG_ENABLED) {
+                log.debug("serialize OutputStream optimisation: false");
+            }
             // Read the bytes into a reader and 
             // write to the writer.
             XMLStreamReader xmlReader = getReader();

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?rev=712373&r1=712372&r2=712373&view=diff
==============================================================================
--- 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 Nov  8 02:40:14 2008
@@ -31,6 +31,7 @@
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.OMNamespaceImpl;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.StAXUtils;
@@ -75,6 +76,8 @@
     private static Log log = LogFactory.getLog(OMSourcedElementImpl.class);
     private static final boolean isDebugEnabled = log.isDebugEnabled();
     
+    private static Log forceExpandLog = LogFactory.getLog(OMSourcedElementImpl.class.toString()+".forceExpand");
+    
     private XMLStreamReader readerFromDS = null;  // Reader from DataSource
 
     /**
@@ -237,6 +240,12 @@
             if (isDebugEnabled) {
                 log.debug("forceExpand: expanding element " +
                         getPrintableName());
+                if(forceExpandLog.isDebugEnabled()){
+                	// When using an OMSourcedElement, it can be particularly difficult to
+                	// determine why an expand occurs... a stack trace should help debugging this
+                	Exception e = new Exception("Debug Stack Trace");
+                	forceExpandLog.debug("forceExpand stack", e);
+                }
             }
 
             // Get the XMLStreamReader