1 18 package org.apache.batik.script; 19 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 import org.apache.batik.dom.svg.SVGOMDocument; 25 import org.apache.batik.util.Service; 26 27 import org.w3c.dom.Document ; 28 29 42 public class InterpreterPool { 43 44 45 private static final String RHINO = 46 "org.apache.batik.script.rhino.RhinoInterpreterFactory"; 47 48 49 private static final String JPYTHON = 50 "org.apache.batik.script.jpython.JPythonInterpreterFactory"; 51 52 53 private static final String JACL = 54 "org.apache.batik.script.jacl.JaclInterpreterFactory"; 55 56 59 public static final String BIND_NAME_DOCUMENT = "document"; 60 61 64 protected static Map defaultFactories = new HashMap (7); 65 66 69 protected Map factories = new HashMap (7); 70 71 static { 72 Iterator iter = Service.providers(InterpreterFactory.class); 73 while (iter.hasNext()) { 74 InterpreterFactory factory = null; 75 factory = (InterpreterFactory)iter.next(); 76 defaultFactories.put(factory.getMimeType(), factory); 78 } 79 } 80 81 84 public InterpreterPool() { 85 factories.putAll(defaultFactories); 86 } 87 88 97 public Interpreter createInterpreter(Document document, String language) { 98 InterpreterFactory factory = (InterpreterFactory)factories.get(language); 99 Interpreter interpreter = null; 100 if (factory != null) 101 interpreter = factory.createInterpreter 102 (((SVGOMDocument)document).getURLObject()); 103 if (document != null) { 104 interpreter.bindObject(BIND_NAME_DOCUMENT, document); 105 } 106 107 return interpreter; 108 } 109 110 116 public void putInterpreterFactory(String language, 117 InterpreterFactory factory) { 118 factories.put(language, factory); 119 } 120 121 126 public void removeInterpreterFactory(String language) { 127 factories.remove(language); 128 } 129 } 130 131 | Popular Tags |