public Object apply()

in src/main/java/org/apache/bsf/engines/jython/JythonEngine.java [90:121]


    public Object apply(final String source, final int lineNo, final int columnNo, final Object funcBody, final Vector paramNames, final Vector arguments)
            throws BSFException {
        try {
            /*
             * We wrapper the original script in a function definition, and evaluate the function. A hack, no question, but it allows apply() to pretend to work
             * on Jython.
             */
            final StringBuilder script = new StringBuilder(byteify(funcBody.toString()));
            int index = 0;
            script.insert(0, "def bsf_temp_fn():\n");

            while (index < script.length()) {
                if (script.charAt(index) == '\n') {
                    script.insert(index + 1, '\t');
                }
                index++;
            }

            final String scriptStr = script.toString();
            importPackage(scriptStr);
            interp.exec(scriptStr);

            Object result = interp.eval("bsf_temp_fn()");

            if (result instanceof PyJavaInstance) {
                result = ((PyJavaInstance) result).__tojava__(Object.class);
            }
            return result;
        } catch (final PyException e) {
            throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Jython:\n" + e, e);
        }
    }