You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2007/04/02 17:51:40 UTC

svn commit: r524806 - /xalan/java/trunk/src/org/apache/xml/utils/DefaultErrorHandler.java

Author: zongaro
Date: Mon Apr  2 08:51:39 2007
New Revision: 524806

URL: http://svn.apache.org/viewvc?view=rev&rev=524806
Log:
Part of fix for Jira issue XALANJ-2375.

Changed default constructor to defer creating a PrintWriter through which to
report any error messages until a message actually needs to be reported.  A
PrintWriter instance consumes a substantial amount of space, and deferring its
creation saves initialization time for the XPath API and XSLT.

Reviewed by Christine Li (jycli () ca ! ibm ! com).

Modified:
    xalan/java/trunk/src/org/apache/xml/utils/DefaultErrorHandler.java

Modified: xalan/java/trunk/src/org/apache/xml/utils/DefaultErrorHandler.java
URL: http://svn.apache.org/viewvc/xalan/java/trunk/src/org/apache/xml/utils/DefaultErrorHandler.java?view=diff&rev=524806&r1=524805&r2=524806
==============================================================================
--- xalan/java/trunk/src/org/apache/xml/utils/DefaultErrorHandler.java (original)
+++ xalan/java/trunk/src/org/apache/xml/utils/DefaultErrorHandler.java Mon Apr  2 08:51:39 2007
@@ -79,10 +79,24 @@
    */
   public DefaultErrorHandler(boolean throwExceptionOnError)
   {
-    m_pw = new PrintWriter(System.err, true);
+    // Defer creation of a PrintWriter until it's actually needed
     m_throwExceptionOnError = throwExceptionOnError;
   }
 
+  /**
+   * Retrieve <code>java.io.PrintWriter</code> to which errors are being
+   * directed.
+   * @return The <code>PrintWriter</code> installed via the constructor
+   *         or the default <code>PrintWriter</code>
+   */
+  public PrintWriter getErrorWriter() {
+    // Defer creating the java.io.PrintWriter until an error needs to be
+    // reported.
+    if (m_pw == null) {
+      m_pw = new PrintWriter(System.err, true);
+    }
+    return m_pw;
+  }
 
   /**
    * Receive notification of a warning.
@@ -102,8 +116,10 @@
    */
   public void warning(SAXParseException exception) throws SAXException
   {
-    printLocation(m_pw, exception);
-    m_pw.println("Parser warning: " + exception.getMessage());
+    PrintWriter pw = getErrorWriter();
+
+    printLocation(pw, exception);
+    pw.println("Parser warning: " + exception.getMessage());
   }
 
   /**
@@ -130,7 +146,7 @@
   public void error(SAXParseException exception) throws SAXException
   {
     //printLocation(exception);
-    // m_pw.println(exception.getMessage());
+    // getErrorWriter().println(exception.getMessage());
 
     throw exception;
   }
@@ -157,7 +173,7 @@
   public void fatalError(SAXParseException exception) throws SAXException
   {
     // printLocation(exception);
-    // m_pw.println(exception.getMessage());
+    // getErrorWriter().println(exception.getMessage());
 
     throw exception;
   }
@@ -181,9 +197,10 @@
    */
   public void warning(TransformerException exception) throws TransformerException
   {
-    printLocation(m_pw, exception);
+    PrintWriter pw = getErrorWriter();
 
-    m_pw.println(exception.getMessage());
+    printLocation(pw, exception);
+    pw.println(exception.getMessage());
   }
 
   /**
@@ -216,8 +233,10 @@
       throw exception;
     else
     {
-      printLocation(m_pw, exception);
-      m_pw.println(exception.getMessage());
+      PrintWriter pw = getErrorWriter();
+
+      printLocation(pw, exception);
+      pw.println(exception.getMessage());
     }
   }
 
@@ -249,8 +268,10 @@
       throw exception;
     else
     {
-      printLocation(m_pw, exception);
-      m_pw.println(exception.getMessage());
+      PrintWriter pw = getErrorWriter();
+
+      printLocation(pw, exception);
+      pw.println(exception.getMessage());
     }
   }
   
@@ -327,7 +348,7 @@
         
     if(null != locator)
     {
-      // m_pw.println("Parser fatal error: "+exception.getMessage());
+      // getErrorWriter().println("Parser fatal error: "+exception.getMessage());
       String id = (null != locator.getPublicId() )
                   ? locator.getPublicId()
                     : (null != locator.getSystemId())



---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org