|
16 | 16 | import java.lang.reflect.UndeclaredThrowableException;
|
17 | 17 |
|
18 | 18 | import javax.script.Bindings;
|
| 19 | +import javax.script.Compilable; |
| 20 | +import javax.script.CompiledScript; |
19 | 21 | import javax.script.Invocable;
|
20 | 22 | import javax.script.ScriptContext;
|
21 | 23 | import javax.script.ScriptEngine;
|
22 | 24 | import javax.script.ScriptException;
|
23 | 25 |
|
24 | 26 | /**
|
25 |
| - * Delegate allowing AOP-style interception of calls, either before Invocation, or upon a {@link ScriptException}. |
26 |
| - * being thrown. |
| 27 | + * Delegate allowing AOP-style interception of calls, either before Invocation, or upon a {@link ScriptException} being |
| 28 | + * thrown. |
27 | 29 | *
|
28 | 30 | * @param <T> The delegate class
|
29 | 31 | * @author Jonathan Gilbert - Initial contribution
|
30 | 32 | */
|
31 |
| -public abstract class InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable<T extends ScriptEngine & Invocable & AutoCloseable> |
32 |
| - extends DelegatingScriptEngineWithInvocableAndAutocloseable<T> { |
| 33 | +public abstract class InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable<T extends ScriptEngine & Invocable & Compilable & AutoCloseable> |
| 34 | + extends DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable<T> { |
33 | 35 |
|
34 |
| - public InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable(T delegate) { |
| 36 | + public InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable(T delegate) { |
35 | 37 | super(delegate);
|
36 | 38 | }
|
37 | 39 |
|
@@ -155,4 +157,28 @@ public Object invokeFunction(String s, Object... objects)
|
155 | 157 | throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions
|
156 | 158 | }
|
157 | 159 | }
|
| 160 | + |
| 161 | + @Override |
| 162 | + public CompiledScript compile(String s) throws ScriptException { |
| 163 | + try { |
| 164 | + beforeInvocation(); |
| 165 | + return (CompiledScript) afterInvocation(super.compile(s)); |
| 166 | + } catch (ScriptException se) { |
| 167 | + throw (ScriptException) afterThrowsInvocation(se); |
| 168 | + } catch (Exception e) { |
| 169 | + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + @Override |
| 174 | + public CompiledScript compile(Reader reader) throws ScriptException { |
| 175 | + try { |
| 176 | + beforeInvocation(); |
| 177 | + return (CompiledScript) afterInvocation(super.compile(reader)); |
| 178 | + } catch (ScriptException se) { |
| 179 | + throw (ScriptException) afterThrowsInvocation(se); |
| 180 | + } catch (Exception e) { |
| 181 | + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions |
| 182 | + } |
| 183 | + } |
158 | 184 | }
|
0 commit comments