sboag 01/08/06 15:17:17
Modified: java/src/org/apache/xalan/transformer
TransformerHandlerImpl.java TransformerImpl.java
java/src/org/apache/xalan/xslt Process.java
java/src/org/apache/xml/dtm/ref
IncrementalSAXSource_Filter.java
java/src/org/apache/xml/utils DefaultErrorHandler.java
java/src/org/apache/xpath/operations Variable.java
Log:
This checkin hopefully fixes many problems with bad diagnostics lately, but
at the expense of a slight change in behavior. The rule now is, the
DefaultErrorHandler never outputs location info for error and fatalError...
this has to be done
by the catcher of the exception. Convenience methods for this are
in DefaultErrorHandler#printLocation. This method will unwrap the
exception as close to the originating source as possible.
Revision Changes Path
1.13 +39 -18
xml-xalan/java/src/org/apache/xalan/transformer/TransformerHandlerImpl.java
Index: TransformerHandlerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerHandlerImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TransformerHandlerImpl.java 2001/08/06 06:24:50 1.12
+++ TransformerHandlerImpl.java 2001/08/06 22:17:17 1.13
@@ -148,32 +148,41 @@
/**
* Do what needs to be done to shut down the CoRoutine management.
*/
- protected void clearCoRoutine(Exception ex)
+ protected void clearCoRoutine(SAXException ex)
{
+ if(null != ex)
+ m_transformer.setExceptionThrown(ex);
if(m_dtm instanceof SAX2DTM)
{
if(DEBUG)
- System.out.println("In clearCoRoutine...");
- SAX2DTM sax2dtm = ((SAX2DTM)m_dtm);
- if(null != m_contentHandler
- && m_contentHandler instanceof IncrementalSAXSource_Filter)
+ System.err.println("In clearCoRoutine...");
+ try
+ {
+ SAX2DTM sax2dtm = ((SAX2DTM)m_dtm);
+ if(null != m_contentHandler
+ && m_contentHandler instanceof IncrementalSAXSource_Filter)
+ {
+ IncrementalSAXSource_Filter sp =
+ (IncrementalSAXSource_Filter)m_contentHandler;
+ // This should now be all that's needed.
+ sp.deliverMoreNodes(false);
+ }
+
+ sax2dtm.clearCoRoutine(true);
+ m_contentHandler = null;
+ m_dtdHandler = null;
+ m_entityResolver = null;
+ m_errorHandler = null;
+ m_lexicalHandler = null;
+ }
+ catch(Throwable throwable)
{
- IncrementalSAXSource_Filter sp =
- (IncrementalSAXSource_Filter)m_contentHandler;
- // This should now be all that's needed.
- sp.deliverMoreNodes(false);
+ throwable.printStackTrace();
}
- sax2dtm.clearCoRoutine(true);
- m_contentHandler = null;
- m_dtdHandler = null;
- m_entityResolver = null;
- m_errorHandler = null;
- m_lexicalHandler = null;
-
if(DEBUG)
- System.out.println("...exiting clearCoRoutine");
+ System.err.println("...exiting clearCoRoutine");
}
}
@@ -716,13 +725,25 @@
*/
public void fatalError(SAXParseException e) throws SAXException
{
- clearCoRoutine(e);
+ if(null != m_errorHandler)
+ {
+ try
+ {
+ m_errorHandler.fatalError(e);
+ }
+ catch(SAXParseException se)
+ {
+ // ignore
+ }
+ // clearCoRoutine(e);
+ }
// This is not great, but we really would rather have the error
// handler be the error listener if it is a error handler. Coroutine's
fatalError
// can't really be configured, so I think this is the best thing right
now
// for error reporting. Possibly another JAXP 1.1 hole. -sb
javax.xml.transform.ErrorListener errorListener =
m_transformer.getErrorListener();
+
if(errorListener instanceof ErrorHandler)
{
((ErrorHandler)errorListener).fatalError(e);
1.112 +24 -2
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -r1.111 -r1.112
--- TransformerImpl.java 2001/08/04 18:23:30 1.111
+++ TransformerImpl.java 2001/08/06 22:17:17 1.112
@@ -1189,8 +1189,30 @@
}
catch (Exception e){}
}
-
- throw new TransformerException(se.getMessage(), se);
+
+ // SAXSourceLocator
+ while(se instanceof org.apache.xml.utils.WrappedRuntimeException)
+ {
+ Exception e =
((org.apache.xml.utils.WrappedRuntimeException)se).getException();
+ if(null != e)
+ se = e;
+ }
+
+ if(se instanceof TransformerException)
+ {
+ m_errorHandler.fatalError((TransformerException)se);
+ }
+ else if(se instanceof org.xml.sax.SAXParseException)
+ {
+ m_errorHandler.fatalError(new
TransformerException(se.getMessage(),
+ new
SAXSourceLocator((org.xml.sax.SAXParseException)se),
+ se));
+ }
+ else
+ {
+ m_errorHandler.fatalError(new TransformerException(se));
+ }
+
}
finally
{
1.41 +4 -0 xml-xalan/java/src/org/apache/xalan/xslt/Process.java
Index: Process.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xslt/Process.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- Process.java 2001/07/28 00:25:59 1.40
+++ Process.java 2001/08/06 22:17:17 1.41
@@ -91,6 +91,7 @@
import org.apache.xalan.trace.PrintTraceListener;
import org.apache.xalan.trace.TraceListener;
import org.apache.xalan.trace.TraceManager;
+import org.apache.xml.utils.DefaultErrorHandler;
// Needed TRaX classes
import javax.xml.transform.Result;
@@ -910,10 +911,13 @@
if (doStackDumpOnError)
throwable.printStackTrace(dumpWriter);
else
+ {
+ DefaultErrorHandler.printLocation(diagnosticsWriter, throwable);
diagnosticsWriter.println(
XSLMessages.createMessage(XSLTErrorResources.ER_XSLT_ERROR, null)
+ " (" + throwable.getClass().getName() + "): "
+ throwable.getMessage());
+ }
//
diagnosticsWriter.println(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUCCESSFUL,
null)); //"XSL Process was not successful.");
if (null != dumpFileName)
1.5 +11 -5
xml-xalan/java/src/org/apache/xml/dtm/ref/IncrementalSAXSource_Filter.java
Index: IncrementalSAXSource_Filter.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/IncrementalSAXSource_Filter.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- IncrementalSAXSource_Filter.java 2001/07/28 00:25:59 1.4
+++ IncrementalSAXSource_Filter.java 2001/08/06 22:17:17 1.5
@@ -233,7 +233,7 @@
// and resume our coroutine each time that counter hits zero and
// is reset.
//
- // Note that for everything except endDocument, we do the count-and-yield
+ // Note that for everything except endDocument and fatalError, we do the
count-and-yield
// BEFORE passing the call along. I'm hoping that this will encourage JIT
// compilers to realize that these are tail-calls, reducing the expense of
// the additional layer of data flow.
@@ -448,8 +448,14 @@
public void fatalError(SAXParseException exception) throws SAXException
{
+ // EXCEPTION: In this case we need to run the event BEFORE we yield --
+ // just as with endDocument, this terminates the event stream.
if(null!=clientErrorHandler)
clientErrorHandler.error(exception);
+
+ eventcounter=0;
+ co_yield(false);
+
}
public void warning(SAXParseException exception) throws SAXException
@@ -717,7 +723,7 @@
fCoroutineManager.co_resume(parsemore?Boolean.TRUE:Boolean.FALSE,
fControllerCoroutineID,
fSourceCoroutineID);
if(result==Boolean.FALSE)
- fCoroutineManager.co_exit(fControllerCoroutineID);
+ fCoroutineManager.co_exit(fControllerCoroutineID);
return result;
}
@@ -750,7 +756,7 @@
// The filter is not currently designed to be restartable
// after a parse has ended. Generate a new one each time.
IncrementalSAXSource_Filter filter=
- new IncrementalSAXSource_Filter();
+ new IncrementalSAXSource_Filter();
// Use a serializer as our sample output
org.apache.xml.serialize.XMLSerializer trace;
trace=new org.apache.xml.serialize.XMLSerializer(System.out,null);
@@ -759,11 +765,11 @@
try
{
- InputSource source = new InputSource(args[arg]);
+ InputSource source = new InputSource(args[arg]);
Object result=null;
boolean more=true;
- // init not issued; we _should_ automagically Do The Right Thing
+ // init not issued; we _should_ automagically Do The Right Thing
// Bind parser, kick off parsing in a thread
filter.setXMLReader(theSAXParser);
1.6 +99 -22
xml-xalan/java/src/org/apache/xml/utils/DefaultErrorHandler.java
Index: DefaultErrorHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/utils/DefaultErrorHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultErrorHandler.java 2001/06/27 03:03:48 1.5
+++ DefaultErrorHandler.java 2001/08/06 22:17:17 1.6
@@ -60,21 +60,43 @@
import javax.xml.transform.ErrorListener;
import javax.xml.transform.TransformerException;
import javax.xml.transform.SourceLocator;
+import java.io.PrintWriter;
+import java.io.PrintStream;
+
/**
* <meta name="usage" content="general"/>
* Implement SAX error handler for default reporting.
*/
public class DefaultErrorHandler implements ErrorHandler, ErrorListener
{
+ PrintWriter m_pw;
/**
* Constructor DefaultErrorHandler
*/
+ public DefaultErrorHandler(PrintWriter pw)
+ {
+ m_pw = pw;
+ }
+
+ /**
+ * Constructor DefaultErrorHandler
+ */
+ public DefaultErrorHandler(PrintStream pw)
+ {
+ m_pw = new PrintWriter(pw);
+ }
+
+ /**
+ * Constructor DefaultErrorHandler
+ */
public DefaultErrorHandler()
{
+ m_pw = new PrintWriter(System.err);
}
+
/**
* Receive notification of a warning.
*
@@ -93,8 +115,8 @@
*/
public void warning(SAXParseException exception) throws SAXException
{
- printLocation(exception);
- System.err.println("Parser warning: " + exception.getMessage());
+ printLocation(m_pw, exception);
+ m_pw.println("Parser warning: " + exception.getMessage());
}
/**
@@ -120,8 +142,8 @@
*/
public void error(SAXParseException exception) throws SAXException
{
- printLocation(exception);
- System.err.println(exception.getMessage());
+ // printLocation(exception);
+ // m_pw.println(exception.getMessage());
throw exception;
}
@@ -147,8 +169,8 @@
*/
public void fatalError(SAXParseException exception) throws SAXException
{
- printLocation(exception);
- System.err.println(exception.getMessage());
+ // printLocation(exception);
+ // m_pw.println(exception.getMessage());
throw exception;
}
@@ -172,9 +194,9 @@
*/
public void warning(TransformerException exception) throws
TransformerException
{
- printLocation(exception);
+ printLocation(m_pw, exception);
- System.err.println(exception.getMessage());
+ m_pw.println(exception.getMessage());
}
/**
@@ -201,7 +223,8 @@
*/
public void error(TransformerException exception) throws
TransformerException
{
- printLocation(exception);
+ // printLocation(exception);
+ // ensureLocationSet(exception);
throw exception;
}
@@ -228,36 +251,90 @@
*/
public void fatalError(TransformerException exception) throws
TransformerException
{
- printLocation(exception);
+ // printLocation(exception);
+ // ensureLocationSet(exception);
throw exception;
}
- private void printLocation(org.xml.sax.SAXParseException exception)
+ public static void ensureLocationSet(TransformerException exception)
{
- // System.err.println("Parser fatal error: "+exception.getMessage());
- String id = (null != exception.getSystemId())
- ? exception.getSystemId() : "SystemId Unknown";
-
- System.err.print(id + "; Line " + exception.getLineNumber()
- + "; Column " + exception.getColumnNumber()+"; ");
+ // SourceLocator locator = exception.getLocator();
+ SourceLocator locator = null;
+ Throwable cause = exception;
+
+ // Try to find the locator closest to the cause.
+ do
+ {
+ if(cause instanceof SAXParseException)
+ {
+ locator = new SAXSourceLocator((SAXParseException)cause);
+ }
+ else if (cause instanceof TransformerException)
+ {
+ SourceLocator causeLocator =
((TransformerException)cause).getLocator();
+ if(null != causeLocator)
+ locator = causeLocator;
+ }
+
+ if(cause instanceof TransformerException)
+ cause = ((TransformerException)cause).getCause();
+ else if(cause instanceof SAXException)
+ cause = ((SAXException)cause).getException();
+ else
+ cause = null;
+ }
+ while(null != cause);
+
+ exception.setLocator(locator);
}
-
+
+ public static void printLocation(PrintStream pw, TransformerException
exception)
+ {
+ printLocation(new PrintWriter(pw), exception);
+ }
- private void printLocation(TransformerException exception)
+ public static void printLocation(PrintWriter pw, Throwable exception)
{
- SourceLocator locator = exception.getLocator();
+ SourceLocator locator = null;
+ Throwable cause = exception;
+ // Try to find the locator closest to the cause.
+ do
+ {
+ if(cause instanceof SAXParseException)
+ {
+ locator = new SAXSourceLocator((SAXParseException)cause);
+ }
+ else if (cause instanceof TransformerException)
+ {
+ SourceLocator causeLocator =
((TransformerException)cause).getLocator();
+ if(null != causeLocator)
+ locator = causeLocator;
+ }
+ if(cause instanceof TransformerException)
+ cause = ((TransformerException)cause).getCause();
+ else if(cause instanceof WrappedRuntimeException)
+ cause = ((WrappedRuntimeException)cause).getException();
+ else if(cause instanceof SAXException)
+ cause = ((SAXException)cause).getException();
+ else
+ cause = null;
+ }
+ while(null != cause);
+
if(null != locator)
{
- // System.err.println("Parser fatal error: "+exception.getMessage());
+ // m_pw.println("Parser fatal error: "+exception.getMessage());
String id = (locator.getPublicId() != locator.getPublicId())
? locator.getPublicId()
: (null != locator.getSystemId())
? locator.getSystemId() : "SystemId Unknown";
- System.err.print(id + "; Line " + locator.getLineNumber()
+ pw.print(id + "; Line " + locator.getLineNumber()
+ "; Column " + locator.getColumnNumber()+"; ");
}
+ else
+ pw.print("(Location of error unknown)");
}
}
1.15 +8 -2
xml-xalan/java/src/org/apache/xpath/operations/Variable.java
Index: Variable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/operations/Variable.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Variable.java 2001/07/28 00:45:05 1.14
+++ Variable.java 2001/08/06 22:17:17 1.15
@@ -56,6 +56,8 @@
*/
package org.apache.xpath.operations;
+import javax.xml.transform.TransformerException;
+
import org.apache.xml.utils.QName;
import org.apache.xpath.Expression;
import org.apache.xpath.XPath;
@@ -124,8 +126,12 @@
return;
}
}
- throw new
RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_COULD_NOT_FIND_VAR,
new Object[]{m_qname.toString()})); //"Could not find variable with the name
of "
- // +m_qname.toString()+"!");
+ java.lang.String msg =
XSLMessages.createXPATHMessage(XPATHErrorResources.ER_COULD_NOT_FIND_VAR,
+ new
Object[]{m_qname.toString()});
+
+ TransformerException te = new TransformerException(msg, m_slocator);
+
+ throw new org.apache.xml.utils.WrappedRuntimeException(te);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]