]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Reconfigured ElementMapping from an interface to an abstract base class
authorGlen Mazza <gmazza@apache.org>
Sat, 12 Jul 2003 21:22:04 +0000 (21:22 +0000)
committerGlen Mazza <gmazza@apache.org>
Sat, 12 Jul 2003 21:22:04 +0000 (21:22 +0000)
Removed FOTreeBuilder references from all ElementMapping subclasses
Simplified FOTreeBuilder ElementMapping instantiation somewhat

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196687 13f79535-47bb-0310-9956-ffa450edef68

examples/mathml/src/org/apache/fop/mathml/MathMLElementMapping.java
examples/plan/src/org/apache/fop/plan/PlanElementMapping.java
src/java/org/apache/fop/extensions/ExtensionElementMapping.java
src/java/org/apache/fop/fo/ElementMapping.java
src/java/org/apache/fop/fo/FOElementMapping.java
src/java/org/apache/fop/fo/FOTreeBuilder.java
src/java/org/apache/fop/svg/SVGElementMapping.java

index c80a0c33c273f49496568150a2cb4cb36b1bf66c..9c48520ebfb36b2bb431a2d4e2e37078eebd84a0 100644 (file)
@@ -50,7 +50,6 @@
  */ 
 package org.apache.fop.mathml;
 
-import org.apache.fop.fo.FOTreeBuilder;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.image.analyser.XMLReader;
@@ -65,14 +64,13 @@ import net.sourceforge.jeuclid.DOMMathBuilder;
 /**
  * This class provides the element mapping for FOP.
  */
