01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.scripting.config;
18:
19: import org.springframework.beans.factory.config.BeanDefinition;
20: import org.springframework.beans.factory.support.BeanDefinitionRegistry;
21: import org.springframework.beans.factory.support.RootBeanDefinition;
22: import org.springframework.scripting.support.ScriptFactoryPostProcessor;
23:
24: /**
25: * @author Rob Harrop
26: * @author Mark Fisher
27: * @since 2.5
28: */
29: public abstract class LangNamespaceUtils {
30:
31: /**
32: * The unique name under which the internally managed {@link ScriptFactoryPostProcessor} is
33: * registered in the {@link BeanDefinitionRegistry}.
34: */
35: private static final String SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME = "org.springframework.scripting.config.scriptFactoryPostProcessor";
36:
37: /**
38: * Register a {@link ScriptFactoryPostProcessor} bean definition in the supplied
39: * {@link BeanDefinitionRegistry} if the {@link ScriptFactoryPostProcessor} hasn't
40: * already been registered.
41: * @param registry the {@link BeanDefinitionRegistry} to register the script processor with
42: * @return the {@link ScriptFactoryPostProcessor} bean definition (new or already registered)
43: */
44: public static BeanDefinition registerScriptFactoryPostProcessorIfNecessary(
45: BeanDefinitionRegistry registry) {
46: BeanDefinition beanDefinition = null;
47: if (registry
48: .containsBeanDefinition(SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME)) {
49: beanDefinition = registry
50: .getBeanDefinition(SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME);
51: } else {
52: beanDefinition = new RootBeanDefinition(
53: ScriptFactoryPostProcessor.class);
54: registry.registerBeanDefinition(
55: SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME,
56: beanDefinition);
57: }
58: return beanDefinition;
59: }
60:
61: }
|