Download Java And XSLT

Transcript
JUnit also has a Swing GUI client that can be executed with the following command:
java junit.swingui.TestRunner chap9.SampleUnitTest
Figure 9-4 shows the graphical output when errors occur.
Figure 9-4. JUnit output with errors
The rectangular area to the left of "U" is a progress bar that expands as tests are executed. When
dozens or hundreds of tests are executed, the progress bar gives a good visual indication of how
many tests have executed. It also changes from green to red when errors or failures occur, so
programmers know exactly when something went wrong. The scrolling list in the middle of the
screen shows individual test errors and failures, and the text area near the bottom of the screen
shows details for the selected error.
The GUI interface is great for interactive testing, while the command-line interface is more
appropriate for batch-mode, automated tests. These are the sorts of tests that execute as part of
a nightly build process. We now move past unit testing software into the realm of custom
application error handling using JAXP error listeners.
9.2.2 JAXP 1.1 Error Listeners
When performing XSLT transformations using JAXP, errors are typically reported to
System.err. While this is sufficient for command-line transformations, some custom
applications require more control over the error-reporting process. For this class of applications,
the javax.xml.transform.ErrorListener interface is provided.
By implementing this interface, an application can capture and report detailed information about
where transformation errors occur and why. In Example 9-9, a custom Swing table model is
presented. This class implements the javax.xml.transform.ErrorListener interface and
is used by a JTable to display errors graphically. Later, in Example 9-11, we show how to
register this error listener with a TransformerFactory and Transformer.
Example 9-9. ErrorListenerModel
package com.oreilly.javaxslt.swingtrans;
import java.io.*;