From: Jeremias Maerki Date: Mon, 2 Jun 2003 22:17:36 +0000 (+0000) Subject: Make more dummy-safe (more verbose error messages). X-Git-Tag: Root_Temp_KnuthStylePageBreaking~1423 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2eb4fd9965676e93be6d243a4c02c9ed5af33d39;p=xmlgraphics-fop.git Make more dummy-safe (more verbose error messages). Reintroduce setLogger() method from maint-branch (deprecated, for backwards-compatibility) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196489 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index ce278228d..7f97f0d97 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -261,11 +261,17 @@ public class Driver implements LogEnabled { this.stream = stream; } + private boolean isInitialized() { + return (treeBuilder != null); + } + /** * Initializes the Driver object. */ public void initialize() { - stream = null; + if (isInitialized()) { + throw new IllegalStateException("Driver already initialized"); + } treeBuilder = new FOTreeBuilder(); treeBuilder.setUserAgent(getUserAgent()); setupDefaultMappings(); @@ -305,6 +311,15 @@ public class Driver implements LogEnabled { } } + /** + * Provide the Driver instance with a logger. + * @param log the logger. Must not be null. + * @deprecated Use #enableLogging(Logger) instead. + */ + public void setLogger(Logger log) { + enableLogging(log); + } + /** * Returns the logger for use by FOP. @@ -349,6 +364,12 @@ public class Driver implements LogEnabled { this.stream = stream; } + private void validateOutputStream() { + if (this.stream == null) { + throw new IllegalStateException("OutputStream has not been set"); + } + } + /** * Set the source for the FO document. This can be a normal SAX * InputSource, or an DocumentInputSource containing a DOM document. @@ -553,10 +574,10 @@ public class Driver implements LogEnabled { * @return a content handler for handling the SAX events. */ public ContentHandler getContentHandler() { - if (treeBuilder == null) { - throw new NullPointerException("Driver isn't initialized. " - + "You may have to call initialize() first."); + if (!isInitialized()) { + initialize(); } + validateOutputStream(); // TODO: - do this stuff in a better way // PIJ: I guess the structure handler should be created by the renderer. @@ -588,6 +609,9 @@ public class Driver implements LogEnabled { */ public synchronized void render(XMLReader parser, InputSource source) throws FOPException { + if (!isInitialized()) { + initialize(); + } parser.setContentHandler(getContentHandler()); try { parser.parse(source); @@ -610,6 +634,9 @@ public class Driver implements LogEnabled { */ public synchronized void render(Document document) throws FOPException { + if (!isInitialized()) { + initialize(); + } try { DocumentInputSource source = new DocumentInputSource(document); DocumentReader reader = new DocumentReader(); @@ -638,6 +665,9 @@ public class Driver implements LogEnabled { * @throws FOPException if anything else goes wrong. */ public synchronized void run() throws IOException, FOPException { + if (!isInitialized()) { + initialize(); + } if (renderer == null) { setRenderer(RENDER_PDF); }