-public class MathMLElementMapping implements ElementMapping {
+public class MathMLElementMapping extends ElementMapping {
 
-    /** MathML namespace */
-    public static final String URI = "http://www.w3.org/1998/Math/MathML";
-
-    private static HashMap foObjs = null;
+    public MathMLElementMapping() {
+        URI = "http://www.w3.org/1998/Math/MathML";
+    }
 
-    private static synchronized void setupMathML() {
+    protected void initialize() {
         if (foObjs == null) {
             foObjs = new HashMap();
             foObjs.put("math", new ME());
@@ -82,14 +80,6 @@ public class MathMLElementMapping implements ElementMapping {
         }
     }
 
-    /**
-     * @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder)
-     */
-    public void addToBuilder(FOTreeBuilder builder) {
-        setupMathML();
-        builder.addMapping(URI, foObjs);
-    }
-
     static class MathMLMaker extends ElementMapping.Maker {
         public FONode make(FONode parent) {
             return new MathMLObj(parent);
index 7a1fecb19c56dc6855045a8d364a651689c58dba..724871eddc300adb2ef174815888b5af5c9d09da 100644 (file)
@@ -50,7 +50,6 @@
  */ 
 package org.apache.fop.plan;
 
-import org.apache.fop.fo.FOTreeBuilder;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.image.analyser.XMLReader;
@@ -62,14 +61,13 @@ import java.util.HashMap;
 /**
  * This class provides the element mapping for FOP.
  */
-public class PlanElementMapping implements ElementMapping {
+public class PlanElementMapping extends ElementMapping {
 
-    /** The namespace for the plan extension */
-    public static final String URI = "http://xml.apache.org/fop/plan";
-
-    private static HashMap foObjs = null;
+    public PlanElementMapping() {
+        URI = "http://xml.apache.org/fop/plan";
+    }
 
-    private static synchronized void setupPlan() {
+    protected void initialize() {
         if (foObjs == null) {
             foObjs = new java.util.HashMap();
             foObjs.put("plan", new PE());
@@ -79,14 +77,6 @@ public class PlanElementMapping implements ElementMapping {
         }
     }
 
-    /**
-     * @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder)
-     */
-    public void addToBuilder(FOTreeBuilder builder) {
-        setupPlan();
-        builder.addMapping(URI, foObjs);
-    }
-
     static class PlanMaker extends ElementMapping.Maker {
         public FONode make(FONode parent) {
             return new PlanObj(parent);
index 283bc6e68caf552a6ad9f13622e7427afb2be169..b95a54ba75e46d2ac2934eda6d71a31698d31374 100644 (file)
@@ -52,7 +52,6 @@ package org.apache.fop.extensions;
 
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.ElementMapping;
-import org.apache.fop.fo.FOTreeBuilder;
 
 import java.util.HashMap;
 
@@ -61,16 +60,13 @@ import java.util.HashMap;
  * This sets up the mapping for the classes that handle the
  * pdf bookmark extension.
  */
-public class ExtensionElementMapping implements ElementMapping {
-    /**
-     * The pdf bookmark extension uri
-     */
-    public static final String URI = "http://xml.apache.org/fop/extensions";
+public class ExtensionElementMapping extends ElementMapping {
 
-    // the mappings are only setup once and resued after that
-    private static HashMap foObjs = null;
+    public ExtensionElementMapping() {
+        URI = "http://xml.apache.org/fop/extensions";
+    }
 
-    private static synchronized void setupExt() {
+    protected void initialize() {
         if (foObjs == null) {
             foObjs = new HashMap();
             foObjs.put("bookmarks", new B());
@@ -79,18 +75,6 @@ public class ExtensionElementMapping implements ElementMapping {
         }
     }
 
-    /**
-     * Add the mappings to the fo tree builder.
-     *
-     * @param builder the fo tree builder to add the mappings
-     */
-    public void addToBuilder(FOTreeBuilder builder) {
-        if (foObjs == null) {
-            setupExt();
-        }
-        builder.addMapping(URI, foObjs);
-    }
-
     static class B extends ElementMapping.Maker {
         public FONode make(FONode parent) {
             return new Bookmarks(parent);
index 331ca2a85d03e7721264a3bd2b7136057993cb8c..c8118771988c3d6456e01a5ccab2654398c10bad 100644 (file)
  */ 
 package org.apache.fop.fo;
 
+import java.util.HashMap;
+
 /**
  * Interface for adding supported element and property mappings to
  * the given builder.
  */
-public interface ElementMapping {
-    final String DEFAULT = "<default>";
+/** Abstract base class of FO Element Mappings.  */
+public abstract class ElementMapping {
+    public static final String DEFAULT = "<default>";
+
+    /** The HashMap table of formatting objects defined by the ElementMapping */
+    protected HashMap foObjs = null;
+
+    /** The namespace for the ElementMapping */
+    protected String URI = null;
+
+    /**
+     * Returns a HashMap of maker objects for this element mapping
+     *
+     * @return Table of Maker objects for this ElementMapping
+     */
+    public HashMap getTable() {
+        if (foObjs == null) {
+            initialize();
+        }
+        return foObjs;
+    }
+
+    /**
+     * Returns the namespace URI for this element mapping
+     *
+     * @return Namespace URI for this element mapping
+    */
+    public String getNamespaceURI() {
+        return URI;
+    }
 
-    void addToBuilder(FOTreeBuilder builder);
+    /**
+     * Initializes the set of maker objects associated with this ElementMapping
+     *
+    */
+    protected abstract void initialize();
 
     public static class Maker {
         public FONode make(FONode parent) {
index f9db7f51cad0ba73cdcb6e903c57a818acfa07bd..4dce2889af1983c5acb43a81b2c25bb3c34f8c91 100644 (file)
@@ -56,11 +56,13 @@ import java.util.HashMap;
 /**
  * Element mapping class for all XSL-FO elements.
  */
-public class FOElementMapping implements ElementMapping {
+public class FOElementMapping extends ElementMapping {
     
-    private static HashMap foObjs = null;
+    public FOElementMapping() {
+        URI = "http://www.w3.org/1999/XSL/Format";
+    }
 
-    private static synchronized void setupFO() {
+    protected void initialize() {
         if (foObjs == null) {
             foObjs = new HashMap();
 
@@ -148,16 +150,6 @@ public class FOElementMapping implements ElementMapping {
             foObjs.put("marker", new M());
             foObjs.put("retrieve-marker", new RM());
         }
-
-    }
-
-    /**
-     * @see org.apache.fop.fo.ElementMapping#addToBuilder(FOTreeBuilder)
-     */
-    public void addToBuilder(FOTreeBuilder builder) {
-        setupFO();
-        String uri = "http://www.w3.org/1999/XSL/Format";
-        builder.addMapping(uri, foObjs);
     }
 
     static class R extends ElementMapping.Maker {
index 78a5a99735ce0ab05f2bfa5c17efa5c75e9ad0fa..546efe0ad0c5048eb13d16aeda629afa19a64a15 100644 (file)
@@ -171,17 +171,6 @@ public class FOTreeBuilder extends DefaultHandler {
         }
     }
 
-    /**
-     * Adds a mapping from a namespace to a table of makers.
-     *
-     * @param namespaceURI namespace URI of formatting object elements
-     * @param table table of makers
-     */
-    public void addMapping(String namespaceURI, HashMap table) {
-        this.fobjTable.put(namespaceURI, table);
-        this.namespaces.add(namespaceURI.intern());
-    }
-
     /**
      * Add the given element mapping.
      * An element mapping maps element names to Java classes.
@@ -189,7 +178,8 @@ public class FOTreeBuilder extends DefaultHandler {
      * @param mapping the element mappingto add
      */
     public void addElementMapping(ElementMapping mapping) {
-        mapping.addToBuilder(this);
+        this.fobjTable.put(mapping.getNamespaceURI(), mapping.getTable());
+        this.namespaces.add(mapping.getNamespaceURI().intern());
     }
 
     /**
index dd6296cd55767cb241868a33448ec9a5458d67eb..36135c17def733ad3134fae9ee8ebdead40d163d 100644 (file)
@@ -53,7 +53,6 @@ package org.apache.fop.svg;
 import java.util.HashMap;
 
 import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.FOTreeBuilder;
 import org.apache.fop.fo.ElementMapping;
 import org.apache.fop.apps.Driver;
 
@@ -65,34 +64,25 @@ import org.apache.batik.dom.svg.SVGDOMImplementation;
  * This adds the svg element mappings used to create the objects
  * that create the SVG Document.
  */
-public class SVGElementMapping implements ElementMapping {
-    private static HashMap foObjs = null;
-    private static boolean batik = true;
+public class SVGElementMapping extends ElementMapping {
+    private boolean batik = true;
 
-    private static synchronized void setupSVG() {
-        if (foObjs == null) {
+    public SVGElementMapping() {
+        URI = SVGDOMImplementation.SVG_NAMESPACE_URI;
+    }
+
+    protected void initialize() {
+        if (foObjs == null && batik == true) {
             // this sets the parser that will be used
             // by default (SVGBrokenLinkProvider)
             // normally the user agent value is used
-            XMLResourceDescriptor.setXMLParserClassName(
-              Driver.getParserClassName());
-
-            foObjs = new HashMap();
-            foObjs.put("svg", new SE());
-            foObjs.put(DEFAULT, new SVGMaker());
-        }
-    }
-
-    /**
-     * Add the SVG element mappings to the tree builder.
-     * @param builder the FOTreeBuilder to add the mappings to
-     */
-    public void addToBuilder(FOTreeBuilder builder) {
-        if (batik) {
             try {
-                setupSVG();
-                String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
-                builder.addMapping(svgNS, foObjs);
+                XMLResourceDescriptor.setXMLParserClassName(
+                  Driver.getParserClassName());
+    
+                foObjs = new HashMap();
+                foObjs.put("svg", new SE());
+                foObjs.put(DEFAULT, new SVGMaker());
             } catch (Throwable t) {
                 // if the classes are not available
                 // the DISPLAY is not checked