jeremias 2003/06/02 15:17:36 Modified: src/java/org/apache/fop/apps Driver.java Log: Make more dummy-safe (more verbose error messages). Reintroduce setLogger() method from maint-branch (deprecated, for backwards-compatibility) Revision Changes Path 1.4 +34 -4 xml-fop/src/java/org/apache/fop/apps/Driver.java Index: Driver.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Driver.java 12 Mar 2003 11:00:21 -0000 1.3 +++ Driver.java 2 Jun 2003 22:17:36 -0000 1.4 @@ -261,11 +261,17 @@ 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 @@ } } + /** + * Provide the Driver instance with a logger. + * @param log the logger. Must not be <code>null</code>. + * @deprecated Use #enableLogging(Logger) instead. + */ + public void setLogger(Logger log) { + enableLogging(log); + } + /** * Returns the logger for use by FOP. @@ -349,6 +364,12 @@ 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 @@ * @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 synchronized void render(XMLReader parser, InputSource source) throws FOPException { + if (!isInitialized()) { + initialize(); + } parser.setContentHandler(getContentHandler()); try { parser.parse(source); @@ -610,6 +634,9 @@ */ 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 @@ * @throws FOPException if anything else goes wrong. */ public synchronized void run() throws IOException, FOPException { + if (!isInitialized()) { + initialize(); + } if (renderer == null) { setRenderer(RENDER_PDF); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]