类 ScriptFactoryPostProcessor
- 所有已实现的接口:
Aware,BeanClassLoaderAware,BeanFactoryAware,BeanPostProcessor,InstantiationAwareBeanPostProcessor,SmartInstantiationAwareBeanPostProcessor,DisposableBean,ResourceLoaderAware,cn.taketoday.core.Ordered
BeanPostProcessor that
handles ScriptFactory definitions,
replacing each factory with the actual scripted Java object generated by it.
This is similar to the
FactoryBean mechanism, but is
specifically tailored for scripts and not built into Framework's core
container itself but rather implemented as an extension.
NOTE: The most important characteristic of this post-processor
is that constructor arguments are applied to the
ScriptFactory instance
while bean property values are applied to the generated scripted object.
Typically, constructor arguments include a script source locator and
potentially script interfaces, while bean property values include
references and config values to inject into the scripted object itself.
The following ScriptFactoryPostProcessor will automatically
be applied to the two
ScriptFactory definitions below.
At runtime, the actual scripted objects will be exposed for
"bshMessenger" and "groovyMessenger", rather than the
ScriptFactory instances. Both of
those are supposed to be castable to the example's Messenger
interfaces here.
<bean class="cn.taketoday.scripting.support.ScriptFactoryPostProcessor"/> <bean id="bshMessenger" class="cn.taketoday.scripting.bsh.BshScriptFactory"> <constructor-arg value="classpath:mypackage/Messenger.bsh"/> <constructor-arg value="mypackage.Messenger"/> <property name="message" value="Hello World!"/> </bean> <bean id="groovyMessenger" class="cn.taketoday.scripting.groovy.GroovyScriptFactory"> <constructor-arg value="classpath:mypackage/Messenger.groovy"/> <property name="message" value="Hello World!"/> </bean>
NOTE: Please note that the above excerpt from a Framework
XML bean definition file uses just the <bean/>-style syntax
(in an effort to illustrate using the ScriptFactoryPostProcessor itself).
In reality, you would never create a <bean/> definition for a
ScriptFactoryPostProcessor explicitly; rather you would import the
tags from the 'lang' namespace and simply create scripted
beans using the tags in that namespace... as part of doing so, a
ScriptFactoryPostProcessor will implicitly be created for you.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller, Rob Harrop, Rick Evans, Mark Fisher, Sam Brannen
-
字段概要
字段修饰符和类型字段说明static final StringTheResource-style prefix that denotes an inline script.static final StringThelanguageattribute.protected final cn.taketoday.logging.LoggerLogger available to subclasses.static final StringTheproxyTargetClassattribute.static final StringTherefreshCheckDelayattribute.从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected ScriptSourceconvertToScriptSource(String beanName, String scriptSourceLocator, cn.taketoday.core.io.ResourceLoader resourceLoader) Convert the given script source locator to a ScriptSource instance.protected Class<?>createCompositeInterface(Class<?>[] interfaces) Create a composite interface Class for the given interfaces, implementing the given interfaces in one single Class.protected Class<?>createConfigInterface(BeanDefinition bd, Class<?>[] interfaces) Create a config interface for the given bean definition, defining setter methods for the defined property values as well as an init method and a destroy method (if defined).protected ObjectcreateRefreshableProxy(TargetSource ts, Class<?>[] interfaces, boolean proxyTargetClass) Create a refreshable proxy for the given AOP TargetSource.protected BeanDefinitioncreateScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName, ScriptSource scriptSource, Class<?>[] interfaces) 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).protected BeanDefinitionCreate a ScriptFactory bean definition based on the given script definition, extracting only the definition data that is relevant for the ScriptFactory (that is, only bean class and constructor arguments).voiddestroy()Destroy the inner bean factory (used for scripts) on shutdown.intgetOrder()protected ScriptSourcegetScriptSource(String beanName, String scriptSourceLocator) Obtain a ScriptSource for the given bean, lazily creating it if not cached already.postProcessBeforeInstantiation(Class<?> beanClass, String beanName) Class<?>predictBeanType(Class<?> beanClass, String beanName) protected voidprepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) Prepare the script beans in the internal BeanFactory that this post-processor uses.protected booleanresolveProxyTargetClass(BeanDefinition beanDefinition) protected longresolveRefreshCheckDelay(BeanDefinition beanDefinition) Get the refresh check delay for the givenScriptFactoryBeanDefinition.voidsetBeanClassLoader(ClassLoader classLoader) voidsetBeanFactory(BeanFactory beanFactory) voidsetDefaultProxyTargetClass(boolean defaultProxyTargetClass) Flag to signal that refreshable proxies should be created to proxy the target class not its interfaces.voidsetDefaultRefreshCheckDelay(long defaultRefreshCheckDelay) Set the delay between refresh checks, in milliseconds.voidsetResourceLoader(cn.taketoday.core.io.ResourceLoader resourceLoader) Set the ResourceLoader that this object runs in.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.beans.factory.config.InstantiationAwareBeanPostProcessor
postProcessAfterInstantiation从接口继承的方法 cn.taketoday.beans.factory.config.SmartInstantiationAwareBeanPostProcessor
determineCandidateConstructors, getEarlyBeanReference
-
字段详细资料
-
INLINE_SCRIPT_PREFIX
TheResource-style prefix that denotes an inline script.An inline script is a script that is defined right there in the (typically XML) configuration, as opposed to being defined in an external file.
- 另请参阅:
-
REFRESH_CHECK_DELAY_ATTRIBUTE
TherefreshCheckDelayattribute. -
PROXY_TARGET_CLASS_ATTRIBUTE
TheproxyTargetClassattribute. -
LANGUAGE_ATTRIBUTE
Thelanguageattribute. -
logger
protected final cn.taketoday.logging.Logger loggerLogger available to subclasses.
-
-
构造器详细资料
-
ScriptFactoryPostProcessor
public ScriptFactoryPostProcessor()
-
-
方法详细资料
-
setDefaultRefreshCheckDelay
public void setDefaultRefreshCheckDelay(long defaultRefreshCheckDelay) Set the delay between refresh checks, in milliseconds. Default is -1, indicating no refresh checks at all.Note that an actual refresh will only happen when the
ScriptSourceindicates that it has been modified. -
setDefaultProxyTargetClass
public void setDefaultProxyTargetClass(boolean defaultProxyTargetClass) Flag to signal that refreshable proxies should be created to proxy the target class not its interfaces.- 参数:
defaultProxyTargetClass- the flag value to set
-
setBeanClassLoader
- 指定者:
setBeanClassLoader在接口中BeanClassLoaderAware
-
setBeanFactory
- 指定者:
setBeanFactory在接口中BeanFactoryAware
-
setResourceLoader
public void setResourceLoader(cn.taketoday.core.io.ResourceLoader resourceLoader) 从接口复制的说明:ResourceLoaderAwareSet the ResourceLoader that this object runs in.This might be a ResourcePatternResolver, which can be checked through
instanceof ResourcePatternResolver. See also theResourcePatternUtils.getResourcePatternResolvermethod.Invoked after population of normal bean properties but before an init callback like InitializingBean's
afterPropertiesSetor a custom init-method. Invoked before ApplicationContextAware'ssetApplicationContext.- 指定者:
setResourceLoader在接口中ResourceLoaderAware- 参数:
resourceLoader- the ResourceLoader object to be used by this object- 另请参阅:
-
PatternResourceLoaderPatternResourceLoader.fromResourceLoader(cn.taketoday.core.io.ResourceLoader)
-
getOrder
public int getOrder()- 指定者:
getOrder在接口中cn.taketoday.core.Ordered
-
predictBeanType
-
postProcessBeforeInstantiation
-
prepareScriptBeans
protected void prepareScriptBeans(BeanDefinition bd, String scriptFactoryBeanName, String scriptedObjectBeanName) 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.- 参数:
bd- the original bean definition in the main BeanFactoryscriptFactoryBeanName- the name of the internal ScriptFactory beanscriptedObjectBeanName- the name of the internal scripted object bean
-
resolveRefreshCheckDelay
Get the refresh check delay for the givenScriptFactoryBeanDefinition. If theBeanDefinitionhas ametadata attributeunder the keyREFRESH_CHECK_DELAY_ATTRIBUTEwhich is a validNumbertype, then this value is used. Otherwise, thedefaultRefreshCheckDelayvalue is used.- 参数:
beanDefinition- the BeanDefinition to check- 返回:
- the refresh check delay
-
resolveProxyTargetClass
-
createScriptFactoryBeanDefinition
Create a ScriptFactory bean definition based on the given script definition, extracting only the definition data that is relevant for the ScriptFactory (that is, only bean class and constructor arguments).- 参数:
bd- the full script bean definition- 返回:
- the extracted ScriptFactory bean definition
- 另请参阅:
-
getScriptSource
Obtain a ScriptSource for the given bean, lazily creating it if not cached already.- 参数:
beanName- the name of the scripted beanscriptSourceLocator- the script source locator associated with the bean- 返回:
- the corresponding ScriptSource instance
- 另请参阅:
-
convertToScriptSource
protected ScriptSource convertToScriptSource(String beanName, String scriptSourceLocator, cn.taketoday.core.io.ResourceLoader resourceLoader) Convert the given script source locator to a ScriptSource instance.By default, supported locators are Framework resource locations (such as "file:C:/myScript.bsh" or "classpath:myPackage/myScript.bsh") and inline scripts ("inline:myScriptText...").
- 参数:
beanName- the name of the scripted beanscriptSourceLocator- the script source locatorresourceLoader- the ResourceLoader to use (if necessary)- 返回:
- the ScriptSource instance
-
createConfigInterface
Create a config interface for the given bean definition, defining setter methods for the defined property values as well as an init method and a destroy method (if defined).This implementation creates the interface via CGLIB's InterfaceMaker, determining the property types from the given interfaces (as far as possible).
- 参数:
bd- the bean definition (property values etc) to create a config interface forinterfaces- the interfaces to check against (might define getters corresponding to the setters we're supposed to generate)- 返回:
- the config interface
- 另请参阅:
-
InterfaceMaker
-
createCompositeInterface
Create a composite interface Class for the given interfaces, implementing the given interfaces in one single Class.The default implementation builds a JDK proxy class for the given interfaces.
- 参数:
interfaces- the interfaces to merge- 返回:
- the merged interface as Class
- 另请参阅:
-
createScriptedObjectBeanDefinition
protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName, ScriptSource scriptSource, @Nullable Class<?>[] interfaces) 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).- 参数:
bd- the full script bean definitionscriptFactoryBeanName- the name of the internal ScriptFactory beanscriptSource- the ScriptSource for the scripted beaninterfaces- the interfaces that the scripted bean is supposed to implement- 返回:
- the extracted ScriptFactory bean definition
- 另请参阅:
-
createRefreshableProxy
protected Object createRefreshableProxy(TargetSource ts, @Nullable Class<?>[] interfaces, boolean proxyTargetClass) Create a refreshable proxy for the given AOP TargetSource.- 参数:
ts- the refreshable TargetSourceinterfaces- the proxy interfaces (may benullto indicate proxying of all interfaces implemented by the target class)- 返回:
- the generated proxy
- 另请参阅:
-
destroy
public void destroy()Destroy the inner bean factory (used for scripts) on shutdown.- 指定者:
destroy在接口中DisposableBean
-