本文整理汇总了Java中org.springframework.scripting.ScriptCompilationException类的典型用法代码示例。如果您正苦于以下问题:Java ScriptCompilationException类的具体用法?Java ScriptCompilationException怎么用?Java ScriptCompilationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptCompilationException类属于org.springframework.scripting包,在下文中一共展示了ScriptCompilationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScriptedObjectType
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Override
public Class<?> getScriptedObjectType(ScriptSource scriptSource)
throws IOException, ScriptCompilationException {
try {
synchronized (this.scriptClassMonitor) {
if (scriptSource.isModified()) {
// New script content: Let's check whether it evaluates to a Class.
this.wasModifiedForTypeCheck = true;
this.scriptClass = BshScriptUtils.determineBshObjectType(
scriptSource.getScriptAsString(), this.beanClassLoader);
}
return this.scriptClass;
}
}
catch (EvalError ex) {
throw new ScriptCompilationException(scriptSource, ex);
}
}
示例2: testScriptedClassThatDoesNotHaveANoArgCtor
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Test
public void testScriptedClassThatDoesNotHaveANoArgCtor() throws Exception {
ScriptSource script = mock(ScriptSource.class);
final String badScript = "class Foo { public Foo(String foo) {}}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX
+ badScript);
try {
factory.getScriptedObject(script);
fail("Must have thrown a ScriptCompilationException (no public no-arg ctor in scripted class).");
}
catch (ScriptCompilationException expected) {
assertTrue(expected.contains(InstantiationException.class));
}
}
示例3: testScriptedClassThatHasNoPublicNoArgCtor
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Test
public void testScriptedClassThatHasNoPublicNoArgCtor() throws Exception {
ScriptSource script = mock(ScriptSource.class);
final String badScript = "class Foo { protected Foo() {}}";
given(script.getScriptAsString()).willReturn(badScript);
given(script.suggestedClassName()).willReturn("someName");
GroovyScriptFactory factory = new GroovyScriptFactory(ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX
+ badScript);
try {
factory.getScriptedObject(script);
fail("Must have thrown a ScriptCompilationException (no oublic no-arg ctor in scripted class).");
}
catch (ScriptCompilationException expected) {
assertTrue(expected.contains(IllegalAccessException.class));
}
}
示例4: getScriptedObjectType
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
public Class<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
synchronized (this.scriptClassMonitor) {
if (this.scriptClass == null || scriptSource.isModified()) {
this.scriptClass = this.groovyClassLoader.parseClass(scriptSource.getScriptAsString());
if (Script.class.isAssignableFrom(this.scriptClass)) {
// A Groovy script, probably creating an instance: let's execute it.
Object result = executeScript(this.scriptClass);
this.scriptResultClass = (result != null ? result.getClass() : null);
} else {
this.scriptResultClass = this.scriptClass;
}
}
return this.scriptResultClass;
}
}
示例5: getScriptedObjectType
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Override
public Class<?> getScriptedObjectType(ScriptSource scriptSource)
throws IOException, ScriptCompilationException {
synchronized (this.scriptClassMonitor) {
try {
if (scriptSource.isModified()) {
// New script content: Let's check whether it evaluates to a Class.
this.wasModifiedForTypeCheck = true;
this.scriptClass = BshScriptUtils.determineBshObjectType(
scriptSource.getScriptAsString(), this.beanClassLoader);
}
return this.scriptClass;
}
catch (EvalError ex) {
this.scriptClass = null;
throw new ScriptCompilationException(scriptSource, ex);
}
}
}
示例6: getScriptedObjectType
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
public Class<?> getScriptedObjectType(ScriptSource scriptSource)
throws IOException, ScriptCompilationException {
try {
synchronized (this.scriptClassMonitor) {
if (scriptSource.isModified()) {
// New script content: Let's check whether it evaluates to a Class.
this.wasModifiedForTypeCheck = true;
this.scriptClass = BshScriptUtils.determineBshObjectType(scriptSource.getScriptAsString());
}
return this.scriptClass;
}
}
catch (EvalError ex) {
throw new ScriptCompilationException(scriptSource, ex);
}
}
示例7: getScriptedObjectType
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
public Class<?> getScriptedObjectType(ScriptSource scriptSource)
throws IOException, ScriptCompilationException {
synchronized (this.scriptClassMonitor) {
if (this.scriptClass == null || scriptSource.isModified()) {
this.scriptClass = this.groovyClassLoader.parseClass(scriptSource.getScriptAsString());
if (Script.class.isAssignableFrom(this.scriptClass)) {
// A Groovy script, probably creating an instance: let's execute it.
Object result = executeScript(this.scriptClass);
this.scriptResultClass = (result != null ? result.getClass() : null);
}
else {
this.scriptResultClass = this.scriptClass;
}
}
return this.scriptResultClass;
}
}
示例8: getScriptedObjectType
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Override
public Class<?> getScriptedObjectType(ScriptSource scriptSource)
throws IOException, ScriptCompilationException {
try {
synchronized (this.scriptClassMonitor) {
if (this.scriptClass == null || scriptSource.isModified()) {
// New script content...
this.wasModifiedForTypeCheck = true;
this.scriptClass = getGroovyClassLoader().parseClass(
scriptSource.getScriptAsString(), scriptSource.suggestedClassName());
if (Script.class.isAssignableFrom(this.scriptClass)) {
// A Groovy script, probably creating an instance: let's execute it.
Object result = executeScript(scriptSource, this.scriptClass);
this.scriptResultClass = (result != null ? result.getClass() : null);
this.cachedResult = new CachedResultHolder(result);
}
else {
this.scriptResultClass = this.scriptClass;
}
}
return this.scriptResultClass;
}
}
catch (CompilationFailedException ex) {
throw new ScriptCompilationException(scriptSource, ex);
}
}
示例9: evaluateScript
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
protected Object evaluateScript(ScriptSource scriptSource) {
try {
if (this.scriptEngine == null) {
this.scriptEngine = retrieveScriptEngine(scriptSource);
if (this.scriptEngine == null) {
throw new IllegalStateException("Could not determine script engine for " + scriptSource);
}
}
return this.scriptEngine.eval(scriptSource.getScriptAsString());
}
catch (Exception ex) {
throw new ScriptCompilationException(scriptSource, ex);
}
}
示例10: adaptToInterfaces
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
protected Object adaptToInterfaces(Object script, ScriptSource scriptSource, Class<?>... actualInterfaces) {
Class<?> adaptedIfc;
if (actualInterfaces.length == 1) {
adaptedIfc = actualInterfaces[0];
}
else {
adaptedIfc = ClassUtils.createCompositeInterface(actualInterfaces, this.beanClassLoader);
}
if (adaptedIfc != null) {
if (!(this.scriptEngine instanceof Invocable)) {
throw new ScriptCompilationException(scriptSource,
"ScriptEngine must implement Invocable in order to adapt it to an interface: " +
this.scriptEngine);
}
Invocable invocable = (Invocable) this.scriptEngine;
if (script != null) {
script = invocable.getInterface(script, adaptedIfc);
}
if (script == null) {
script = invocable.getInterface(adaptedIfc);
if (script == null) {
throw new ScriptCompilationException(scriptSource,
"Could not adapt script to interface [" + adaptedIfc.getName() + "]");
}
}
}
return script;
}
示例11: testScriptCompilationException
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Test
public void testScriptCompilationException() throws Exception {
try {
new ClassPathXmlApplicationContext("jrubyBrokenContext.xml", getClass());
fail("Should throw exception for broken script file");
}
catch (BeanCreationException ex) {
assertTrue(ex.contains(ScriptCompilationException.class));
}
}
示例12: testForRefreshedScriptHavingErrorPickedUpOnFirstCall
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Test
public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
collaboratorBuilder.addPropertyReference(MESSENGER_BEAN_NAME, MESSENGER_BEAN_NAME);
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition(PROCESSOR_BEAN_NAME, processorBeanDefinition);
ctx.registerBeanDefinition(MESSENGER_BEAN_NAME, scriptedBeanDefinition);
final String collaboratorBeanName = "collaborator";
ctx.registerBeanDefinition(collaboratorBeanName, collaboratorBuilder.getBeanDefinition());
ctx.refresh();
Messenger messenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertEquals(MESSAGE_TEXT, messenger.getMessage());
// cool; now let's change the script and check the refresh behaviour...
pauseToLetRefreshDelayKickIn(DEFAULT_SECONDS_TO_PAUSE);
StaticScriptSource source = getScriptSource(ctx);
// needs The Sundays compiler; must NOT throw any exception here...
source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea");
Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
try {
refreshedMessenger.getMessage();
fail("Must have thrown an Exception (invalid script)");
}
catch (FatalBeanException expected) {
assertTrue(expected.contains(ScriptCompilationException.class));
}
}
示例13: testScriptCompilationException
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Test
public void testScriptCompilationException() throws Exception {
try {
new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyBrokenContext.xml");
fail("Should throw exception for broken script file");
}
catch (NestedRuntimeException ex) {
assertTrue("Wrong root cause: " + ex, ex.contains(ScriptCompilationException.class));
}
}
示例14: scriptCompilationException
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
@Test
public void scriptCompilationException() throws Exception {
try {
new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml");
fail("Must throw exception for broken script file");
}
catch (NestedRuntimeException ex) {
assertTrue(ex.contains(ScriptCompilationException.class));
}
}
示例15: getScriptedObject
import org.springframework.scripting.ScriptCompilationException; //导入依赖的package包/类
/**
* Load and parse the Rhino script via RhinoScriptUtils.
*
*/
public Object getScriptedObject(ScriptSource actualScriptSource, Class<?>... actualInterfaces) throws IOException, ScriptCompilationException {
log.debug("Getting scripted object...");
try {
return RhinoScriptUtils.createRhinoObject(actualScriptSource.getScriptAsString(), actualInterfaces, extendedClass);
} catch (Exception ex) {
throw new ScriptCompilationException("Could not compile Rhino script: " + actualScriptSource, ex);
}
}