当前位置: 首页>>代码示例>>Java>>正文


Java ScriptSource类代码示例

本文整理汇总了Java中org.springframework.scripting.ScriptSource的典型用法代码示例。如果您正苦于以下问题:Java ScriptSource类的具体用法?Java ScriptSource怎么用?Java ScriptSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScriptSource类属于org.springframework.scripting包,在下文中一共展示了ScriptSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getScriptedObjectType

import org.springframework.scripting.ScriptSource; //导入依赖的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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:BshScriptFactory.java

示例2: retrieveScriptEngine

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
protected ScriptEngine retrieveScriptEngine(ScriptSource scriptSource) {
	ScriptEngineManager scriptEngineManager = new ScriptEngineManager(this.beanClassLoader);

	if (this.scriptEngineName != null) {
		return StandardScriptUtils.retrieveEngineByName(scriptEngineManager, this.scriptEngineName);
	}

	if (scriptSource instanceof ResourceScriptSource) {
		String filename = ((ResourceScriptSource) scriptSource).getResource().getFilename();
		if (filename != null) {
			String extension = StringUtils.getFilenameExtension(filename);
			if (extension != null) {
				ScriptEngine engine = scriptEngineManager.getEngineByExtension(extension);
				if (engine != null) {
					return engine;
				}
			}
		}
	}

	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:StandardScriptFactory.java

示例3: testScriptedClassThatDoesNotHaveANoArgCtor

import org.springframework.scripting.ScriptSource; //导入依赖的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));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:GroovyScriptFactoryTests.java

示例4: testScriptedClassThatHasNoPublicNoArgCtor

import org.springframework.scripting.ScriptSource; //导入依赖的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));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:GroovyScriptFactoryTests.java

示例5: scriptThatCompilesButIsJustPlainBad

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
@Test
public void scriptThatCompilesButIsJustPlainBad() throws Exception {
	ScriptSource script = mock(ScriptSource.class);
	final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
	given(script.getScriptAsString()).willReturn(badScript);
	given(script.isModified()).willReturn(true);
	BshScriptFactory factory = new BshScriptFactory(
			ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript, Messenger.class);
	try {
		Messenger messenger = (Messenger) factory.getScriptedObject(script, Messenger.class);
		messenger.getMessage();
		fail("Must have thrown a BshScriptUtils.BshExecutionException.");
	}
	catch (BshScriptUtils.BshExecutionException expected) {
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:BshScriptFactoryTests.java

示例6: getScriptedObjectType

import org.springframework.scripting.ScriptSource; //导入依赖的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;
        }
    }
 
开发者ID:Red5,项目名称:red5-server-scripting,代码行数:18,代码来源:GroovyScriptFactory.java

示例7: getScriptedObjectType

import org.springframework.scripting.ScriptSource; //导入依赖的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);
		}
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:21,代码来源:BshScriptFactory.java

示例8: getScriptedObjectType

import org.springframework.scripting.ScriptSource; //导入依赖的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);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:18,代码来源:BshScriptFactory.java

示例9: testScriptThatCompilesButIsJustPlainBad

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
public void testScriptThatCompilesButIsJustPlainBad() throws Exception {
	ScriptSource script = mock(ScriptSource.class);
	final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
	given(script.getScriptAsString()).willReturn(badScript);
	given(script.isModified()).willReturn(true);
	BshScriptFactory factory = new BshScriptFactory(
			ScriptFactoryPostProcessor.INLINE_SCRIPT_PREFIX + badScript,
			new Class<?>[] {Messenger.class});
	try {
		Messenger messenger = (Messenger) factory.getScriptedObject(script, new Class<?>[]{Messenger.class});
		messenger.getMessage();
		fail("Must have thrown a BshScriptUtils.BshExecutionException.");
	}
	catch (BshScriptUtils.BshExecutionException expected) {
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:BshScriptFactoryTests.java

示例10: getScriptedObjectType

import org.springframework.scripting.ScriptSource; //导入依赖的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;
	}
}
 
开发者ID:cwpenhale,项目名称:red5-mobileconsole,代码行数:20,代码来源:GroovyScriptFactory.java

示例11: RefreshableScriptTargetSource

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
/**
 * Create a new RefreshableScriptTargetSource.
 * @param beanFactory the BeanFactory to fetch the scripted bean from
 * @param beanName the name of the target bean
 * @param scriptFactory the ScriptFactory to delegate to for determining
 * whether a refresh is required
 * @param scriptSource the ScriptSource for the script definition
 * @param isFactoryBean whether the target script defines a FactoryBean
 */
