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