List of usage examples for org.springframework.scripting ScriptCompilationException ScriptCompilationException
public ScriptCompilationException(String msg)
From source file:org.romaz.spring.scripting.ext.rhino.RhinoScriptFactoryUtils.java
/** * Uses Rhino JavaAdapter facility to create the proxy object. * Seems to cause problems with property injection. * /*from ww w . j a v a2 s .c o m*/ * @deprecated * @param ctx * @param scope * @param result * @param interfacesToImplement * @return */ public static Object createRhinoJavaAdapter(Context ctx, Scriptable scope, Object result, Class[] interfacesToImplement) { Object adapter = ctx.newObject(scope, "JavaAdapter", createJavaAdapterArgs(scope, interfacesToImplement, result)); if (adapter instanceof NativeJavaObject) { return ((NativeJavaObject) adapter).unwrap(); } throw new ScriptCompilationException( "Expected a NativeJavaObject, but it was [" + adapter.getClass() + "]"); }
From source file:org.romaz.spring.scripting.ext.rhino.RhinoScriptFactoryUtils.java
/** * Creates a proxy for the script, implementing all requested interfaces. * //w w w. java2 s.co m * @param ctx * @param scope * @param result * @param interfacesToImplement * @param converter * @return */ public static Object createScriptProxy(Context ctx, Scriptable scope, Object result, Class[] interfacesToImplement, RhinoObjectConverter converter) { if (!(result instanceof Scriptable)) { throw new ScriptCompilationException( "Script execution result must be an instance of Scriptable, it was [" + result.getClass() + "]"); } final Scriptable delegate = (Scriptable) result; return Proxy.newProxyInstance(ClassUtils.getDefaultClassLoader(), interfacesToImplement, new JsObjectMethodInvocationHandler(delegate, scope, converter)); }
From source file:org.red5.server.script.jython.JythonScriptFactory.java
/** {@inheritDoc} */ @SuppressWarnings({ "rawtypes" }) public Object getScriptedObject(ScriptSource scriptSourceLocator, Class[] scriptInterfaces) throws IOException, ScriptCompilationException { String basePath = ""; /* TODO: how to do this when running under Tomcat? ContextHandler handler = WebAppContext.getCurrentWebAppContext(); if (handler != null) {//from www . ja va 2s. c o m File root = handler.getBaseResource().getFile(); if (root != null && root.exists()) { basePath = root.getAbsolutePath() + File.separator + "WEB-INF" + File.separator; } } */ String strScript = scriptSourceLocator.getScriptAsString(); if (scriptInterfaces.length > 0) { try { PySystemState state = new PySystemState(); if (!"".equals(basePath)) { // Add webapp paths that can contain classes and .jar files to python search path state.path.insert(0, Py.newString(basePath + "classes")); File jarRoot = new File(basePath + "lib"); if (jarRoot.exists()) { for (String filename : jarRoot.list(new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(".jar")); } })) { state.path.insert(1, Py.newString(basePath + "lib" + File.separator + filename)); } } } PythonInterpreter interp = new PythonInterpreter(null, state); interp.exec(strScript); PyObject getInstance = interp.get("getInstance"); if (!(getInstance instanceof PyFunction)) { throw new ScriptCompilationException("\"getInstance\" is not a function."); } PyObject _this; if (arguments == null) { _this = ((PyFunction) getInstance).__call__(); } else { PyObject[] args = new PyObject[arguments.length]; for (int i = 0; i < arguments.length; i++) { args[i] = PyJavaType.wrapJavaObject(arguments[i]); } _this = ((PyFunction) getInstance).__call__(args); } return _this.__tojava__(scriptInterfaces[0]); } catch (Exception ex) { logger.error("Error while loading script.", ex); if (ex instanceof IOException) { // Raise to caller throw (IOException) ex; } else if (ex instanceof ScriptCompilationException) { // Raise to caller throw (ScriptCompilationException) ex; } throw new ScriptCompilationException(ex.getMessage()); } } logger.error("No scriptInterfaces provided."); return null; }