public RefreshableScriptTargetSource(BeanFactory beanFactory, String beanName,
		ScriptFactory scriptFactory, ScriptSource scriptSource, boolean isFactoryBean) {

	super(beanFactory, beanName);
	Assert.notNull(scriptFactory, "ScriptFactory must not be null");
	Assert.notNull(scriptSource, "ScriptSource must not be null");
	this.scriptFactory = scriptFactory;
	this.scriptSource = scriptSource;
	this.isFactoryBean = isFactoryBean;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:RefreshableScriptTargetSource.java

示例12: prepareScriptBeans

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
/**
 * Prepare the script beans in the internal BeanFactory that this
 * post-processor uses. Each original bean definition will be split
 * into a ScriptFactory definition and a scripted object definition.
 * @param bd the original bean definition in the main BeanFactory
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptedObjectBeanName the name of the internal scripted object bean
 */
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) {

	// Avoid recreation of the script bean definition in case of a prototype.
	synchronized (this.scriptBeanFactory) {
		if (!this.scriptBeanFactory.containsBeanDefinition(scriptedObjectBeanName)) {

			this.scriptBeanFactory.registerBeanDefinition(scriptFactoryBeanName,
					createScriptFactoryBeanDefinition(bd));
			ScriptFactory scriptFactory = this.scriptBeanFactory
					.getBean(scriptFactoryBeanName, ScriptFactory.class);
			ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName,
					scriptFactory.getScriptSourceLocator());
			Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

			Class<?>[] scriptedInterfaces = interfaces;
			if (scriptFactory.requiresConfigInterface() && !bd.getPropertyValues().isEmpty()) {
				Class<?> configInterface = createConfigInterface(bd, interfaces);
				scriptedInterfaces = ObjectUtils.addObjectToArray(interfaces, configInterface);
			}

			BeanDefinition objectBd = createScriptedObjectBeanDefinition(bd, scriptFactoryBeanName, scriptSource,
					scriptedInterfaces);
			long refreshCheckDelay = resolveRefreshCheckDelay(bd);
			if (refreshCheckDelay >= 0) {
				objectBd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
			}

			this.scriptBeanFactory.registerBeanDefinition(scriptedObjectBeanName, objectBd);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:ScriptFactoryPostProcessor.java

示例13: getScriptSource

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
/**
 * Obtain a ScriptSource for the given bean, lazily creating it
 * if not cached already.
 * @param beanName the name of the scripted bean
 * @param scriptSourceLocator the script source locator associated with the bean
 * @return the corresponding ScriptSource instance
 * @see #convertToScriptSource
 */
protected ScriptSource getScriptSource(String beanName, String scriptSourceLocator) {
	synchronized (this.scriptSourceCache) {
		ScriptSource scriptSource = this.scriptSourceCache.get(beanName);
		if (scriptSource == null) {
			scriptSource = convertToScriptSource(beanName, scriptSourceLocator, this.resourceLoader);
			this.scriptSourceCache.put(beanName, scriptSource);
		}
		return scriptSource;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:ScriptFactoryPostProcessor.java

示例14: convertToScriptSource

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
/**
 * Convert the given script source locator to a ScriptSource instance.
 * <p>By default, supported locators are Spring resource locations
 * (such as "file:C:/myScript.bsh" or "classpath:myPackage/myScript.bsh")
 * and inline scripts ("inline:myScriptText...").
 * @param beanName the name of the scripted bean
 * @param scriptSourceLocator the script source locator
 * @param resourceLoader the ResourceLoader to use (if necessary)
 * @return the ScriptSource instance
 */
protected ScriptSource convertToScriptSource(String beanName, String scriptSourceLocator,
		ResourceLoader resourceLoader) {

	if (scriptSourceLocator.startsWith(INLINE_SCRIPT_PREFIX)) {
		return new StaticScriptSource(scriptSourceLocator.substring(INLINE_SCRIPT_PREFIX.length()), beanName);
	}
	else {
		return new ResourceScriptSource(resourceLoader.getResource(scriptSourceLocator));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:ScriptFactoryPostProcessor.java

示例15: createScriptedObjectBeanDefinition

import org.springframework.scripting.ScriptSource; //导入依赖的package包/类
/**
 * Create a bean definition for the scripted object, based on the given script
 * definition, extracting the definition data that is relevant for the scripted
 * object (that is, everything but bean class and constructor arguments).
 * @param bd the full script bean definition
 * @param scriptFactoryBeanName the name of the internal ScriptFactory bean
 * @param scriptSource the ScriptSource for the scripted bean
 * @param interfaces the interfaces that the scripted bean is supposed to implement
 * @return the extracted ScriptFactory bean definition
 * @see org.springframework.scripting.ScriptFactory#getScriptedObject
 */
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName,
		ScriptSource scriptSource, Class<?>[] interfaces) {

	GenericBeanDefinition objectBd = new GenericBeanDefinition(bd);
	objectBd.setFactoryBeanName(scriptFactoryBeanName);
	objectBd.setFactoryMethodName("getScriptedObject");
	objectBd.getConstructorArgumentValues().clear();
	objectBd.getConstructorArgumentValues().addIndexedArgumentValue(0, scriptSource);
	objectBd.getConstructorArgumentValues().addIndexedArgumentValue(1, interfaces);
	return objectBd;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:ScriptFactoryPostProcessor.java


注:本文中的org.springframework.scripting.ScriptSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。