/** Get dynamic proxy for interface, caching those it creates. */ public Object getInterface( Class clas ) { return getInterface( new Class[] { clas } ); }
/** Get dynamic proxy for interface, caching those it creates. */ public Object getInterface( Class clas ) { return getInterface( new Class[] { clas } ); }
/** * Returns an implementation of an interface using member functions of a * scripting object compiled in the interpreter. The methods of the interface * may be implemented using invoke(Object, String, Object...) method. * * @param thiz The scripting object whose member functions are used to * implement the methods of the interface. * @param clasz The {@code Class} object of the interface to return. * @return An instance of requested interface - null if the requested * interface is unavailable, i. e. if compiled methods in the * {@code ScriptEngine} cannot be found matching the ones in the * requested interface. * @throws IllegalArgumentException if the specified {@code Class} object * does not exist or is not an interface, or if the specified Object is null * or does not represent a scripting object. */ public <T> T getInterface(Object thiz, Class<T> clasz) { if (!(thiz instanceof bsh.This)) { throw new IllegalArgumentException("invalid object type: " + thiz.getClass()); } bsh.This bshThis = (bsh.This) thiz; return clasz.cast(bshThis.getInterface(clasz)); }
/** * Returns an implementation of an interface using member functions of a * scripting object compiled in the interpreter. The methods of the interface * may be implemented using invoke(Object, String, Object...) method. * * @param thiz The scripting object whose member functions are used to * implement the methods of the interface. * @param clasz The {@code Class} object of the interface to return. * @return An instance of requested interface - null if the requested * interface is unavailable, i. e. if compiled methods in the * {@code ScriptEngine} cannot be found matching the ones in the * requested interface. * @throws IllegalArgumentException if the specified {@code Class} object * does not exist or is not an interface, or if the specified Object is null * or does not represent a scripting object. */ @Override public <T> T getInterface(Object thiz, Class<T> clasz) { if (!(thiz instanceof bsh.This)) { throw new IllegalArgumentException("Illegal object type: " + (null == thiz ? "null" : thiz.getClass())); } bsh.This bshThis = (bsh.This) thiz; return clasz.cast(bshThis.getInterface(clasz)); }
/** * Returns an implementation of an interface using procedures compiled in the * interpreter. The methods of the interface may be implemented using the * {@code invoke} method. * * @param clasz The {@code Class} object of the interface to return. * @return An instance of requested interface - null if the requested interface * is unavailable, i. e. if compiled methods in the * {@code ScriptEngine} cannot be found matching the ones in the * requested interface. * @throws IllegalArgumentException if the specified {@code Class} object * does not exist or is not an interface. */ @Override public <T> T getInterface(Class<T> clasz) { return clasz.cast(getGlobal().getInterface(clasz)); }
/** * Returns an implementation of an interface using procedures compiled in the * interpreter. The methods of the interface may be implemented using the * {@code invoke} method. * * @param clasz The {@code Class} object of the interface to return. * @return An instance of requested interface - null if the requested interface * is unavailable, i. e. if compiled methods in the * {@code ScriptEngine} cannot be found matching the ones in the * requested interface. * @throws IllegalArgumentException if the specified {@code Class} object * does not exist or is not an interface. */ public <T> T getInterface(Class<T> clasz) { return clasz.cast(getGlobal().getInterface(clasz)); }
return globalNameSpace.getThis( this ).getInterface( interf );
return globalNameSpace.getThis( this ).getInterface( interf );
public Object constructWithInterfaceBody( BSHAllocationExpression node, Class type, Object[] args, BSHBlock body ) throws EvalError { NameSpace namespace = callstack.top(); NameSpace local = new NameSpace(namespace, "AnonymousBlock"); callstack.push(local); evalBlock(body, true); callstack.pop(); // statical import fields from the interface so that code inside // can refer to the fields directly (e.g. HEIGHT) local.importStatic( type ); return local.getThis(interpreter).getInterface( type ); }
private Object constructWithInterfaceBody( Class type, Object[] args, BSHBlock body, CallStack callstack, Interpreter interpreter ) throws EvalError { NameSpace namespace = callstack.top(); NameSpace local = new NameSpace(namespace, "AnonymousBlock"); callstack.push(local); body.eval( callstack, interpreter, true/*overrideNamespace*/ ); callstack.pop(); // statical import fields from the interface so that code inside // can refer to the fields directly (e.g. HEIGHT) local.importStatic( type ); return local.getThis(interpreter).getInterface( type ); }
/** Helper class for type suffixes. */ public static class Suffix { private static final Map<String, Class<?>> m = Collections.unmodifiableMap(new HashMap<String, Class<?>>() { private static final long serialVersionUID = 1L; { put("O", Byte.TYPE); put("S", Short.TYPE); put("I", Integer.TYPE); put("L", Long.TYPE); put("W", BigInteger.class); put("w", BigDecimal.class); put("d", Double.TYPE); put("f", Float.TYPE); } }); private static String toUpperKey(Character key) { return key.toString().toUpperCase(); } private static String toLowerKey(Character key) { return key.toString().toLowerCase(); } public static boolean isIntegral(Character key) { return m.containsKey(toUpperKey(key)); } public static Class<?> getIntegralType(Character key) { return m.get(toUpperKey(key));
((bsh.This)fromValue).getInterface( toType );