You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2002/02/12 16:14:37 UTC
cvs commit: xml-batik/sources/org/apache/batik/script InterpreterPool.java
tkormann 02/02/12 07:14:37
Modified: sources/org/apache/batik/bridge
AbstractGraphicsNodeBridge.java
AbstractSVGBridge.java Bridge.java
BridgeContext.java BridgeEventSupport.java
GVTBuilder.java SVGBridgeExtension.java
SVGCircleElementBridge.java
SVGEllipseElementBridge.java
SVGLineElementBridge.java SVGPathElementBridge.java
SVGPolygonElementBridge.java
SVGPolylineElementBridge.java
SVGRectElementBridge.java
SVGShapeElementBridge.java
ScriptingEnvironment.java
sources/org/apache/batik/script InterpreterPool.java
Removed: sources/org/apache/batik/bridge DynamicBridge.java
Log:
- clean BridgeContext
- changing transform attribute should work
- all basic shapes and path element geometry should be animated
- change a bit InterpreterPool behavior to fit our needs
tests will come soon
Revision Changes Path
1.9 +69 -3 xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java
Index: AbstractGraphicsNodeBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- AbstractGraphicsNodeBridge.java 11 Feb 2002 16:00:07 -0000 1.8
+++ AbstractGraphicsNodeBridge.java 12 Feb 2002 15:14:37 -0000 1.9
@@ -15,6 +15,10 @@
import org.apache.batik.parser.ParseException;
import org.w3c.dom.Element;
+import org.w3c.dom.events.Event;
+import org.w3c.dom.events.EventListener;
+import org.w3c.dom.events.EventTarget;
+import org.w3c.dom.events.MutationEvent;
/**
* The base bridge class for SVG graphics node. By default, the namespace URI is
@@ -35,12 +39,27 @@
* </ul>
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: AbstractGraphicsNodeBridge.java,v 1.8 2002/02/11 16:00:07 tkormann Exp $
+ * @version $Id: AbstractGraphicsNodeBridge.java,v 1.9 2002/02/12 15:14:37 tkormann Exp $
*/
public abstract class AbstractGraphicsNodeBridge extends AbstractSVGBridge
implements GraphicsNodeBridge, ErrorConstants {
/**
+ * The element that has been handled by this bridge.
+ */
+ protected Element e;
+
+ /**
+ * The graphics node constructed by this bridge.
+ */
+ protected GraphicsNode node;
+
+ /**
+ * The bridge context to use for dynamic updates.
+ */
+ protected BridgeContext ctx;
+
+ /**
* Constructs a new abstract bridge.
*/
protected AbstractGraphicsNodeBridge() {}
@@ -100,6 +119,12 @@
// bind the specified element and its associated graphics node if needed
if (ctx.isDynamic()) {
+ ((EventTarget)e).addEventListener("DOMAttrModified",
+ new DOMAttrModifiedEventListener(),
+ false);
+ this.e = e;
+ this.node = node;
+ this.ctx = ctx;
ctx.bind(e, node);
BridgeEventSupport.addDOMListener(ctx, e);
}
@@ -107,7 +132,48 @@
SVGUtilities.bridgeChildren(ctx, e);
}
- public Bridge getInstance(){
- return this;
+ // dynamic support
+
+ /**
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
+ */
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_TRANSFORM_ATTRIBUTE)) {
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+
+ String s = evt.getNewValue();
+ AffineTransform at = GraphicsNode.IDENTITY;
+ if (s.length() != 0) {
+ at = SVGUtilities.convertTransform
+ (e, SVG_TRANSFORM_ATTRIBUTE, s);
+ }
+ node.setTransform(at);
+
+ fireBridgeUpdateCompleted(be);
+ }
+ }
+
+
+ /**
+ * The listener class for 'DOMAttrModified' event.
+ */
+ protected class DOMAttrModifiedEventListener implements EventListener {
+
+ /**
+ * Handles 'DOMAttrModfied' events and deleguates to the
+ * 'handleDOMAttrModifiedEvent' method any changes to the
+ * GraphicsNode if any.
+ *
+ * @param evt the DOM event
+ */
+ public void handleEvent(Event evt) {
+ if (evt.getTarget() != e) {
+ throw new Error("handleEvent bad target");
+ }
+ handleDOMAttrModifiedEvent((MutationEvent)evt);
+ }
}
}
1.2 +68 -1 xml-batik/sources/org/apache/batik/bridge/AbstractSVGBridge.java
Index: AbstractSVGBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractSVGBridge.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractSVGBridge.java 2 May 2001 14:33:32 -0000 1.1
+++ AbstractSVGBridge.java 12 Feb 2002 15:14:37 -0000 1.2
@@ -14,11 +14,22 @@
* The base bridge class for SVG elements.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: AbstractSVGBridge.java,v 1.1 2001/05/02 14:33:32 tkormann Exp $
+ * @version $Id: AbstractSVGBridge.java,v 1.2 2002/02/12 15:14:37 tkormann Exp $
*/
public abstract class AbstractSVGBridge implements Bridge, SVGConstants {
/**
+ * The update handler to notify each time the GVT product
+ * associated to this bridge changes.
+ */
+ protected BridgeUpdateHandler handler;
+
+ /**
+ * The private key of the update handler.
+ */
+ protected int handlerKey;
+
+ /**
* Constructs a new abstract bridge for SVG elements.
*/
protected AbstractSVGBridge() {}
@@ -28,5 +39,61 @@
*/
public String getNamespaceURI() {
return SVG_NAMESPACE_URI;
+ }
+
+ /**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ // <!> FIXME: temporary fix for progressive implementation
+ //System.out.println("use static bridge for: "+getLocalName());
+ return this;
+ }
+
+ /**
+ * Returns the handler that is called each time this bridge
+ * updates its GVT product.
+ */
+ public BridgeUpdateHandler getBridgeUpdateHandler() {
+ return handler;
+ }
+
+ /**
+ * Sets the handler that is used to track each update of this
+ * bridge's GVT product.
+ *
+ * @param handler the handler to call
+ * @param handlerKey a private key the handler might use when it registers
+ */
+ public void setBridgeUpdateHandler(BridgeUpdateHandler handler,
+ int handlerKey) {
+ this.handler = handler;
+ this.handlerKey = handlerKey;
+ }
+
+ /**
+ * Notifies the BridgeUpdateHandler using the specified event that
+ * an update is starting.
+ *
+ * @param evt the BridgeUpdateHandler event
+ */
+ protected void fireBridgeUpdateStarting(BridgeUpdateEvent evt) {
+ if (handler != null) {
+ evt.setHandlerKey(handlerKey);
+ handler.bridgeUpdateStarting(evt);
+ }
+ }
+
+ /**
+ * Notifies the BridgeUpdateHandler using the specified event that
+ * an update is complete.
+ *
+ * @param evt the BridgeUpdateHandler event
+ */
+ protected void fireBridgeUpdateCompleted(BridgeUpdateEvent evt) {
+ if (handler != null) {
+ evt.setHandlerKey(handlerKey);
+ handler.bridgeUpdateCompleted(evt);
+ }
}
}
1.5 +23 -2 xml-batik/sources/org/apache/batik/bridge/Bridge.java
Index: Bridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/Bridge.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Bridge.java 2 May 2001 14:33:33 -0000 1.4
+++ Bridge.java 12 Feb 2002 15:14:37 -0000 1.5
@@ -10,10 +10,11 @@
/**
* A tagging interface that all bridges must implement. A bridge is
- * responsible on creating an appropriate object according to an Element.
+ * responsible on creating and maintaining an appropriate object
+ * according to an Element.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: Bridge.java,v 1.4 2001/05/02 14:33:33 tkormann Exp $
+ * @version $Id: Bridge.java,v 1.5 2002/02/12 15:14:37 tkormann Exp $
*/
public interface Bridge {
@@ -28,5 +29,25 @@
* to.
*/
String getLocalName();
+
+ /**
+ * Returns a new instance of this bridge.
+ */
+ Bridge getInstance();
+
+ /**
+ * Returns the handler that is called each time this bridge
+ * updates its GVT product.
+ */
+ BridgeUpdateHandler getBridgeUpdateHandler();
+
+ /**
+ * Sets the handler that is used to track each update of this
+ * bridge's GVT product.
+ *
+ * @param handler the handler to call
+ * @param handlerKey a private key the handler might use when it registers
+ */
+ void setBridgeUpdateHandler(BridgeUpdateHandler handler, int handlerKey);
}
1.32 +85 -151 xml-batik/sources/org/apache/batik/bridge/BridgeContext.java
Index: BridgeContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- BridgeContext.java 21 Dec 2001 14:40:31 -0000 1.31
+++ BridgeContext.java 12 Feb 2002 15:14:37 -0000 1.32
@@ -24,10 +24,12 @@
import org.apache.batik.css.HiddenChildElementSupport;
import org.apache.batik.gvt.GraphicsNode;
import org.apache.batik.gvt.TextPainter;
+import org.apache.batik.script.Interpreter;
import org.apache.batik.script.InterpreterPool;
import org.apache.batik.util.Service;
import org.apache.batik.util.SVGConstants;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;
@@ -45,16 +47,28 @@
* a SVG DOM tree such as the current viewport or the user agent.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: BridgeContext.java,v 1.31 2001/12/21 14:40:31 hillion Exp $
+ * @version $Id: BridgeContext.java,v 1.32 2002/02/12 15:14:37 tkormann Exp $
*/
public class BridgeContext implements ErrorConstants {
/**
+ * The document is bridge context is dedicated to.
+ */
+ protected Document document;
+
+ /**
* The GVT builder that might be used to create a GVT subtree.
*/
protected GVTBuilder gvtBuilder;
/**
+ * The interpreter cache per document.
+ * key is the language -
+ * value is a Interpreter
+ */
+ protected Map interpreterMap = new HashMap(7);
+
+ /**
* The viewports.
* key is an Element -
* value is a Viewport
@@ -86,20 +100,6 @@
protected HashMap nodeElementMap;
/**
- * Binding Map:
- * key is style Element -
- * value is a list of styleReference
- */
- protected HashMap elementStyleAttMap;
-
- /**
- * Binding Map:
- * key is GraphicsNode -
- * value is list of StyleElement.
- */
- protected HashMap nodeStyleMap;
-
- /**
* Bridge Map:
* Keys are namespace URI - values are HashMap (with keys are local
* name and values are a Bridge instance).
@@ -183,9 +183,7 @@
registerSVGBridges(this);
}
- /////////////////////////////////////////////////////////////////////////
// properties
- /////////////////////////////////////////////////////////////////////////
/**
* Sets the text painter that will be used by text nodes. This attributes
@@ -199,6 +197,13 @@
}
/**
+ * Returns the document this bridge context is dedicated to.
+ */
+ public Document getDocument() {
+ return document;
+ }
+
+ /**
* Returns the text painter that will be used be text nodes.
*/
public TextPainter getTextPainter() {
@@ -213,6 +218,15 @@
}
/**
+ * Sets the document this bridge context is dedicated to, to the
+ * specified document.
+ * @param document the document
+ */
+ protected void setDocument(Document document) {
+ this.document = document;
+ }
+
+ /**
* Sets the user agent to the specified user agent.
* @param userAgent the user agent
*/
@@ -242,6 +256,23 @@
}
/**
+ * Returns a Interpreter for the specified language.
+ *
+ * @param language the scripting language
+ */
+ public Interpreter getInterpreter(String language) {
+ if (document == null) {
+ throw new RuntimeException("Unknown document");
+ }
+ Interpreter interpreter = (Interpreter)interpreterMap.get(language);
+ if (interpreter == null) {
+ interpreter = interpreterPool.createInterpreter(document, language);
+ interpreterMap.put(language, interpreter);
+ }
+ return interpreter;
+ }
+
+ /**
* Sets the interpreter pool used to handle scripts to the
* specified interpreter pool.
* @param interpreterPool the interpreter pool
@@ -265,9 +296,7 @@
this.documentLoader = newDocumentLoader;
}
- /////////////////////////////////////////////////////////////////////////
// convenient methods
- /////////////////////////////////////////////////////////////////////////
/**
* Returns the element referenced by the specified element by the
@@ -301,9 +330,7 @@
}
}
- /////////////////////////////////////////////////////////////////////////
// methods to access to the current state of the bridge context
- /////////////////////////////////////////////////////////////////////////
/**
* Returns the actual size of the document or null if the document
@@ -327,12 +354,9 @@
* @param e the element interested in its viewport
*/
public Viewport getViewport(Element e) {
- if (viewportStack != null) { // building time
- if (viewportStack.size() > 0) {
- return (Viewport)viewportStack.get(0);
- } else {
- return (Viewport)viewportMap.get(userAgent);
- }
+ if (viewportStack != null) {
+ // building time
+ return (Viewport)viewportStack.get(0);
} else {
// search the first parent which has defined a viewport
e = HiddenChildElementSupport.getParentElement(e);
@@ -354,6 +378,9 @@
*/
public void openViewport(Element e, Viewport viewport) {
viewportMap.put(e, viewport);
+ if (viewportStack == null) {
+ viewportStack = new LinkedList();
+ }
viewportStack.add(0, viewport);
}
@@ -364,6 +391,9 @@
public void closeViewport(Element e) {
viewportMap.remove(e);
viewportStack.remove(0);
+ if (viewportStack.size() == 0) {
+ viewportStack = null;
+ }
}
/**
@@ -395,9 +425,7 @@
updateManager = um;
}
- /////////////////////////////////////////////////////////////////////////
// binding methods
- /////////////////////////////////////////////////////////////////////////
/**
* Binds the specified GraphicsNode to the specified Element. This method
@@ -416,11 +444,7 @@
}
/**
- * Removes the binding of the specified Element. This method
- * unbinds the specified element to its associated graphics node,
- * remove the binding from the graphics node to the specified
- * element, and all the style references associated to the
- * specified element are also removed.
+ * Removes the binding of the specified Element.
* @param element the element to unbind
*/
public void unbind(Element element) {
@@ -430,13 +454,12 @@
GraphicsNode node = (GraphicsNode)elementNodeMap.get(element);
elementNodeMap.remove(element);
nodeElementMap.remove(node);
- // Removes all styles bound to this GraphicsNode
- removeStyleReferences(node);
}
/**
* Returns the GraphicsNode associated to the specified Element or
* null if any.
+ *
* @param element the element associated to the graphics node to return
*/
public GraphicsNode getGraphicsNode(Element element) {
@@ -450,6 +473,7 @@
/**
* Returns the Element associated to the specified GraphicsNode or
* null if any.
+ *
* @param node the graphics node associated to the element to return
*/
public Element getElement(GraphicsNode node) {
@@ -460,109 +484,8 @@
}
}
- /**
- * Binds a style element to a style reference.
- * Several style reference can be bound to the same style element.
- * @param element the element
- * @param reference the style reference
- */
- public void bind(Element element, StyleReference reference) {
- if (elementStyleAttMap == null) {
- elementStyleAttMap = new HashMap();
- }
- LinkedList list = (LinkedList)elementStyleAttMap.get(element);
- if (list == null) {
- list = new LinkedList();
- elementStyleAttMap.put(element, list);
- }
- list.add(reference);
- if (nodeStyleMap == null)
- nodeStyleMap = new HashMap();
-
- GraphicsNode node = reference.getGraphicsNode();
- list = (LinkedList)nodeStyleMap.get(node);
- if (list == null) {
- list = new LinkedList();
- nodeStyleMap.put(node, list);
- }
- list.add(element);
- }
-
- /**
- * Returns an enumeration of all style refence for the specified
- * style element.
- * @param element the element
- */
- public List getStyleReferenceList(Element element) {
- if (elementStyleAttMap == null) {
- return Collections.EMPTY_LIST;
- } else {
- LinkedList list = (LinkedList)elementStyleAttMap.get(element);
- if (list != null) {
- return list;
- } else {
- return Collections.EMPTY_LIST;
- }
- }
- }
-
- /**
- * Removes all bindings between a style Element and the specified
- * GraphicsNode.
- * @param node the graphics node
- */
- private void removeStyleReferences(GraphicsNode node){
- // Get the list of style Elements used by this node
- if (nodeStyleMap == null) {
- return;
- }
- List styles = (List)nodeStyleMap.get(node);
- if (styles != null) {
- nodeStyleMap.remove(node);
- }
- for (Iterator it = styles.iterator(); it.hasNext();){
- Element style = (Element)it.next();
- removeStyleReference(node, style);
- }
- }
-
- /**
- * Removes all StyleReference corresponding to the specified GraphicsNode.
- * @param node the graphics node
- * @param style the style element
- */
- private void removeStyleReference(GraphicsNode node, Element style){
- if (elementStyleAttMap == null) {
- return;
- }
- LinkedList list = (LinkedList)elementStyleAttMap.get(style);
- List removed = null;
- if (list == null) {
- return;
- }
- for (Iterator it = list.iterator(); it.hasNext();){
- StyleReference styleRef = (StyleReference)it.next();
- if (styleRef.getGraphicsNode()==node) {
- if (removed == null) {
- removed = new LinkedList();
- }
- removed.add(styleRef);
- }
- }
- if (removed != null) {
- for (Iterator it = removed.iterator(); it.hasNext();) {
- list.remove(it.next());
- }
- }
- if (list.size() == 0) {
- elementStyleAttMap.remove(style);
- }
- }
-
- /////////////////////////////////////////////////////////////////////////
// bridge support
- /////////////////////////////////////////////////////////////////////////
-
+
/**
* Returns the bridge associated with the specified element.
* @param element the element
@@ -578,7 +501,12 @@
if (localNameMap == null) {
return null;
}
- return (Bridge)localNameMap.get(localName);
+ Bridge bridge = (Bridge)localNameMap.get(localName);
+ if (dynamic) {
+ return bridge == null ? null : bridge.getInstance();
+ } else {
+ return bridge;
+ }
}
/**
@@ -587,13 +515,17 @@
* @param localName element's local name
*
*/
- public Bridge getBridge(String namespaceURI,
- String localName){
+ public Bridge getBridge(String namespaceURI, String localName) {
HashMap localNameMap = (HashMap) namespaceURIMap.get(namespaceURI);
if (localNameMap == null) {
return null;
}
- return (Bridge)localNameMap.get(localName);
+ Bridge bridge = (Bridge)localNameMap.get(localName);
+ if (dynamic) {
+ return bridge == null ? null : bridge.getInstance();
+ } else {
+ return bridge;
+ }
}
/**
@@ -603,8 +535,7 @@
* @param localName the local name
* @param bridge the bridge that manages the element
*/
- public void putBridge(String namespaceURI, String localName,
- Bridge bridge) {
+ public void putBridge(String namespaceURI, String localName, Bridge bridge) {
// debug
if (!(namespaceURI.equals(bridge.getNamespaceURI())
&& localName.equals(bridge.getLocalName()))) {
@@ -629,17 +560,17 @@
/**
* Associates the specified <tt>Bridge</tt> object with it's
* namespace URI and local name.
+ *
* @param bridge the bridge that manages the element
*/
public void putBridge(Bridge bridge) {
- putBridge(bridge.getNamespaceURI(),
- bridge.getLocalName(),
- bridge);
+ putBridge(bridge.getNamespaceURI(), bridge.getLocalName(), bridge);
}
/**
* Removes the <tt>Bridge</tt> object associated to the specified
* namespace URI and local name.
+ *
* @param namespaceURI the namespace URI
* @param localName the local name
*/
@@ -662,6 +593,7 @@
/**
* Registers the bridges to handle SVG 1.0 elements.
+ *
* @param ctx the bridge context to initialize
*/
public static void registerSVGBridges(BridgeContext ctx) {
@@ -677,10 +609,13 @@
static List extensions = null;
+ /**
+ * Returns the extensions supported by this bridge context.
+ */
public synchronized static List getBridgeExtensions() {
- if (extensions != null)
+ if (extensions != null) {
return extensions;
-
+ }
extensions = new LinkedList();
extensions.add(new SVGBridgeExtension());
@@ -704,7 +639,6 @@
}
}
return extensions;
- }
-
+ }
}
1.22 +2 -3 xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java
Index: BridgeEventSupport.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- BridgeEventSupport.java 12 Feb 2002 07:08:17 -0000 1.21
+++ BridgeEventSupport.java 12 Feb 2002 15:14:37 -0000 1.22
@@ -56,7 +56,7 @@
* on the GVT root to propagate GVT events to the DOM.
* @author <a href="mailto:cjolif@ilog.fr>Christophe Jolif</a>
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
- * @version $Id: BridgeEventSupport.java,v 1.21 2002/02/12 07:08:17 hillion Exp $
+ * @version $Id: BridgeEventSupport.java,v 1.22 2002/02/12 15:14:37 tkormann Exp $
*/
class BridgeEventSupport implements SVGConstants {
private static final String[] EVENT_ATTRIBUTES_GRAPHICS = {
@@ -319,8 +319,7 @@
for (int i = 0; i < list.getLength(); i++) {
language = (selement = (Element)list.item(i)).
getAttribute("type");
- final Interpreter interpret =
- ctx.getInterpreterPool().getInterpreter(doc, language);
+ final Interpreter interpret = ctx.getInterpreter(language);
if (interpret != null) {
if (language != lang) {
se.setEnvironment(interpret, language);
1.17 +3 -1 xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java
Index: GVTBuilder.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- GVTBuilder.java 23 Jan 2002 14:14:07 -0000 1.16
+++ GVTBuilder.java 12 Feb 2002 15:14:37 -0000 1.17
@@ -30,7 +30,7 @@
* This class is responsible for creating a GVT tree using an SVG DOM tree.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: GVTBuilder.java,v 1.16 2002/01/23 14:14:07 deweese Exp $
+ * @version $Id: GVTBuilder.java,v 1.17 2002/02/12 15:14:37 tkormann Exp $
*/
public class GVTBuilder implements SVGConstants {
@@ -48,6 +48,8 @@
* the GVT tree
*/
public GraphicsNode build(BridgeContext ctx, Document document) {
+ // the bridge context is now associated to one document
+ ctx.setDocument(document);
// set the media type
AbstractViewCSS view;
view = (AbstractViewCSS)((DocumentView)document).getDefaultView();
1.7 +5 -5 xml-batik/sources/org/apache/batik/bridge/SVGBridgeExtension.java
Index: SVGBridgeExtension.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGBridgeExtension.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SVGBridgeExtension.java 23 Jan 2002 14:14:07 -0000 1.6
+++ SVGBridgeExtension.java 12 Feb 2002 15:14:37 -0000 1.7
@@ -133,12 +133,12 @@
// single if() and register all the right bridges
// for static or dynamic together.
//
- if (true) { // ctx.isDynamic()){
+ // if (false) { // ctx.isDynamic()){
// System.out.println("Using Dynamic rect Bridge");
- ctx.putBridge(new SVGRectElementBridge.Dynamic());
- } else {
- ctx.putBridge(new SVGRectElementBridge());
- }
+ //ctx.putBridge(new SVGRectElementBridge.Dynamic());
+ //} else {
+ ctx.putBridge(new SVGRectElementBridge());
+ //}
ctx.putBridge(new AbstractSVGGradientElementBridge.SVGStopElementBridge());
ctx.putBridge(new SVGSVGElementBridge());
1.5 +34 -1 xml-batik/sources/org/apache/batik/bridge/SVGCircleElementBridge.java
Index: SVGCircleElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGCircleElementBridge.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SVGCircleElementBridge.java 18 Sep 2001 09:23:39 -0000 1.4
+++ SVGCircleElementBridge.java 12 Feb 2002 15:14:37 -0000 1.5
@@ -16,11 +16,13 @@
import org.w3c.dom.Element;
+import org.w3c.dom.events.MutationEvent;
+
/**
* Bridge class for the <circle> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGCircleElementBridge.java,v 1.4 2001/09/18 09:23:39 tkormann Exp $
+ * @version $Id: SVGCircleElementBridge.java,v 1.5 2002/02/12 15:14:37 tkormann Exp $
*/
public class SVGCircleElementBridge extends SVGShapeElementBridge {
@@ -37,6 +39,13 @@
}
/**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ return new SVGCircleElementBridge();
+ }
+
+ /**
* Constructs a circle according to the specified parameters.
*
* @param ctx the bridge context to use
@@ -84,5 +93,29 @@
float y = cy - r;
float w = r * 2;
shapeNode.setShape(new Ellipse2D.Float(x, y, w, w));
+ }
+
+ // dynamic support
+
+ /**
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
+ */
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_CX_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_CY_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_R_ATTRIBUTE)) {
+
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+ buildShape(ctx, e, (ShapeNode)node);
+ if (((ShapeNode)node).getShape() == null) {
+ // <!> FIXME: disable the rendering
+ }
+ fireBridgeUpdateCompleted(be);
+ } else {
+ super.handleDOMAttrModifiedEvent(evt);
+ }
}
}
1.5 +35 -1 xml-batik/sources/org/apache/batik/bridge/SVGEllipseElementBridge.java
Index: SVGEllipseElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGEllipseElementBridge.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SVGEllipseElementBridge.java 18 Sep 2001 09:23:39 -0000 1.4
+++ SVGEllipseElementBridge.java 12 Feb 2002 15:14:37 -0000 1.5
@@ -16,11 +16,13 @@
import org.w3c.dom.Element;
+import org.w3c.dom.events.MutationEvent;
+
/**
* Bridge class for the <ellipse> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGEllipseElementBridge.java,v 1.4 2001/09/18 09:23:39 tkormann Exp $
+ * @version $Id: SVGEllipseElementBridge.java,v 1.5 2002/02/12 15:14:37 tkormann Exp $
*/
public class SVGEllipseElementBridge extends SVGShapeElementBridge {
@@ -37,6 +39,13 @@
}
/**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ return new SVGEllipseElementBridge();
+ }
+
+ /**
* Constructs an ellipse according to the specified parameters.
*
* @param ctx the bridge context to use
@@ -97,5 +106,30 @@
}
shapeNode.setShape(new Ellipse2D.Float(cx-rx, cy-ry, rx*2, ry*2));
+ }
+
+ // dynamic support
+
+ /**
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
+ */
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_CX_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_CY_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_RX_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_RY_ATTRIBUTE)) {
+
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+ buildShape(ctx, e, (ShapeNode)node);
+ if (((ShapeNode)node).getShape() == null) {
+ // <!> FIXME: disable the rendering
+ }
+ fireBridgeUpdateCompleted(be);
+ } else {
+ super.handleDOMAttrModifiedEvent(evt);
+ }
}
}
1.5 +35 -1 xml-batik/sources/org/apache/batik/bridge/SVGLineElementBridge.java
Index: SVGLineElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGLineElementBridge.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SVGLineElementBridge.java 2 May 2001 14:34:06 -0000 1.4
+++ SVGLineElementBridge.java 12 Feb 2002 15:14:37 -0000 1.5
@@ -15,11 +15,13 @@
import org.w3c.dom.Element;
+import org.w3c.dom.events.MutationEvent;
+
/**
* Bridge class for the <line> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGLineElementBridge.java,v 1.4 2001/05/02 14:34:06 tkormann Exp $
+ * @version $Id: SVGLineElementBridge.java,v 1.5 2002/02/12 15:14:37 tkormann Exp $
*/
public class SVGLineElementBridge extends SVGDecoratedShapeElementBridge {
@@ -36,6 +38,13 @@
}
/**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ return new SVGLineElementBridge();
+ }
+
+ /**
* Constructs a line according to the specified parameters.
*
* @param ctx the bridge context to use
@@ -82,5 +91,30 @@
}
shapeNode.setShape(new Line2D.Float(x1, y1, x2, y2));
+ }
+
+ // dynamic support
+
+ /**
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
+ */
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_X1_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_Y1_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_X2_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_Y2_ATTRIBUTE)) {
+
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+ buildShape(ctx, e, (ShapeNode)node);
+ if (((ShapeNode)node).getShape() == null) {
+ // <!> FIXME: disable the rendering
+ }
+ fireBridgeUpdateCompleted(be);
+ } else {
+ super.handleDOMAttrModifiedEvent(evt);
+ }
}
}
1.8 +32 -1 xml-batik/sources/org/apache/batik/bridge/SVGPathElementBridge.java
Index: SVGPathElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPathElementBridge.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SVGPathElementBridge.java 8 Nov 2001 23:02:43 -0000 1.7
+++ SVGPathElementBridge.java 12 Feb 2002 15:14:37 -0000 1.8
@@ -18,11 +18,13 @@
import org.w3c.dom.Element;
+import org.w3c.dom.events.MutationEvent;
+
/**
* Bridge class for the <path> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGPathElementBridge.java,v 1.7 2001/11/08 23:02:43 deweese Exp $
+ * @version $Id: SVGPathElementBridge.java,v 1.8 2002/02/12 15:14:37 tkormann Exp $
*/
public class SVGPathElementBridge extends SVGDecoratedShapeElementBridge {
@@ -39,6 +41,13 @@
}
/**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ return new SVGPathElementBridge();
+ }
+
+ /**
* Constructs a path according to the specified parameters.
*
* @param ctx the bridge context to use
@@ -70,6 +79,28 @@
} else {
throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
new Object[] {SVG_D_ATTRIBUTE});
+ }
+ }
+
+ // dynamic support
+
+ /**
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
+ */
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_D_ATTRIBUTE)) {
+
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+ buildShape(ctx, e, (ShapeNode)node);
+ if (((ShapeNode)node).getShape() == null) {
+ // <!> FIXME: disable the rendering
+ }
+ fireBridgeUpdateCompleted(be);
+ } else {
+ super.handleDOMAttrModifiedEvent(evt);
}
}
}
1.9 +32 -1 xml-batik/sources/org/apache/batik/bridge/SVGPolygonElementBridge.java
Index: SVGPolygonElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPolygonElementBridge.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SVGPolygonElementBridge.java 8 Nov 2001 23:02:43 -0000 1.8
+++ SVGPolygonElementBridge.java 12 Feb 2002 15:14:37 -0000 1.9
@@ -18,11 +18,13 @@
import org.w3c.dom.Element;
+import org.w3c.dom.events.MutationEvent;
+
/**
* Bridge class for the <polygon> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGPolygonElementBridge.java,v 1.8 2001/11/08 23:02:43 deweese Exp $
+ * @version $Id: SVGPolygonElementBridge.java,v 1.9 2002/02/12 15:14:37 tkormann Exp $
*/
public class SVGPolygonElementBridge extends SVGDecoratedShapeElementBridge {
@@ -39,6 +41,13 @@
}
/**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ return new SVGPolygonElementBridge();
+ }
+
+ /**
* Constructs a polygon according to the specified parameters.
*
* @param ctx the bridge context to use
@@ -69,6 +78,28 @@
} else {
throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
new Object[] {SVG_POINTS_ATTRIBUTE});
+ }
+ }
+
+ // dynamic support
+
+ /**
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
+ */
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_POINTS_ATTRIBUTE)) {
+
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+ buildShape(ctx, e, (ShapeNode)node);
+ if (((ShapeNode)node).getShape() == null) {
+ // <!> FIXME: disable the rendering
+ }
+ fireBridgeUpdateCompleted(be);
+ } else {
+ super.handleDOMAttrModifiedEvent(evt);
}
}
}
1.8 +32 -1 xml-batik/sources/org/apache/batik/bridge/SVGPolylineElementBridge.java
Index: SVGPolylineElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPolylineElementBridge.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SVGPolylineElementBridge.java 8 Nov 2001 23:02:43 -0000 1.7
+++ SVGPolylineElementBridge.java 12 Feb 2002 15:14:37 -0000 1.8
@@ -18,11 +18,13 @@
import org.w3c.dom.Element;
+import org.w3c.dom.events.MutationEvent;
+
/**
* Bridge class for the <polyline> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGPolylineElementBridge.java,v 1.7 2001/11/08 23:02:43 deweese Exp $
+ * @version $Id: SVGPolylineElementBridge.java,v 1.8 2002/02/12 15:14:37 tkormann Exp $
*/
public class SVGPolylineElementBridge extends SVGDecoratedShapeElementBridge {
@@ -39,6 +41,13 @@
}
/**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ return new SVGPolylineElementBridge();
+ }
+
+ /**
* Constructs a polyline according to the specified parameters.
*
* @param ctx the bridge context to use
@@ -69,6 +78,28 @@
} else {
throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
new Object[] {SVG_POINTS_ATTRIBUTE});
+ }
+ }
+
+ // dynamic support
+
+ /**
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
+ */
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_POINTS_ATTRIBUTE)) {
+
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+ buildShape(ctx, e, (ShapeNode)node);
+ if (((ShapeNode)node).getShape() == null) {
+ // <!> FIXME: disable the rendering
+ }
+ fireBridgeUpdateCompleted(be);
+ } else {
+ super.handleDOMAttrModifiedEvent(evt);
}
}
}
1.7 +28 -100 xml-batik/sources/org/apache/batik/bridge/SVGRectElementBridge.java
Index: SVGRectElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGRectElementBridge.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SVGRectElementBridge.java 31 Jan 2002 21:57:35 -0000 1.6
+++ SVGRectElementBridge.java 12 Feb 2002 15:14:37 -0000 1.7
@@ -18,16 +18,13 @@
import org.w3c.dom.Element;
-import org.w3c.dom.events.Event;
-import org.w3c.dom.events.EventListener;
-import org.w3c.dom.events.EventTarget;
import org.w3c.dom.events.MutationEvent;
/**
* Bridge class for the <rect> element.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGRectElementBridge.java,v 1.6 2002/01/31 21:57:35 deweese Exp $
+ * @version $Id: SVGRectElementBridge.java,v 1.7 2002/02/12 15:14:37 tkormann Exp $
*/
public class SVGRectElementBridge extends SVGShapeElementBridge {
@@ -44,6 +41,13 @@
}
/**
+ * Returns a new instance of this bridge.
+ */
+ public Bridge getInstance() {
+ return new SVGRectElementBridge();
+ }
+
+ /**
* Constructs a rectangle according to the specified parameters.
*
* @param ctx the bridge context to use
@@ -148,106 +152,30 @@
shapeNode.setShape(shape);
}
+ // dynamic support
+
/**
- * Extension of the <tt>SVGRectElementBridge</tt> that can
- * handle updates in the corresponding <tt><rect></tt>
- * element.
+ * Handles DOMAttrModified events.
+ *
+ * @param evt the DOM mutation event
*/
- public static class Dynamic extends SVGRectElementBridge
- implements DynamicBridge, EventListener{
- private BridgeContext ctx;
- private BridgeUpdateHandler handler;
- private int handlerKey;
- private ShapeNode node;
-
- public Bridge getInstance(){
- return new SVGRectElementBridge();
- }
-
- /**
- * Creates a graphics node using the specified BridgeContext and
- * for the specified element.
- *
- * @param ctx the bridge context to use
- * @param e the element that describes the graphics node to build
- * @return a graphics node that represents the specified element
- */
- public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) {
- // System.out.println("Calling createGraphicsNode");
- ((EventTarget)e).addEventListener("DOMAttrModified",
- this,
- false);
- node = (ShapeNode)super.createGraphicsNode(ctx, e);
- this.ctx = ctx;
- return node;
- }
-
- /**
- *
- */
- public void handleEvent(Event evt){
-
- BridgeUpdateEvent be = new BridgeUpdateEvent();
- be.setHandlerKey(handlerKey);
-
- // Notify handler if any.
- if(handler != null){
- handler.bridgeUpdateStarting(be);
- }
+ protected void handleDOMAttrModifiedEvent(MutationEvent evt) {
+ if (evt.getAttrName().equals(SVG_X_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_Y_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_WIDTH_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_HEIGHT_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_RX_ATTRIBUTE) ||
+ evt.getAttrName().equals(SVG_RY_ATTRIBUTE)) {
- Rectangle2D r = (Rectangle2D)node.getShape();
- // System.out.println("Old r: " + r);
-
- MutationEvent mevt = (MutationEvent)evt;
- if (mevt.getAttrName().equals("x")){
- r.setRect(Float.parseFloat(((MutationEvent)evt).getNewValue()),
- r.getY(),
- r.getWidth(),
- r.getHeight());
- } else if (mevt.getAttrName().equals("y")){
- r.setRect(r.getX(),
- Float.parseFloat(((MutationEvent)evt).getNewValue()),
- r.getWidth(),
- r.getHeight());
-
- } else if (mevt.getAttrName().equals("width")){
- r.setRect(r.getX(),
- r.getY(),
- Float.parseFloat(((MutationEvent)evt).getNewValue()),
- r.getHeight());
-
- }else if (mevt.getAttrName().equals("height")){
- r.setRect(r.getX(),
- r.getY(),
- r.getWidth(),
- Float.parseFloat(((MutationEvent)evt).getNewValue()));
-
- }
- // System.out.println("New r: " + r);
-
- node.setShape(r);
-
- if(handler != null){
- handler.bridgeUpdateCompleted(be);
+ BridgeUpdateEvent be = new BridgeUpdateEvent();
+ fireBridgeUpdateStarting(be);
+ buildShape(ctx, e, (ShapeNode)node);
+ if (((ShapeNode)node).getShape() == null) {
+ // <!> FIXME: disable the rendering
}
+ fireBridgeUpdateCompleted(be);
+ } else {
+ super.handleDOMAttrModifiedEvent(evt);
}
-
- /**
- *
- */
- public BridgeUpdateHandler getBridgeUpdateHandler(){
- return handler;
- }
-
- /**
- *
- */
- public void setBridgeUpdateHandler(BridgeUpdateHandler handler,
- int handlerKey){
- System.out.println("SVGRectElementBridge.Dynamic, I have been called: " + handler );
- this.handler = handler;
- this.handlerKey = handlerKey;
- }
-
}
}
1.13 +3 -3 xml-batik/sources/org/apache/batik/bridge/SVGShapeElementBridge.java
Index: SVGShapeElementBridge.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGShapeElementBridge.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SVGShapeElementBridge.java 13 Nov 2001 15:20:58 -0000 1.12
+++ SVGShapeElementBridge.java 12 Feb 2002 15:14:37 -0000 1.13
@@ -21,7 +21,7 @@
* The base bridge class for shapes. Subclasses bridge <tt>ShapeNode</tt>.
*
* @author <a href="mailto:tkormann@apache.org">Thierry Kormann</a>
- * @version $Id: SVGShapeElementBridge.java,v 1.12 2001/11/13 15:20:58 tkormann Exp $
+ * @version $Id: SVGShapeElementBridge.java,v 1.13 2002/02/12 15:14:37 tkormann Exp $
*/
public abstract class SVGShapeElementBridge extends AbstractGraphicsNodeBridge {
@@ -45,9 +45,9 @@
}
// delegates to subclasses the shape construction
buildShape(ctx, e, shapeNode);
- if (shapeNode.getShape() == null) {
+ if (shapeNode.getShape() == null) {
return null; // Disable the rendering if something bad happens
- }
+ }
// 'shape-rendering' and 'color-rendering'
Map shapeHints = CSSUtilities.convertShapeRendering(e);
Map colorHints = CSSUtilities.convertColorRendering(e);
1.3 +3 -2 xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java
Index: ScriptingEnvironment.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/ScriptingEnvironment.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ScriptingEnvironment.java 12 Feb 2002 07:08:17 -0000 1.2
+++ ScriptingEnvironment.java 12 Feb 2002 15:14:37 -0000 1.3
@@ -28,7 +28,7 @@
* This class contains the informations needed by the SVG scripting.
*
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
- * @version $Id: ScriptingEnvironment.java,v 1.2 2002/02/12 07:08:17 hillion Exp $
+ * @version $Id: ScriptingEnvironment.java,v 1.3 2002/02/12 15:14:37 tkormann Exp $
*/
public class ScriptingEnvironment {
@@ -225,6 +225,7 @@
* To run a piece of script.
*/
protected abstract class ScriptingThread extends Thread {
+
protected UserAgent userAgent;
protected Interpreter interpreter;
@@ -235,7 +236,7 @@
BridgeContext bc = updateManager.getBridgeContext();
userAgent = bc.getUserAgent();
Document doc = updateManager.getDocument();
- interpreter = bc.getInterpreterPool().getInterpreter(doc, lang);
+ interpreter = bc.getInterpreter(lang);
if (interpreter == null) {
if (userAgent != null) {
userAgent.displayError
1.8 +81 -114 xml-batik/sources/org/apache/batik/script/InterpreterPool.java
Index: InterpreterPool.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/script/InterpreterPool.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- InterpreterPool.java 21 Feb 2001 16:49:54 -0000 1.7
+++ InterpreterPool.java 12 Feb 2002 15:14:37 -0000 1.8
@@ -11,167 +11,134 @@
import org.apache.batik.dom.svg.*;
import java.util.HashMap;
-import java.util.WeakHashMap;
+import java.util.Map;
import org.w3c.dom.Document;
import org.w3c.dom.svg.SVGDocument;
/**
- * A class allowing to create/query an {@link org.apache.batik.script.Interpreter}
- * corresponding to a particular <code>Document</code> and scripting language.
- * By default, it is able to create interpreters for ECMAScript, Python and Tcl
- * scripting languages if you provide the right jar files in your CLASSPATH (i.e.
- * Rhino, JPython and Jacl jar files).
+ * A class allowing to create/query an {@link
+ * org.apache.batik.script.Interpreter} corresponding to a particular
+ * <tt>Document</tt> and scripting language.
+ *
+ * <p>By default, it is able to create interpreters for ECMAScript,
+ * Python and Tcl scripting languages if you provide the right jar
+ * files in your CLASSPATH (i.e. Rhino, JPython and Jacl jar
+ * files).</p>
+ *
* @author <a href="mailto:cjolif@ilog.fr">Christophe Jolif</a>
- * @version $Id: InterpreterPool.java,v 1.7 2001/02/21 16:49:54 cjolif Exp $
+ * @version $Id: InterpreterPool.java,v 1.8 2002/02/12 15:14:37 tkormann Exp $
*/
public class InterpreterPool {
- // by default we have 3 languages a few chances that other
- // languages are added...
- private HashMap factories = new HashMap(3);
- // as we use a WeakHashMap, beeing referenced here will not
- // prevent a Document from beeing discared
- // by default we have one document a time.
- private WeakHashMap documentsMap = new WeakHashMap(1);
-
+ /** The InterpreterFactory classname for Rhino. */
private static final String RHINO =
"org.apache.batik.script.rhino.RhinoInterpreterFactory";
+ /** The InterpreterFactory classname for JPython. */
private static final String JPYTHON =
"org.apache.batik.script.jpython.JPythonInterpreterFactory";
+ /** The InterpreterFactory classname for Jacl. */
private static final String JACL =
"org.apache.batik.script.jacl.JaclInterpreterFactory";
- private static HashMap defaultFactories = null;
+ /**
+ * The default InterpreterFactory map.
+ */
+ protected static Map defaultFactories = new HashMap(7);
/**
- * Builds an instance of <code>InterpreterPool</code> that
- * will create <code>Interpreter</code> instances. Initializes
- * the <code>InterpreterPool</code> to recognize the default
- * scripting languages.
+ * The InterpreterFactory map.
+ */
+ protected Map factories = new HashMap(7);
+
+ static {
+ InterpreterFactory factory = null;
+ try {
+ factory =
+ (InterpreterFactory)Class.forName(RHINO).newInstance();
+ defaultFactories.put("text/ecmascript", factory);
+ } catch (Throwable t1) {
+ // may append if the class is not in the CLASSPATH
+ }
+ try {
+ factory =
+ (InterpreterFactory)Class.forName(JPYTHON).newInstance();
+ defaultFactories.put("text/python", factory);
+ } catch (Throwable t2) {
+ // may append if the class is not in the CLASSPATH
+ }
+ try {
+ factory =
+ (InterpreterFactory)Class.forName(JACL).newInstance();
+ defaultFactories.put("text/tcl", factory);
+ } catch (Throwable t3) {
+ // may append if the class is not in the CLASSPATH
+ }
+ }
+
+ /**
+ * Constructs a new <tt>InterpreterPool</tt>.
*/
public InterpreterPool() {
- initDefaultFactories();
factories.putAll(defaultFactories);
}
/**
- * We init the default factories only once whatever is the number
- * of <code>IntepreterPool</code> instances because it is sufficient.
+ * Creates a new interpreter for the specified document and
+ * according to the specified language. This method can return
+ * null if no interpreter has been found for the specified
+ * language.
+ *
+ * @param document the document that needs the interpreter
+ * @param language the scripting language
*/
- private static void initDefaultFactories() {
- if (defaultFactories == null) {
- defaultFactories = new HashMap(3);
- InterpreterFactory factory = null;
- try {
- factory =
- (InterpreterFactory)Class.forName(RHINO).newInstance();
- defaultFactories.put("text/ecmascript",
- factory);
- } catch (Throwable t1) {
- // may append if the class is not in the CLASSPATH
- }
+ public Interpreter createInterpreter(Document document, String language) {
+ InterpreterFactory factory = (InterpreterFactory)factories.get(language);
+ Interpreter interpreter = null;
+ if (factory != null)
try {
- factory =
- (InterpreterFactory)Class.forName(JPYTHON).newInstance();
- defaultFactories.put("text/python",
- factory);
- } catch (Throwable t2) {
- // may append if the class is not in the CLASSPATH
- }
- try {
- factory =
- (InterpreterFactory)Class.forName(JACL).newInstance();
- defaultFactories.put("text/tcl",
- factory);
- } catch (Throwable t3) {
- // may append if the class is not in the CLASSPATH
+ interpreter = factory.createInterpreter();
+ if (document != null) {
+ interpreter.bindObject("document",
+ createDocumentProxy(document));
+ }
+ } catch (Throwable t) {
+ // may append if the batik interpreters class is here but
+ // not the scripting engine jar
}
- }
+ return interpreter;
}
-
+
/**
* We use Proxies that use WeakReference to prevent from referencing
* directly the document, otherwhise, the WeakHashMap will be useless
* as the document will never be in situation of beeing discarded.
*/
- private static Document createDocumentProxy(Document document)
- {
- if (document instanceof SVGDocument)
+ protected static Document createDocumentProxy(Document document) {
+ if (document instanceof SVGDocument) {
return new SVGDocumentProxy((SVGDocument)document);
- else
+ } else {
return new DocumentProxy(document);
- }
-
- /**
- * Returns a unique instance of an implementation of
- * <code>Interpreter</code> interface that matches the given language and
- * the given <code>Document</code>.
- * It returns <code>null</code> if the interpreter cannot be build (for
- * example the language is not recognized by this
- * <code>InterpreterPool</code>). If the document is not <code>null</code>,
- * the variable "document" in the returned interpreter will give access
- * to an instance of <code>Document</code> or <code>SVGDocument</code>
- * depending on the type of the document. The interpreter will
- * automatically be released
- * when the <code>Document</code> will no longer be referenced elsewhere.
- * @param document a DOM <code>Document</code> instance.
- * @param language a mimeType like string describing the language to use
- * (i.e. "text/ecmascript" for ECMAScript interpreter, "text/tcl" for Tcl
- * interpreter...).
- */
- public synchronized Interpreter getInterpreter(Document document,
- String language) {
- // document maybe null HashMap supports null key.
- HashMap interpretersMap = (HashMap)documentsMap.get(document);
- if (interpretersMap == null) {
- // by default we use only one language for a particular document
- interpretersMap = new HashMap(1);
- documentsMap.put(document, interpretersMap);
}
- Interpreter interpreter = (Interpreter)interpretersMap.get(language);
- if (interpreter == null) {
- InterpreterFactory factory =
- (InterpreterFactory)factories.get(language);
- if (factory != null)
- try {
- interpreter = factory.createInterpreter();
- if (document != null) {
- interpreter.bindObject("document",
- createDocumentProxy(document));
- }
- interpretersMap.put(language, interpreter);
- } catch (Throwable t) {
- // may append if the batik interpreters class is here but
- // not the scripting engine jar
- }
- }
- return interpreter;
}
/**
- * Registers an <code>InterpreterFactory</code> for the given
- * language. This allows you to add other languages to the default
- * ones or to replace the <code>InterpreterFactory</code> usually used
- * to create an <code>Interpreter</code> instance for a particular language
- * by your own to be able to have your own interpreter.
- * @param language the language for which the factory is registered.
- * @parma factory the <code>InterpreterFactory</code> that will allow to
- * create a interpreter for the language.
+ * Adds for the specified language, the specified Interpreter factory.
+ *
+ * @param language the language for which the factory is registered
+ * @param factory the <code>InterpreterFactory</code> to register
*/
- public void putInterpreterFactory(String language,
+ public void putInterpreterFactory(String language,
InterpreterFactory factory) {
factories.put(language, factory);
}
/**
- * Unregisters the <code>InterpreterFactory</code> of the given
- * language. It will then be impossible to create new <code>Interpreter</code>
- * instances for the given language.
- * @param language the language for which the factory should
- * be unregistered.
+ * Removes the InterpreterFactory associated to the specified language.
+ *
+ * @param language the language for which the factory should be removed.
*/
public void removeInterpreterFactory(String language) {
factories.remove(language);
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org