From 951ce154766871a9a2d9c0d5941c9a6dfe5d9250 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 27 Jan 2006 15:34:10 +0000 Subject: [PATCH] Added safe-guard against reuse to avoid problems with the renderers. Removed reset() method. Compared to the many hundred object instances that get created by the FO tree and layout engine, the Fop and FOTreeBuilder instance are negligible. Better keep the API as simple as possible and create an environmental class in the long run. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@372880 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FOTreeBuilder.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index c0aa87a44..f674d58c8 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -48,6 +48,8 @@ public class FOTreeBuilder extends DefaultHandler { /** The registry for ElementMapping instances */ protected ElementMappingRegistry elementMappingRegistry; + //TODO Remove the ElementMappingRegistry from here and move it to a new environmental class + //FOTreeBuilder should be a "one-use" component. /** * The root of the formatting object tree @@ -76,6 +78,8 @@ public class FOTreeBuilder extends DefaultHandler { /** The user agent for this processing run. */ private FOUserAgent userAgent; + private boolean used = false; + /** * FOTreeBuilder constructor * @param outputFormat the MIME type of the output format to use (ex. "application/pdf"). @@ -143,6 +147,11 @@ public class FOTreeBuilder extends DefaultHandler { * @see org.xml.sax.ContentHandler#startDocument() */ public void startDocument() throws SAXException { + if (used) { + throw new IllegalStateException("FOTreeBuilder (and the Fop class) cannot be reused." + + " Please instantiate a new instance."); + } + used = true; rootFObj = null; // allows FOTreeBuilder to be reused if (log.isDebugEnabled()) { log.debug("Building formatting object tree"); @@ -300,14 +309,5 @@ public class FOTreeBuilder extends DefaultHandler { } } - /** - * Resets this object for another run. - */ - public void reset() { - currentFObj = null; - rootFObj = null; - foEventHandler = null; - } - } -- 2.39.5