Author: djencks
Date: Wed Jun  1 02:07:52 2011
New Revision: 1129986

URL: http://svn.apache.org/viewvc?rev=1129986&view=rev
Log:
OWB-578 alternate DI constructor for OpenWebBeansConfiguration

Modified:
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
    
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java?rev=1129986&r1=1129985&r2=1129986&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
 Wed Jun  1 02:07:52 2011
@@ -118,6 +118,16 @@ public class OpenWebBeansConfiguration
     public static final String USE_BDA_BEANSXML_SCANNER = 
"org.apache.webbeans.useBDABeansXMLScanner";
 
     /**
+     * you can configure this externally as well.
+     *
+     * @param properties
+     */
+    public OpenWebBeansConfiguration(Properties properties)
+    {
+        configProperties.putAll(properties);
+    }
+
+    /**
      * Parse configuration.
      */
     public OpenWebBeansConfiguration()

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1129986&r1=1129985&r2=1129986&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
 Wed Jun  1 02:07:52 2011
@@ -23,6 +23,7 @@ import java.lang.reflect.InvocationTarge
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import org.apache.webbeans.annotation.AnnotationManager;
 import org.apache.webbeans.container.BeanManagerImpl;
@@ -31,9 +32,6 @@ import org.apache.webbeans.container.Ser
 import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.context.creational.CreationalContextFactory;
 import org.apache.webbeans.conversation.ConversationManager;
-//import org.apache.webbeans.corespi.se.DefaultContextsService;
-//import org.apache.webbeans.corespi.se.DefaultJndiService;
-//import org.apache.webbeans.corespi.se.DefaultScannerService;
 import org.apache.webbeans.decorator.DecoratorsManager;
 import org.apache.webbeans.deployment.StereoTypeManager;
 import org.apache.webbeans.exception.WebBeansException;
@@ -65,35 +63,58 @@ public class WebBeansContext
 
     private final Map<Class<?>, Object> serviceMap = new HashMap<Class<?>, 
Object>();
 
