public class OSGiScriptEngineManager extends ScriptEngineManager
ScriptEngineFactory
classes. For each bundle, it creates a
ScriptEngineManager, then merges them. ScriptEngineFactory
objects are wrapped
into @link OSGiScriptEngineFactory objects to deal with problems of context class loader:
Those scripting engines that rely on the ContextClassloader for finding resources need to use this wrapper
and the @link OSGiScriptFactory. Mainly, jruby does.
Note that even if no context classloader issues arose, it would still be needed to search manually for the
factories and either use them directly (losing the mimeType/extension/shortName mechanisms for finding engines
or manually registering them) or still use this class, which would be smarter. In the latter case,
it would only be needed to remove the hack that temporarily sets the context classloader to the appropriate,
bundle-related, class loader.
Caveats:
OSGiScriptEngineFactory
. As Engines are not wrapped,
calls like
ScriptEngineManager osgiManager=new OSGiScriptEngineManager(context);
ScriptEngine engine=osgiManager.getEngineByName("ruby");
ScriptEngineFactory factory=engine.getFactory() //this does not return the OSGiFactory wrapper
factory.getScriptEngine(); //this might fail, as it does not use OSGiScriptEngineFactory wrapper
might result in unexpected errors. Future versions may wrap the ScriptEngine with a OSGiScriptEngine to solve this
issue, but for the moment it is not needed.
Constructor and Description |
---|
OSGiScriptEngineManager(org.osgi.framework.BundleContext context) |
Modifier and Type | Method and Description |
---|---|
Object |
get(String key) |
Bindings |
getBindings() |
ScriptEngine |
getEngineByExtension(String extension) |
ScriptEngine |
getEngineByMimeType(String mimeType) |
ScriptEngine |
getEngineByName(String shortName) |
List<ScriptEngineFactory> |
getEngineFactories() |
String |
printScriptEngines() |
void |
put(String key,
Object value) |
void |
registerEngineExtension(String extension,
ScriptEngineFactory factory) |
void |
registerEngineMimeType(String type,
ScriptEngineFactory factory) |
void |
registerEngineName(String name,
ScriptEngineFactory factory) |
void |
reloadManagers()
This method is the only one that is visible and not part of the ScriptEngineManager class.
|
void |
setBindings(Bindings bindings)
Follows the same behavior of @link javax.script.ScriptEngineManager#setBindings(Bindings)
This means that the same bindings are applied to all the underlying managers.
|
public OSGiScriptEngineManager(org.osgi.framework.BundleContext context)
public void reloadManagers()
ScriptEngineManager manager=new OSGiScriptEngineManager(context);
(...)//do stuff
osgiManager=(OSGiScriptEngineManager)manager;//cast to ease reading
osgiManager.reloadManagers();
manager.setBindings(new OSGiBindings());//or you can use your own bindings implementation
public Object get(String key)
get
in class ScriptEngineManager
public Bindings getBindings()
getBindings
in class ScriptEngineManager
public void setBindings(Bindings bindings)
setBindings
in class ScriptEngineManager
bindings
- public ScriptEngine getEngineByExtension(String extension)
getEngineByExtension
in class ScriptEngineManager
public ScriptEngine getEngineByMimeType(String mimeType)
getEngineByMimeType
in class ScriptEngineManager
public ScriptEngine getEngineByName(String shortName)
getEngineByName
in class ScriptEngineManager
public List<ScriptEngineFactory> getEngineFactories()
getEngineFactories
in class ScriptEngineManager
public void put(String key, Object value)
put
in class ScriptEngineManager
public void registerEngineExtension(String extension, ScriptEngineFactory factory)
registerEngineExtension
in class ScriptEngineManager
public void registerEngineMimeType(String type, ScriptEngineFactory factory)
registerEngineMimeType
in class ScriptEngineManager
public void registerEngineName(String name, ScriptEngineFactory factory)
registerEngineName
in class ScriptEngineManager
public String printScriptEngines()
Copyright © 2016 Hazelcast, Inc.. All Rights Reserved.