/** * Create a new BeanShell-scripted object from the given script source. * <p>The script may either be a simple script that needs a corresponding proxy * generated (implementing the specified interfaces), or declare a full class * or return an actual instance of the scripted object (in which case the * specified interfaces, if any, need to be implemented by that class/instance). * @param scriptSource the script source text * @param scriptInterfaces the interfaces that the scripted Java object is * supposed to implement (may be {@code null} or empty if the script itself * declares a full class or returns an actual instance of the scripted object) * @param classLoader the ClassLoader to use for evaluating the script * @return the scripted Java object * @throws EvalError in case of BeanShell parsing failure */ public static Object createBshObject(String scriptSource, @Nullable Class<?>[] scriptInterfaces, @Nullable ClassLoader classLoader) throws EvalError { Object result = evaluateBshScript(scriptSource, scriptInterfaces, classLoader); if (result instanceof Class) { Class<?> clazz = (Class<?>) result; try { return ReflectionUtils.accessibleConstructor(clazz).newInstance(); } catch (Throwable ex) { throw new IllegalStateException("Could not instantiate script class: " + clazz.getName(), ex); } } else { return result; } }
/** * Create a new BeanShell-scripted object from the given script source. * <p>The script may either be a simple script that needs a corresponding proxy * generated (implementing the specified interfaces), or declare a full class * or return an actual instance of the scripted object (in which case the * specified interfaces, if any, need to be implemented by that class/instance). * @param scriptSource the script source text * @param scriptInterfaces the interfaces that the scripted Java object is * supposed to implement (may be {@code null} or empty if the script itself * declares a full class or returns an actual instance of the scripted object) * @param classLoader the ClassLoader to use for evaluating the script * @return the scripted Java object * @throws EvalError in case of BeanShell parsing failure */ public static Object createBshObject(String scriptSource, @Nullable Class<?>[] scriptInterfaces, @Nullable ClassLoader classLoader) throws EvalError { Object result = evaluateBshScript(scriptSource, scriptInterfaces, classLoader); if (result instanceof Class) { Class<?> clazz = (Class<?>) result; try { return ReflectionUtils.accessibleConstructor(clazz).newInstance(); } catch (Throwable ex) { throw new IllegalStateException("Could not instantiate script class: " + clazz.getName(), ex); } } else { return result; } }
Object result = BshScriptUtils.evaluateBshScript( scriptSource.getScriptAsString(), actualInterfaces, this.beanClassLoader); if (result instanceof Class) {
Object result = BshScriptUtils.evaluateBshScript( scriptSource.getScriptAsString(), actualInterfaces, this.beanClassLoader); if (result instanceof Class) {
/** * Create a new BeanShell-scripted object from the given script source. * <p>The script may either be a simple script that needs a corresponding proxy * generated (implementing the specified interfaces), or declare a full class * or return an actual instance of the scripted object (in which case the * specified interfaces, if any, need to be implemented by that class/instance). * @param scriptSource the script source text * @param scriptInterfaces the interfaces that the scripted Java object is * supposed to implement (may be {@code null} or empty if the script itself * declares a full class or returns an actual instance of the scripted object) * @param classLoader the ClassLoader to use for evaluating the script * @return the scripted Java object * @throws EvalError in case of BeanShell parsing failure */ public static Object createBshObject(String scriptSource, @Nullable Class<?>[] scriptInterfaces, @Nullable ClassLoader classLoader) throws EvalError { Object result = evaluateBshScript(scriptSource, scriptInterfaces, classLoader); if (result instanceof Class) { Class<?> clazz = (Class<?>) result; try { return ReflectionUtils.accessibleConstructor(clazz).newInstance(); } catch (Throwable ex) { throw new IllegalStateException("Could not instantiate script class: " + clazz.getName(), ex); } } else { return result; } }
Object result = BshScriptUtils.evaluateBshScript( scriptSource.getScriptAsString(), actualInterfaces, this.beanClassLoader); if (result instanceof Class) {