本文整理了Java中bsh.Interpreter.getClassManager()
方法的一些代码示例,展示了Interpreter.getClassManager()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Interpreter.getClassManager()
方法的具体详情如下:
包路径:bsh.Interpreter
类名称:Interpreter
方法名:getClassManager
[英]Get the class manager associated with this interpreter (the BshClassManager of this interpreter's global namespace). This is primarily a convenience method.
[中]获取与此解释器关联的类管理器(此解释器的全局命名空间的BshClassManager)。这主要是一种方便的方法。
代码示例来源:origin: osmandapp/Osmand
public BeanShellTileSourceTemplate(String name, String urlToLoad, String ext,
int maxZoom, int minZoom, int tileSize, int bitDensity, int avgSize) {
super(name, urlToLoad, ext, maxZoom, minZoom, tileSize, bitDensity, avgSize);
bshInterpreter = new Interpreter();
try {
bshInterpreter.eval(urlToLoad);
bshInterpreter.getClassManager().setClassLoader(new ClassLoader() {
@Override
public URL getResource(String resName) {
return null;
}
@Override
public InputStream getResourceAsStream(String resName) {
return null;
}
@Override
public Class<?> loadClass(String className) throws ClassNotFoundException {
throw new ClassNotFoundException("Error requesting " + className);
}
});
} catch (bsh.EvalError e) {
log.error("Error executing the map init script " + urlToLoad, e);
}
}
代码示例来源:origin: jitlogic/zorka
/**
Set an external class loader to be used as the base classloader
for BeanShell. The base classloader is used for all classloading
unless/until the addClasspath()/setClasspath()/reloadClasses()
commands are called to modify the interpreter's classpath. At that
time the new paths /updated paths are added on top of the base
classloader.
<p>
BeanShell will use this at the same point it would otherwise use the
plain Class.forName().
i.e. if no explicit classpath management is done from the script
(addClassPath(), setClassPath(), reloadClasses()) then BeanShell will
only use the supplied classloader. If additional classpath management
is done then BeanShell will perform that in addition to the supplied
external classloader.
However BeanShell is not currently able to reload
classes supplied through the external classloader.
<p>
@see BshClassManager#setClassLoader( ClassLoader )
*/
public void setClassLoader( ClassLoader externalCL ) {
getClassManager().setClassLoader( externalCL );
}
代码示例来源:origin: beanshell/beanshell
/**
Set an external class loader to be used as the base classloader
for BeanShell. The base classloader is used for all classloading
unless/until the addClasspath()/setClasspath()/reloadClasses()
commands are called to modify the interpreter's classpath. At that
time the new paths /updated paths are added on top of the base
classloader.
<p>
BeanShell will use this at the same point it would otherwise use the
plain Class.forName().
i.e. if no explicit classpath management is done from the script
(addClassPath(), setClassPath(), reloadClasses()) then BeanShell will
only use the supplied classloader. If additional classpath management
is done then BeanShell will perform that in addition to the supplied
external classloader.
However BeanShell is not currently able to reload
classes supplied through the external classloader.
<p>
@see BshClassManager#setClassLoader( ClassLoader )
*/
public void setClassLoader( ClassLoader externalCL ) {
getClassManager().setClassLoader( externalCL );
}
代码示例来源:origin: beanshell/beanshell
/**
A command may be implemented as a compiled Java class containing one or
more static invoke() methods of the correct signature. The invoke()
methods must accept two additional leading arguments of the interpreter
and callstack, respectively. e.g. invoke(interpreter, callstack, ... )
This method adds the arguments and invokes the static method, returning
the result.
*/
public static Object invokeCompiledCommand(
Class<?> commandClass, Object [] args, Interpreter interpreter,
CallStack callstack, SimpleNode callerInfo )
throws UtilEvalError
{
// add interpereter and namespace to args list
Object[] invokeArgs = new Object[args.length + 2];
invokeArgs[0] = interpreter;
invokeArgs[1] = callstack;
System.arraycopy( args, 0, invokeArgs, 2, args.length );
BshClassManager bcm = interpreter.getClassManager();
try {
return invokeStaticMethod(
bcm, commandClass, "invoke", invokeArgs, callerInfo );
} catch ( InvocationTargetException e ) {
throw new UtilEvalError(
"Error in compiled command: " + e.getCause(), e );
} catch ( ReflectError e ) {
throw new UtilEvalError("Error invoking compiled command: " + e, e );
}
}
代码示例来源:origin: org.zkoss.zk/zk
/*package*/ NS newNS(Scope scope) {
scope = getIdSpace(scope);
Scope p = getParentIdSpace(scope);
return new NS(p != null ? prepareNS(p) : _bshns, _ip.getClassManager(), scope);
//Bug 1831534: we have to pass class manager
//Bug 1899353: we have to use _bshns instead of null (Reason: unknown)
}
代码示例来源:origin: jitlogic/zorka
/**
* A command may be implemented as a compiled Java class containing one or
* more static invoke() methods of the correct signature. The invoke()
* methods must accept two additional leading arguments of the interpreter
* and callstack, respectively. e.g. invoke(interpreter, callstack, ... )
* This method adds the arguments and invokes the static method, returning
* the result.
*/
public static Object invokeCompiledCommand(Class commandClass, Object[] args, BshEvaluatingVisitor visitor) throws UtilEvalError {
// add interpereter and namespace to args list
Object[] invokeArgs = new Object[args.length + 2];
invokeArgs[0] = visitor.getInterpreter();
invokeArgs[1] = visitor.getCallstack();
System.arraycopy(args, 0, invokeArgs, 2, args.length);
BshClassManager bcm = visitor.getInterpreter().getClassManager();
try {
return Reflect.invokeStaticMethod(bcm, commandClass, "invoke", invokeArgs);
} catch (InvocationTargetException e) {
throw new UtilEvalError("Error in compiled command: " + e.getTargetException(), e);
} catch (ReflectError e) {
throw new UtilEvalError("Error invoking compiled command: " + e, e);
}
}
代码示例来源:origin: jitlogic/zorka
public Class getType(BSHType tnode)
throws EvalError
{
// return cached type if available
if ( tnode.type != null )
return tnode.type;
// first node will either be PrimitiveType or AmbiguousName
SimpleNode node = tnode.getTypeNode();
if ( node instanceof BSHPrimitiveType )
tnode.baseType = ((BSHPrimitiveType)node).getType();
else
tnode.baseType = ambiguousNameToClass(((BSHAmbiguousName)node));
if ( tnode.arrayDims > 0 ) {
try {
// Get the type by constructing a prototype array with
// arbitrary (zero) length in each dimension.
int[] dims = new int[tnode.arrayDims]; // int array default zeros
Object obj = Array.newInstance(tnode.baseType, dims);
tnode.type = obj.getClass();
} catch(Exception e) {
throw new EvalError("Couldn't construct array type",
tnode, callstack );
}
} else
tnode.type = tnode.baseType;
// hack... sticking to first interpreter that resolves this
// see comments on type instance variable
interpreter.getClassManager().addListener(tnode);
return tnode.type;
}
代码示例来源:origin: beanshell/beanshell
BshClassManager bcm = interpreter.getClassManager();
代码示例来源:origin: org.zkoss.zk/zk
public void init(Page owner, String zslang) {
super.init(owner, zslang);
_ip = new bsh.Interpreter();
_ip.setClassLoader(Classes.getContextClassLoader(BSHInterpreter.class));
_bshns = new GlobalNS(_ip.getClassManager(), "global");
_ip.setNameSpace(_bshns);
}
代码示例来源:origin: beanshell/beanshell
interpreter.getClassManager().addListener(this);
代码示例来源:origin: jitlogic/zorka
BshClassManager bcm = interpreter.getClassManager();
代码示例来源:origin: beanshell/beanshell
public Object invoke(final Map<String, ?> context) throws EvalError {
final NameSpace nameSpace = new NameSpace("BeanshellExecutable", _interpreter.getClassManager());
nameSpace.setParent(_interpreter.getNameSpace());
final BshMethod method = new BshMethod(_method.getName(), _method.getReturnType(),
_method.getParameterNames(), _method.getParameterTypes(), _method.getParameterModifiers(),
_method.methodBody, nameSpace, _method.getModifiers());
for (final Map.Entry<String, ?> entry : context.entrySet()) {
try {
final Object value = entry.getValue();
nameSpace.setVariable(entry.getKey(), value != null ? value : Primitive.NULL, false);
} catch (final UtilEvalError e) {
throw new EvalError("cannot set variable '" + entry.getKey() + '\'', null, null, e);
}
}
final Object result = method.invoke(Reflect.ZERO_ARGS, _interpreter);
if ( Types.getType(result) == Void.TYPE )
return null;
return Primitive.unwrap(result);
}
代码示例来源:origin: jitlogic/zorka
public Object invoke(final Map<String, ?> context) throws EvalError {
final NameSpace nameSpace = new NameSpace(_interpreter.getClassManager(), "BeanshellExecutable");
nameSpace.setParent(_interpreter.getNameSpace());
final BshMethod method = new BshMethod(_method.getName(), _method.getReturnType(), _method.getParameterNames(), _method.getParameterTypes(), _method.methodBody, nameSpace, _method.getModifiers());
for (final Map.Entry<String, ?> entry : context.entrySet()) {
try {
nameSpace.setVariable(entry.getKey(), entry.getValue(), false);
} catch (final UtilEvalError e) {
throw new EvalError("cannot set variable '" + entry.getKey() + '\'', null, null, e);
}
}
final Object result = method.invoke(new Object[0], new BshEvaluatingVisitor(null, _interpreter));
if (result instanceof Primitive) {
if (( (Primitive) result).getType() == Void.TYPE) {
return null;
}
return ( (Primitive) result).getValue();
}
return result;
}
代码示例来源:origin: beanshell/beanshell
interpreter == null ? null : interpreter.getClassManager();
Class<?> clas = object.getClass();
代码示例来源:origin: jpos/jPOS
public void initService() {
bsh = new Interpreter ();
BshClassManager bcm = bsh.getClassManager();
try {
bcm.setClassPath(getServer().getLoader().getURLs());
} catch (UtilEvalError e) {
e.printStackTrace();
}
bcm.setClassLoader(getServer().getLoader());
}
public void startService() {
代码示例来源:origin: beanshell/beanshell
private void initRootSystemObject()
{
BshClassManager bcm = getClassManager();
// bsh
setu("bsh", new NameSpace(null, bcm, "Bsh Object" ).getThis( this ) );
// bsh.system
setu( "bsh.system", SYSTEM_OBJECT);
setu( "bsh.shared", SYSTEM_OBJECT); // alias
// bsh.help
This helpText = new NameSpace(null, bcm, "Bsh Command Help Text" ).getThis( this );
setu( "bsh.help", helpText );
// bsh.cwd
setu( "bsh.cwd", System.getProperty("user.dir") );
// bsh.interactive
setu( "bsh.interactive", interactive ? Primitive.TRUE : Primitive.FALSE );
// bsh.evalOnly
setu( "bsh.evalOnly", Primitive.FALSE );
}
代码示例来源:origin: jitlogic/zorka
/**
* Invoke method on arbitrary object instance.
* invocation may be static (through the object instance) or dynamic.
* Object may be a bsh scripted object (bsh.This type).
*
* @return the result of the method call
*/
public static Object invokeObjectMethod(Object object, String methodName, Object[] args, BshEvaluatingVisitor visitor, SimpleNode callerInfo) throws ReflectError, EvalError, InvocationTargetException {
// Bsh scripted object
if (object instanceof This && !This.isExposedThisMethod(methodName)) {
return ((This) object).invokeMethod(methodName, args, visitor.getInterpreter(), visitor.getCallstack(), callerInfo, false/*delcaredOnly*/);
}
// Plain Java object, find the java method
try {
BshClassManager bcm = visitor.getInterpreter() == null ? null : visitor.getInterpreter().getClassManager();
Class clas = object.getClass();
Method method = resolveExpectedJavaMethod(bcm, clas, object, methodName, args, false);
return invokeMethod(method, object, args);
} catch (UtilEvalError e) {
throw e.toEvalError(callerInfo, visitor.getCallstack());
}
}
代码示例来源:origin: jitlogic/zorka
private void initRootSystemObject()
{
BshClassManager bcm = getClassManager();
// bsh
setu("bsh", new NameSpace( bcm, "Bsh Object" ).getThis( this ) );
setu( "bsh.system", SYSTEM_OBJECT);
setu( "bsh.shared", SYSTEM_OBJECT); // alias
// bsh.help
This helpText = new NameSpace(bcm, "Bsh Command Help Text" ).getThis( this );
setu( "bsh.help", helpText );
// bsh.cwd
try {
setu( "bsh.cwd", System.getProperty("user.dir") );
} catch ( SecurityException e ) {
// applets can't see sys props
setu( "bsh.cwd", "." );
}
// bsh.interactive
setu( "bsh.interactive", new Primitive(interactive) );
// bsh.evalOnly
setu( "bsh.evalOnly", new Primitive(evalOnly) );
}
代码示例来源:origin: jpos/jPOS-EE
private Interpreter initBSH () throws UtilEvalError, EvalError {
Interpreter bsh = new Interpreter ();
BshClassManager bcm = bsh.getClassManager();
bcm.setClassPath(getServer().getLoader().getURLs());
bcm.setClassLoader(getServer().getLoader());
bsh.set ("qbean", this);
bsh.set ("log", getLog());
bsh.eval (getPersist().getChildTextTrim ("init"));
return bsh;
}
private ISOMsg applyRequestProps (ISOMsg m, Interpreter bsh)
代码示例来源:origin: beanshell/beanshell
String className = enclosingNameSpace.isClass ? (enclosingNameSpace.getName() + "$" + name) : name;
String fqClassName = packageName == null ? className : packageName + "." + className;
BshClassManager bcm = interpreter.getClassManager();
内容来源于网络,如有侵权,请联系作者删除!