@@ -70,17 +70,17 @@ class ScriptBeanDefinitionParser extends AbstractBeanDefinitionParser {
7070 private static final String SCRIPT_INTERFACES_ATTRIBUTE = "script-interfaces" ;
7171
7272 private static final String REFRESH_CHECK_DELAY_ATTRIBUTE = "refresh-check-delay" ;
73-
74- private static final String CUSTOMIZER_REF_ATTRIBUTE = "customizer-ref" ;
7573
74+ private static final String PROXY_TARGET_CLASS_ATTRIBUTE = "proxy-target-class" ;
75+
76+ private static final String CUSTOMIZER_REF_ATTRIBUTE = "customizer-ref" ;
7677
7778 /**
7879 * The {@link org.springframework.scripting.ScriptFactory} class that this
7980 * parser instance will create bean definitions for.
8081 */
8182 private final String scriptFactoryClassName ;
8283
83-
8484 /**
8585 * Create a new instance of this parser, creating bean definitions for the
8686 * supplied {@link org.springframework.scripting.ScriptFactory} class.
@@ -90,7 +90,6 @@ public ScriptBeanDefinitionParser(String scriptFactoryClassName) {
9090 this .scriptFactoryClassName = scriptFactoryClassName ;
9191 }
9292
93-
9493 /**
9594 * Parses the dynamic object element and returns the resulting bean definition.
9695 * Registers a {@link ScriptFactoryPostProcessor} if needed.
@@ -110,7 +109,8 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
110109 GenericBeanDefinition bd = new GenericBeanDefinition ();
111110 bd .setBeanClassName (this .scriptFactoryClassName );
112111 bd .setSource (parserContext .extractSource (element ));
113-
112+ bd .setAttribute (ScriptFactoryPostProcessor .LANGUAGE_ATTRIBUTE , element .getLocalName ());
113+
114114 // Determine bean scope.
115115 String scope = element .getAttribute (SCOPE_ATTRIBUTE );
116116 if (StringUtils .hasLength (scope )) {
@@ -123,8 +123,7 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
123123 // Only "byType" and "byName" supported, but maybe other default inherited...
124124 if (autowireMode == GenericBeanDefinition .AUTOWIRE_AUTODETECT ) {
125125 autowireMode = GenericBeanDefinition .AUTOWIRE_BY_TYPE ;
126- }
127- else if (autowireMode == GenericBeanDefinition .AUTOWIRE_CONSTRUCTOR ) {
126+ } else if (autowireMode == GenericBeanDefinition .AUTOWIRE_CONSTRUCTOR ) {
128127 autowireMode = GenericBeanDefinition .AUTOWIRE_NO ;
129128 }
130129 bd .setAutowireMode (autowireMode );
@@ -134,31 +133,34 @@ else if (autowireMode == GenericBeanDefinition.AUTOWIRE_CONSTRUCTOR) {
134133 bd .setDependencyCheck (parserContext .getDelegate ().getDependencyCheck (dependencyCheck ));
135134
136135 // Retrieve the defaults for bean definitions within this parser context
137- BeanDefinitionDefaults beanDefinitionDefaults =
138- parserContext .getDelegate ().getBeanDefinitionDefaults ();
136+ BeanDefinitionDefaults beanDefinitionDefaults = parserContext .getDelegate ().getBeanDefinitionDefaults ();
139137
140138 // Determine init method and destroy method.
141139 String initMethod = element .getAttribute (INIT_METHOD_ATTRIBUTE );
142140 if (StringUtils .hasLength (initMethod )) {
143141 bd .setInitMethodName (initMethod );
144- }
145- else if (beanDefinitionDefaults .getInitMethodName () != null ) {
142+ } else if (beanDefinitionDefaults .getInitMethodName () != null ) {
146143 bd .setInitMethodName (beanDefinitionDefaults .getInitMethodName ());
147144 }
148145
149146 String destroyMethod = element .getAttribute (DESTROY_METHOD_ATTRIBUTE );
150147 if (StringUtils .hasLength (destroyMethod )) {
151148 bd .setDestroyMethodName (destroyMethod );
152- }
153- else if (beanDefinitionDefaults .getDestroyMethodName () != null ) {
149+ } else if (beanDefinitionDefaults .getDestroyMethodName () != null ) {
154150 bd .setDestroyMethodName (beanDefinitionDefaults .getDestroyMethodName ());
155151 }
156152
157153 // Attach any refresh metadata.
158154 String refreshCheckDelay = element .getAttribute (REFRESH_CHECK_DELAY_ATTRIBUTE );
159155 if (StringUtils .hasText (refreshCheckDelay )) {
160- bd .setAttribute (
161- ScriptFactoryPostProcessor .REFRESH_CHECK_DELAY_ATTRIBUTE , new Long (refreshCheckDelay ));
156+ bd .setAttribute (ScriptFactoryPostProcessor .REFRESH_CHECK_DELAY_ATTRIBUTE , new Long (refreshCheckDelay ));
157+ }
158+
159+ // Attach any proxy target class metadata.
160+ String proxyTargetClass = element .getAttribute (PROXY_TARGET_CLASS_ATTRIBUTE );
161+ if (StringUtils .hasText (proxyTargetClass )) {
162+ Boolean flag = new Boolean (proxyTargetClass );
163+ bd .setAttribute (ScriptFactoryPostProcessor .PROXY_TARGET_CLASS_ATTRIBUTE , flag );
162164 }
163165
164166 // Add constructor arguments.
@@ -168,14 +170,13 @@ else if (beanDefinitionDefaults.getDestroyMethodName() != null) {
168170 if (element .hasAttribute (SCRIPT_INTERFACES_ATTRIBUTE )) {
169171 cav .addIndexedArgumentValue (constructorArgNum ++, element .getAttribute (SCRIPT_INTERFACES_ATTRIBUTE ));
170172 }
171-
173+
172174 // This is used for Groovy. It's a bean reference to a customizer bean.
173175 if (element .hasAttribute (CUSTOMIZER_REF_ATTRIBUTE )) {
174176 String customizerBeanName = element .getAttribute (CUSTOMIZER_REF_ATTRIBUTE );
175177 if (!StringUtils .hasText (customizerBeanName )) {
176178 parserContext .getReaderContext ().error ("Attribute 'customizer-ref' has empty value" , element );
177- }
178- else {
179+ } else {
179180 cav .addIndexedArgumentValue (constructorArgNum ++, new RuntimeBeanReference (customizerBeanName ));
180181 }
181182 }
@@ -197,15 +198,12 @@ private String resolveScriptSource(Element element, XmlReaderContext readerConte
197198 if (hasScriptSource && !elements .isEmpty ()) {
198199 readerContext .error ("Only one of 'script-source' and 'inline-script' should be specified." , element );
199200 return null ;
200- }
201- else if (hasScriptSource ) {
201+ } else if (hasScriptSource ) {
202202 return element .getAttribute (SCRIPT_SOURCE_ATTRIBUTE );
203- }
204- else if (!elements .isEmpty ()) {
203+ } else if (!elements .isEmpty ()) {
205204 Element inlineElement = (Element ) elements .get (0 );
206205 return "inline:" + DomUtils .getTextValue (inlineElement );
207- }
208- else {
206+ } else {
209207 readerContext .error ("Must specify either 'script-source' or 'inline-script'." , element );
210208 return null ;
211209 }
0 commit comments