|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -119,9 +119,9 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { |
|
|
|
public Object getScriptedObject(ScriptSource scriptSource, Class<?>... actualInterfaces) |
|
|
|
public Object getScriptedObject(ScriptSource scriptSource, Class<?>... actualInterfaces) |
|
|
|
throws IOException, ScriptCompilationException { |
|
|
|
throws IOException, ScriptCompilationException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
Class<?> clazz; |
|
|
|
Class<?> clazz; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
synchronized (this.scriptClassMonitor) { |
|
|
|
synchronized (this.scriptClassMonitor) { |
|
|
|
boolean requiresScriptEvaluation = (this.wasModifiedForTypeCheck && this.scriptClass == null); |
|
|
|
boolean requiresScriptEvaluation = (this.wasModifiedForTypeCheck && this.scriptClass == null); |
|
|
|
this.wasModifiedForTypeCheck = false; |
|
|
|
this.wasModifiedForTypeCheck = false; |
|
|
|
@ -145,25 +145,31 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { |
|
|
|
} |
|
|
|
} |
|
|
|
clazz = this.scriptClass; |
|
|
|
clazz = this.scriptClass; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (EvalError ex) { |
|
|
|
|
|
|
|
this.scriptClass = null; |
|
|
|
|
|
|
|
throw new ScriptCompilationException(scriptSource, ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (clazz != null) { |
|
|
|
if (clazz != null) { |
|
|
|
// A Class: We need to create an instance for every call.
|
|
|
|
// A Class: We need to create an instance for every call.
|
|
|
|
try { |
|
|
|
try { |
|
|
|
return clazz.newInstance(); |
|
|
|
return clazz.newInstance(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
throw new ScriptCompilationException( |
|
|
|
throw new ScriptCompilationException( |
|
|
|
scriptSource, "Could not instantiate script class: " + clazz.getName(), ex); |
|
|
|
scriptSource, "Could not instantiate script class: " + clazz.getName(), ex); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
} |
|
|
|
// Not a Class: We need to evaluate the script for every call.
|
|
|
|
else { |
|
|
|
|
|
|
|
// Not a Class: We need to evaluate the script for every call.
|
|
|
|
|
|
|
|
try { |
|
|
|
return BshScriptUtils.createBshObject( |
|
|
|
return BshScriptUtils.createBshObject( |
|
|
|
scriptSource.getScriptAsString(), actualInterfaces, this.beanClassLoader); |
|
|
|
scriptSource.getScriptAsString(), actualInterfaces, this.beanClassLoader); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (EvalError ex) { |
|
|
|
catch (EvalError ex) { |
|
|
|
throw new ScriptCompilationException(scriptSource, ex); |
|
|
|
throw new ScriptCompilationException(scriptSource, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -171,8 +177,8 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { |
|
|
|
public Class<?> getScriptedObjectType(ScriptSource scriptSource) |
|
|
|
public Class<?> getScriptedObjectType(ScriptSource scriptSource) |
|
|
|
throws IOException, ScriptCompilationException { |
|
|
|
throws IOException, ScriptCompilationException { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
synchronized (this.scriptClassMonitor) { |
|
|
|
synchronized (this.scriptClassMonitor) { |
|
|
|
try { |
|
|
|
if (scriptSource.isModified()) { |
|
|
|
if (scriptSource.isModified()) { |
|
|
|
// New script content: Let's check whether it evaluates to a Class.
|
|
|
|
// New script content: Let's check whether it evaluates to a Class.
|
|
|
|
this.wasModifiedForTypeCheck = true; |
|
|
|
this.wasModifiedForTypeCheck = true; |
|
|
|
@ -181,9 +187,10 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { |
|
|
|
} |
|
|
|
} |
|
|
|
return this.scriptClass; |
|
|
|
return this.scriptClass; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (EvalError ex) { |
|
|
|
catch (EvalError ex) { |
|
|
|
this.scriptClass = null; |
|
|
|
throw new ScriptCompilationException(scriptSource, ex); |
|
|
|
throw new ScriptCompilationException(scriptSource, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|