-    private WebBeansUtil webBeansUtil = new WebBeansUtil(this);
-    private ContextFactory contextFactory = new ContextFactory(this);
-    private AlternativesManager alternativesManager = new 
AlternativesManager(this);
-    private AnnotatedElementFactory annotatedElementFactory = new 
AnnotatedElementFactory(this);
-    private BeanManagerImpl beanManagerImpl = new BeanManagerImpl(this);
-    private ConversationManager conversationManager = new 
ConversationManager(this);
-    private CreationalContextFactory creationalContextFactory = new 
CreationalContextFactory(this);
-    private DecoratorsManager decoratorsManager = new DecoratorsManager(this);
-    private EJBInterceptorConfig ejbInterceptorConfig = new 
EJBInterceptorConfig(this);
-    private ExtensionLoader extensionLoader = new ExtensionLoader(this);
-    private InterceptorsManager interceptorsManager = new 
InterceptorsManager(this);
-    private WebBeansInterceptorConfig webBeansInterceptorConfig = new 
WebBeansInterceptorConfig(this);
-    private JMSManager jmsManager = new JMSManager();
-    private JavassistProxyFactory javassistProxyFactory = new 
JavassistProxyFactory();
-    private OpenWebBeansConfiguration openWebBeansConfiguration = new 
OpenWebBeansConfiguration();
-    private PluginLoader pluginLoader = new PluginLoader();
-    private SerializableBeanVault serializableBeanVault = new 
SerializableBeanVault();
-    private StereoTypeManager stereoTypeManager = new StereoTypeManager();
-    private AnnotationManager annotationManager = new AnnotationManager(this);
-    private ResolutionUtil resolutionUtil = new ResolutionUtil(this);
-    private InjectionPointFactory injectionPointFactory = new 
InjectionPointFactory(this);
-    private InterceptorUtil interceptorUtil = new InterceptorUtil(this);
-    private DefinitionUtil definitionUtil = new DefinitionUtil(this);
-    private WebBeansAnnotatedTypeUtil annotatedTypeUtil = new 
WebBeansAnnotatedTypeUtil(this);
-    private ManagedBeanConfigurator managedBeanConfigurator = new 
ManagedBeanConfigurator(this);
-    private SecurityService securityService = 
getService(SecurityService.class);
+    private final WebBeansUtil webBeansUtil = new WebBeansUtil(this);
+    private final ContextFactory contextFactory = new ContextFactory(this);
+    private final AlternativesManager alternativesManager = new 
AlternativesManager(this);
+    private final AnnotatedElementFactory annotatedElementFactory = new 
AnnotatedElementFactory(this);
+    private final BeanManagerImpl beanManagerImpl = new BeanManagerImpl(this);
+    private final ConversationManager conversationManager = new 
ConversationManager(this);
+    private final CreationalContextFactory creationalContextFactory = new 
CreationalContextFactory(this);
+    private final DecoratorsManager decoratorsManager = new 
DecoratorsManager(this);
+    private final EJBInterceptorConfig ejbInterceptorConfig = new 
EJBInterceptorConfig(this);
+    private final ExtensionLoader extensionLoader = new ExtensionLoader(this);
+    private final InterceptorsManager interceptorsManager = new 
InterceptorsManager(this);
+    private final WebBeansInterceptorConfig webBeansInterceptorConfig = new 
WebBeansInterceptorConfig(this);
+    private final JMSManager jmsManager = new JMSManager();
+    private final JavassistProxyFactory javassistProxyFactory = new 
JavassistProxyFactory();
+    private final OpenWebBeansConfiguration openWebBeansConfiguration;
+    private final PluginLoader pluginLoader = new PluginLoader();
+    private final SerializableBeanVault serializableBeanVault = new 
SerializableBeanVault();
+    private final StereoTypeManager stereoTypeManager = new 
StereoTypeManager();
+    private final AnnotationManager annotationManager = new 
AnnotationManager(this);
+    private final ResolutionUtil resolutionUtil = new ResolutionUtil(this);
+    private final InjectionPointFactory injectionPointFactory = new 
InjectionPointFactory(this);
+    private final InterceptorUtil interceptorUtil = new InterceptorUtil(this);
+    private final DefinitionUtil definitionUtil = new DefinitionUtil(this);
+    private final WebBeansAnnotatedTypeUtil annotatedTypeUtil = new 
WebBeansAnnotatedTypeUtil(this);
+    private final ManagedBeanConfigurator managedBeanConfigurator = new 
ManagedBeanConfigurator(this);
+    private final SecurityService securityService;
 
     public WebBeansContext()
     {
+        this(null, new OpenWebBeansConfiguration());
+    }
+
+    public WebBeansContext(Map<Class<?>, Object> initialServices, Properties 
properties)
+    {
+        this(initialServices, new OpenWebBeansConfiguration(properties));
+    }
+
+    private WebBeansContext(Map<Class<?>, Object> initialServices, 
OpenWebBeansConfiguration openWebBeansConfiguration)
+    {
+        this.openWebBeansConfiguration = openWebBeansConfiguration;
+        if (initialServices != null)
+        {
+            for (Map.Entry<Class<?>, Object> entry: initialServices.entrySet())
+            {
+                if 
(!entry.getKey().isAssignableFrom(entry.getValue().getClass()))
+                {
+                    throw new IllegalArgumentException("Initial service 
claiming to be of type " + entry.getKey() + " is a " + 
entry.getValue().getClass());
+                }
+                serviceMap.put(entry.getKey(), entry.getValue());
+            }
+        }
+        this.securityService = getService(SecurityService.class);
         WebBeansUtil.initProxyFactoryClassLoaderProvider();
 
         // Allow the WebBeansContext itself to be looked up

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java?rev=1129986&r1=1129985&r2=1129986&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/AbstractLifeCycle.java
 Wed Jun  1 02:07:52 2011
@@ -70,16 +70,21 @@ public abstract class AbstractLifeCycle 
     
     protected AbstractLifeCycle(Properties properties)
     {
+        this(properties, WebBeansContext.getInstance());
+    }
+
+    protected AbstractLifeCycle(Properties properties, WebBeansContext 
webBeansContext)
+    {
         beforeInitApplication(properties);
 
-        webBeansContext = WebBeansContext.getInstance();
-        this.beanManager = webBeansContext.getBeanManagerImpl();
+        this.webBeansContext = webBeansContext;
+        this.beanManager = this.webBeansContext.getBeanManagerImpl();
         this.xmlDeployer = new WebBeansXMLConfigurator();
-        this.deployer = new BeansDeployer(xmlDeployer, webBeansContext);
-        this.jndiService = webBeansContext.getService(JNDIService.class);
+        this.deployer = new BeansDeployer(xmlDeployer, this.webBeansContext);
+        this.jndiService = this.webBeansContext.getService(JNDIService.class);
         this.beanManager.setXMLConfigurator(this.xmlDeployer);
-        this.scannerService = webBeansContext.getScannerService();
-        this.contextsService = 
webBeansContext.getService(ContextsService.class);
+        this.scannerService = this.webBeansContext.getScannerService();
+        this.contextsService = 
this.webBeansContext.getService(ContextsService.class);
         initApplication(properties);
     }
 
@@ -197,14 +202,6 @@ public abstract class AbstractLifeCycle 
     }
 
     /**
-     * @return the scannerService
-     */
-//    protected ScannerService getScannerService()
-//    {
-//        return scannerService;
-//    }
-
-    /**
      * @return the contextsService
      */
     public ContextsService getContextService()
@@ -212,30 +209,6 @@ public abstract class AbstractLifeCycle 
         return contextsService;
     }
 
-    /**
-     * @return the deployer
-     */
-//    protected BeansDeployer getDeployer()
-//    {
-//        return deployer;
-//    }
-
-    /**
-     * @return the xmlDeployer
-     */
-//    protected WebBeansXMLConfigurator getXmlDeployer()
-//    {
-//        return xmlDeployer;
-//    }
-
-    /**
-     * @return the jndiService
-     */
-//    protected JNDIService getJndiService()
-//    {
-//        return jndiService;
-//    }
-
     @Override
     public void initApplication(Properties properties)
     {

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java?rev=1129986&r1=1129985&r2=1129986&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/StandaloneLifeCycle.java
 Wed Jun  1 02:07:52 2011
@@ -44,7 +44,7 @@ public class StandaloneLifeCycle extends
     @Override
     public void beforeInitApplication(Properties properties)
     {
-        WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
+//        WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
     }
     
     @Override
@@ -74,5 +74,10 @@ public class StandaloneLifeCycle extends
             elStore.destroyELContextStore();
         }
     }
-    
+
+    @Override
+    protected void afterStopApplication(Object stopObject)
+    {
+        WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());
+    }
 }
\ No newline at end of file

Modified: 
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1129986&r1=1129985&r2=1129986&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
 (original)
+++ 
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
 Wed Jun  1 02:07:52 2011
@@ -66,6 +66,16 @@ public final class WebContainerLifecycle
         this.logger = WebBeansLogger.getLogger(WebContainerLifecycle.class);
     }
 
+    /**
+     * Creates a new lifecycle instance and initializes
+     * the instance variables.
+     */
+    public WebContainerLifecycle(WebBeansContext webBeansContext)
+    {
+        super(null, webBeansContext);
+        this.logger = WebBeansLogger.getLogger(WebContainerLifecycle.class);
+    }
+
 
     /**
      * {@inheritDoc}


Reply via email to