001/* 002 * Copyright 2002-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.scripting.config; 018 019import org.springframework.beans.factory.config.BeanDefinition; 020import org.springframework.beans.factory.support.BeanDefinitionRegistry; 021import org.springframework.beans.factory.support.RootBeanDefinition; 022import org.springframework.scripting.support.ScriptFactoryPostProcessor; 023 024/** 025 * @author Rob Harrop 026 * @author Mark Fisher 027 * @since 2.5 028 */ 029public abstract class LangNamespaceUtils { 030 031 /** 032 * The unique name under which the internally managed {@link ScriptFactoryPostProcessor} is 033 * registered in the {@link BeanDefinitionRegistry}. 034 */ 035 private static final String SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME = 036 "org.springframework.scripting.config.scriptFactoryPostProcessor"; 037 038 039 /** 040 * Register a {@link ScriptFactoryPostProcessor} bean definition in the supplied 041 * {@link BeanDefinitionRegistry} if the {@link ScriptFactoryPostProcessor} hasn't 042 * already been registered. 043 * @param registry the {@link BeanDefinitionRegistry} to register the script processor with 044 * @return the {@link ScriptFactoryPostProcessor} bean definition (new or already registered) 045 */ 046 public static BeanDefinition registerScriptFactoryPostProcessorIfNecessary(BeanDefinitionRegistry registry) { 047 BeanDefinition beanDefinition = null; 048 if (registry.containsBeanDefinition(SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME)) { 049 beanDefinition = registry.getBeanDefinition(SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME); 050 } 051 else { 052 beanDefinition = new RootBeanDefinition(ScriptFactoryPostProcessor.class); 053 registry.registerBeanDefinition(SCRIPT_FACTORY_POST_PROCESSOR_BEAN_NAME, beanDefinition); 054 } 055 return beanDefinition; 056 } 057 058}