PageRenderTime 36ms CodeModel.GetById 16ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/hudson-core/src/main/java/hudson/util/spring/RuntimeSpringConfiguration.java

http://github.com/hudson/hudson
Java | 204 lines | 33 code | 21 blank | 150 comment | 0 complexity | 8869f03a9a199b6b632777074d66eb56 MD5 | raw file
  1/*
  2 * Copyright 2004-2005 the original author or authors.
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 *      http://www.apache.org/licenses/LICENSE-2.0
  9 *
 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 */
 16package hudson.util.spring;
 17
 18import org.springframework.beans.factory.config.BeanDefinition;
 19import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 20import org.springframework.beans.factory.support.AbstractBeanDefinition;
 21import org.springframework.context.support.StaticApplicationContext;
 22import org.springframework.web.context.ServletContextAware;
 23import org.springframework.web.context.WebApplicationContext;
 24
 25import javax.servlet.ServletContext;
 26import java.util.Collection;
 27import java.util.List;
 28
 29/**
 30 * A programmable runtime Spring configuration that allows a spring ApplicationContext
 31 * to be constructed at runtime
 32 *
 33 * Credit must go to Solomon Duskis and the
 34 * article: http://jroller.com/page/Solomon?entry=programmatic_configuration_in_spring
 35 *
 36 * @author Graeme
 37 * @since 0.3
 38 *
 39 */
 40interface RuntimeSpringConfiguration extends ServletContextAware {
 41
 42    /**
 43     * Adds a singleton bean definition
 44     *
 45     * @param name The name of the bean
 46     * @param clazz The class of the bean
 47     * @return A BeanConfiguration instance
 48     */
 49    public BeanConfiguration addSingletonBean(String name, Class clazz);
 50
 51    public WebApplicationContext getUnrefreshedApplicationContext();
 52    /**
 53     * Adds a prototype bean definition
 54     *
 55     * @param name The name of the bean
 56     * @param clazz The class of the bean
 57     * @return A BeanConfiguration instance
 58     */
 59    public BeanConfiguration addPrototypeBean(String name, Class clazz);
 60
 61    /**
 62     * Retrieves the application context from the current state
 63     *
 64     * @return The ApplicationContext instance
 65     */
 66    WebApplicationContext getApplicationContext();
 67
 68    /**
 69     * Adds an empty singleton bean configuration
 70     * @param name The name of the singleton bean
 71     *
 72     * @return A BeanConfiguration instance
 73     */
 74    public BeanConfiguration addSingletonBean(String name);
 75
 76    /**
 77     * Adds an empty prototype bean configuration
 78     *
 79     * @param name The name of the prototype bean
 80     * @return A BeanConfiguration instance
 81     */
 82    public BeanConfiguration addPrototypeBean(String name);
 83
 84    /**
 85     * Creates a singleton bean configuration. Differs from addSingletonBean in that
 86     * it doesn't add the bean to the list of bean references. Hence should be used for
 87     * creating nested beans
 88     *
 89     * @param clazz
 90     * @return A BeanConfiguration instance
 91     */
 92    public BeanConfiguration createSingletonBean(Class clazz);
 93
 94    /**
 95     * Creates a new singleton bean and adds it to the list of bean references
 96     *
 97     * @param name The name of the bean
 98     * @param clazz The class of the bean
 99     * @param args The constructor arguments of the bean
100     * @return A BeanConfiguration instance
101     */
102    public BeanConfiguration addSingletonBean(String name, Class clazz, Collection args);
103
104    /**
105     * Creates a singleton bean configuration. Differs from addSingletonBean in that
106     * it doesn't add the bean to the list of bean references. Hence should be used for
107     * creating nested beans
108     *
109     * @param clazz The bean class
110     * @param constructorArguments The constructor arguments
111     * @return A BeanConfiguration instance
112     */
113    public BeanConfiguration createSingletonBean(Class clazz, Collection constructorArguments);
114
115    /**
116     * Sets the servlet context
117     *
118     * @param context The servlet Context
119     */
120    public void setServletContext(ServletContext context);
121
122    /**
123     * Creates a new prototype bean configuration. Differs from addPrototypeBean in that
124     * it doesn't add the bean to the list of bean references to be created via the getApplicationContext()
125     * method, hence can be used for creating nested beans
126     *
127     * @param name The bean name
128     * @return A BeanConfiguration instance
129     *
130     */
131    public BeanConfiguration createPrototypeBean(String name);
132
133    /**
134     * Creates a new singleton bean configuration. Differs from addSingletonBean in that
135     * it doesn't add the bean to the list of bean references to be created via the getApplicationContext()
136     * method, hence can be used for creating nested beans
137     *
138     * @param name The bean name
139     * @return A BeanConfiguration instance
140     *
141     */
142    public BeanConfiguration createSingletonBean(String name);
143
144    /**
145     * Adds a bean configuration to the list of beans to be created
146     *
147     * @param beanName The name of the bean in the context
148     * @param beanConfiguration The BeanConfiguration instance
149     */
150    void addBeanConfiguration(String beanName, BeanConfiguration beanConfiguration);
151    /**
152     * Adds a Spring BeanDefinition. Differs from BeanConfiguration which is a factory class
153     * for creating BeanDefinition instances
154     * @param name The name of the bean
155     * @param bd The BeanDefinition instance
156     */
157    public void addBeanDefinition(String name, BeanDefinition bd);
158
159    /**
160     * Returns whether the runtime spring config contains the specified bean
161     *
162     * @param name The bean name
163     * @return True if it does
164     */
165    public boolean containsBean(String name);
166    /**
167     * Returns the BeanConfiguration for the specified name
168     * @param name The name of the bean configuration
169     * @return The BeanConfiguration
170     */
171    public BeanConfiguration getBeanConfig(String name);
172
173    /**
174     * Creates and returns the BeanDefinition that is regsitered within the given name or returns null
175     *
176     * @param name The name of the bean definition
177     * @return A BeanDefinition
178     */
179    public AbstractBeanDefinition createBeanDefinition(String name);
180
181    /**
182     * Registers a bean factory post processor with the context
183     *
184     * @param processor The BeanFactoryPostProcessor instance
185     */
186    public void registerPostProcessor(BeanFactoryPostProcessor processor);
187
188    List<String> getBeanNames();
189
190    /**
191     * Registers the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext
192     *
193     * @param applicationContext The ApplicationContext instance
194     */
195    void registerBeansWithContext(StaticApplicationContext applicationContext);
196
197    /**
198     * Adds an abstract bean definition to the bean factory and returns the BeanConfiguration object
199     *
200     * @param name The name of the bean
201     * @return The BeanConfiguration object
202     */
203    BeanConfiguration addAbstractBean(String name);
204}