Methods Summary |
---|
private boolean | canCallerAccessLoader(java.lang.ClassLoader loader)
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ClassLoader callerLoader = getCallerClassLoader();
if (callerLoader != null) {
if (loader != callerLoader || !isAncestor(loader, callerLoader)) {
try {
sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
} catch (SecurityException exp) {
if (DEBUG) exp.printStackTrace();
return false;
}
} // else fallthru..
} // else fallthru..
} // else fallthru..
return true;
|
public java.lang.Object | get(java.lang.String key)Gets the value for the specified key in the Global Scope
return globalScope.get(key);
|
public javax.script.Bindings | getBindings()getBindings returns the value of the globalScope field.
ScriptEngineManager sets this Bindings as global bindings for
ScriptEngine objects created by it.
return globalScope;
|
private java.lang.ClassLoader | getCallerClassLoader()
Class caller = Reflection.getCallerClass(3);
if (caller == null) {
return null;
}
return caller.getClassLoader();
|
public javax.script.ScriptEngine | getEngineByExtension(java.lang.String extension)Look up and create a ScriptEngine for a given extension. The algorithm
used by getEngineByName is used except that the search starts
by looking for a ScriptEngineFactory registered to handle the
given extension using registerEngineExtension .
if (extension == null) throw new NullPointerException();
//look for registered extension first
Object obj;
if (null != (obj = extensionAssociations.get(extension))) {
ScriptEngineFactory spi = (ScriptEngineFactory)obj;
try {
ScriptEngine engine = spi.getScriptEngine();
engine.setBindings(getBindings(), ScriptContext.GLOBAL_SCOPE);
return engine;
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
}
for (ScriptEngineFactory spi : engineSpis) {
List<String> exts = null;
try {
exts = spi.getExtensions();
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
if (exts == null) continue;
for (String ext : exts) {
if (extension.equals(ext)) {
try {
ScriptEngine engine = spi.getScriptEngine();
engine.setBindings(getBindings(), ScriptContext.GLOBAL_SCOPE);
return engine;
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
}
}
}
return null;
|
public javax.script.ScriptEngine | getEngineByMimeType(java.lang.String mimeType)Look up and create a ScriptEngine for a given mime type. The algorithm
used by getEngineByName is used except that the search starts
by looking for a ScriptEngineFactory registered to handle the
given mime type using registerEngineMimeType .
if (mimeType == null) throw new NullPointerException();
//look for registered types first
Object obj;
if (null != (obj = mimeTypeAssociations.get(mimeType))) {
ScriptEngineFactory spi = (ScriptEngineFactory)obj;
try {
ScriptEngine engine = spi.getScriptEngine();
engine.setBindings(getBindings(), ScriptContext.GLOBAL_SCOPE);
return engine;
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
}
for (ScriptEngineFactory spi : engineSpis) {
List<String> types = null;
try {
types = spi.getMimeTypes();
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
if (types == null) continue;
for (String type : types) {
if (mimeType.equals(type)) {
try {
ScriptEngine engine = spi.getScriptEngine();
engine.setBindings(getBindings(), ScriptContext.GLOBAL_SCOPE);
return engine;
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
}
}
}
return null;
|
public javax.script.ScriptEngine | getEngineByName(java.lang.String shortName)Looks up and creates a ScriptEngine for a given name.
The algorithm first searches for a ScriptEngineFactory that has been
registered as a handler for the specified name using the registerEngineName
method.
If one is not found, it searches the array of ScriptEngineFactory instances
stored by the constructor for one with the specified name. If a ScriptEngineFactory
is found by either method, it is used to create instance of ScriptEngine .
if (shortName == null) throw new NullPointerException();
//look for registered name first
Object obj;
if (null != (obj = nameAssociations.get(shortName))) {
ScriptEngineFactory spi = (ScriptEngineFactory)obj;
try {
ScriptEngine engine = spi.getScriptEngine();
engine.setBindings(getBindings(), ScriptContext.GLOBAL_SCOPE);
return engine;
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
}
for (ScriptEngineFactory spi : engineSpis) {
List<String> names = null;
try {
names = spi.getNames();
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
if (names != null) {
for (String name : names) {
if (shortName.equals(name)) {
try {
ScriptEngine engine = spi.getScriptEngine();
engine.setBindings(getBindings(), ScriptContext.GLOBAL_SCOPE);
return engine;
} catch (Exception exp) {
if (DEBUG) exp.printStackTrace();
}
}
}
}
}
return null;
|
public java.util.List | getEngineFactories()Returns an array whose elements are instances of all the ScriptEngineFactory classes
found by the discovery mechanism.
List<ScriptEngineFactory> res = new ArrayList<ScriptEngineFactory>(engineSpis.size());
for (ScriptEngineFactory spi : engineSpis) {
res.add(spi);
}
return Collections.unmodifiableList(res);
|
private void | init(java.lang.ClassLoader loader)
globalScope = new SimpleBindings();
engineSpis = new HashSet<ScriptEngineFactory>();
nameAssociations = new HashMap<String, ScriptEngineFactory>();
extensionAssociations = new HashMap<String, ScriptEngineFactory>();
mimeTypeAssociations = new HashMap<String, ScriptEngineFactory>();
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
initEngines(loader);
return null;
}
});
|
private void | initEngines(java.lang.ClassLoader loader)
Iterator itr = null;
try {
if (loader != null) {
itr = Service.providers(ScriptEngineFactory.class, loader);
} else {
itr = Service.installedProviders(ScriptEngineFactory.class);
}
} catch (ServiceConfigurationError err) {
System.err.println("Can't find ScriptEngineFactory providers: " +
err.getMessage());
if (DEBUG) {
err.printStackTrace();
}
// do not throw any exception here. user may want to
// manage his/her own factories using this manager
// by explicit registratation (by registerXXX) methods.
return;
}
try {
while (itr.hasNext()) {
try {
ScriptEngineFactory fact = (ScriptEngineFactory) itr.next();
engineSpis.add(fact);
} catch (ServiceConfigurationError err) {
System.err.println("ScriptEngineManager providers.next(): "
+ err.getMessage());
if (DEBUG) {
err.printStackTrace();
}
// one factory failed, but check other factories...
continue;
}
}
} catch (ServiceConfigurationError err) {
System.err.println("ScriptEngineManager providers.hasNext(): "
+ err.getMessage());
if (DEBUG) {
err.printStackTrace();
}
// do not throw any exception here. user may want to
// manage his/her own factories using this manager
// by explicit registratation (by registerXXX) methods.
return;
}
|
private boolean | isAncestor(java.lang.ClassLoader cl1, java.lang.ClassLoader cl2)
do {
cl2 = cl2.getParent();
if (cl1 == cl2) return true;
} while (cl2 != null);
return false;
|
public void | put(java.lang.String key, java.lang.Object value)Sets the specified key/value pair in the Global Scope.
globalScope.put(key, value);
|
public void | registerEngineExtension(java.lang.String extension, javax.script.ScriptEngineFactory factory)Registers a ScriptEngineFactory to handle an extension.
Overrides any such association found using the Discovery mechanism.
if (extension == null || factory == null) throw new NullPointerException();
extensionAssociations.put(extension, factory);
|
public void | registerEngineMimeType(java.lang.String type, javax.script.ScriptEngineFactory factory)Registers a ScriptEngineFactory to handle a mime type.
Overrides any such association found using the Discovery mechanism.
if (type == null || factory == null) throw new NullPointerException();
mimeTypeAssociations.put(type, factory);
|
public void | registerEngineName(java.lang.String name, javax.script.ScriptEngineFactory factory)Registers a ScriptEngineFactory to handle a language
name. Overrides any such association found using the Discovery mechanism.
if (name == null || factory == null) throw new NullPointerException();
nameAssociations.put(name, factory);
|
public void | setBindings(javax.script.Bindings bindings)setBindings stores the specified Bindings
in the globalScope field. ScriptEngineManager sets this
Bindings as global bindings for ScriptEngine
objects created by it.
if (bindings == null) {
throw new IllegalArgumentException("Global scope cannot be null.");
}
globalScope = bindings;
|