Skip to content

Commit

Permalink
New bootstrap for WB
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1715 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Feb 26, 2009
1 parent 6ec7e3a commit bfe595e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 204 deletions.
Expand Up @@ -26,7 +26,6 @@ public void deploy(List<Class<? extends Annotation>> enabledDeploymentTypes, Ite
this.lifecycle = new MockLifecycle();
try
{
lifecycle.initialize();
ManagerImpl manager = lifecycle.getBootstrap().getManager();
if (enabledDeploymentTypes != null)
{
Expand Down
Expand Up @@ -27,6 +27,13 @@
import org.jboss.webbeans.bean.standard.ManagerBean;
import org.jboss.webbeans.bootstrap.api.Bootstrap;
import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.ConversationContext;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.RequestContext;
import org.jboss.webbeans.context.SessionContext;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.webbeans.conversation.ConversationImpl;
import org.jboss.webbeans.conversation.JavaSEConversationTerminator;
import org.jboss.webbeans.conversation.NumericConversationIdGenerator;
Expand Down Expand Up @@ -77,6 +84,7 @@ public void initialize()
this.manager = new ManagerImpl(getNamingContext(), getEjbResolver(), getResourceLoader());
getManager().getNaming().bind(ManagerImpl.JNDI_KEY, getManager());
CurrentManager.setRootManager(manager);
initializeContexts();
}

public ManagerImpl getManager()
Expand Down Expand Up @@ -126,6 +134,13 @@ public void boot()
{
throw new IllegalStateException("ResourceLoader not set");
}
if (getApplicationContext() == null)
{
throw new IllegalStateException("No application context BeanStore set");
}
beginApplication(getApplicationContext());
BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
beginDeploy(requestBeanStore);
// Must populate EJB cache first, as we need it to detect whether a
// bean is an EJB!
manager.getEjbDescriptorCache().addAll(getEjbDiscovery().discoverEjbs());
Expand All @@ -143,6 +158,7 @@ public void boot()
manager.getResolver().resolveInjectionPoints();
new BeanValidator(manager).validate();
manager.fireEvent(manager, new DeployedLiteral());
endDeploy(requestBeanStore);
}
}

Expand All @@ -156,5 +172,42 @@ public static String getVersion()
Package pkg = WebBeansBootstrap.class.getPackage();
return pkg != null ? pkg.getImplementationVersion() : null;
}

protected void initializeContexts()
{
manager.addContext(DependentContext.create());
manager.addContext(RequestContext.create());
manager.addContext(SessionContext.create());
manager.addContext(ApplicationContext.create());
manager.addContext(ConversationContext.create());
}

protected void beginApplication(BeanStore applicationBeanStore)
{
log.trace("Starting application");
ApplicationContext.INSTANCE.setBeanStore(applicationBeanStore);
ApplicationContext.INSTANCE.setActive(true);

}

protected void beginDeploy(BeanStore requestBeanStore)
{
RequestContext.INSTANCE.setBeanStore(requestBeanStore);
RequestContext.INSTANCE.setActive(true);
}

protected void endDeploy(BeanStore requestBeanStore)
{
RequestContext.INSTANCE.setBeanStore(null);
RequestContext.INSTANCE.setActive(false);
}

protected void endApplication(BeanStore applicationBeanStore)
{
log.trace("Ending application");
ApplicationContext.INSTANCE.destroy();
ApplicationContext.INSTANCE.setActive(false);
ApplicationContext.INSTANCE.setBeanStore(null);
}

}
Expand Up @@ -54,13 +54,8 @@ public MockLifecycle(MockWebBeanDiscovery mockWebBeanDiscovery)
bootstrap.setEjbResolver(MOCK_EJB_RESOLVER);
bootstrap.setResourceLoader(MOCK_RESOURCE_LOADER);
bootstrap.setWebBeanDiscovery(webBeanDiscovery);
}

@Override
public void initialize()
{
bootstrap.setApplicationContext(applicationBeanStore);
bootstrap.initialize();
super.initialize();
}

public MockWebBeanDiscovery getWebBeanDiscovery()
Expand All @@ -75,22 +70,18 @@ public WebBeansBootstrap getBootstrap()

public void beginApplication()
{
super.beginApplication("Mock", applicationBeanStore);
BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
super.beginDeploy(requestBeanStore);
bootstrap.setEjbDiscovery(new MockEjbDiscovery(webBeanDiscovery.discoverWebBeanClasses()));
bootstrap.boot();
super.endDeploy(requestBeanStore);
}

public void resetContexts()
public void endApplication()
{

}

public void endApplication()
public void resetContexts()
{
super.endApplication("Mock", applicationBeanStore);

}

public void beginRequest()
Expand Down
@@ -1,8 +1,6 @@
package org.jboss.webbeans.servlet;

import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.ConversationContext;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.RequestContext;
Expand Down Expand Up @@ -36,48 +34,6 @@ protected static void setInstance(AbstractLifecycle instance)

private static LogProvider log = Logging.getLogProvider(AbstractLifecycle.class);

protected void initialize()
{
ManagerImpl manager = CurrentManager.rootManager();
if (manager == null)
{
throw new IllegalStateException("Manager has not been initialized, check that Bootstrap.initialize() has run");
}
manager.addContext(DependentContext.create());
manager.addContext(RequestContext.create());
manager.addContext(SessionContext.create());
manager.addContext(ApplicationContext.create());
manager.addContext(ConversationContext.create());
}

protected void beginApplication(String id, BeanStore applicationBeanStore)
{
log.trace("Starting application " + id);
ApplicationContext.INSTANCE.setBeanStore(applicationBeanStore);
ApplicationContext.INSTANCE.setActive(true);

}

protected void beginDeploy(BeanStore requestBeanStore)
{
RequestContext.INSTANCE.setBeanStore(requestBeanStore);
RequestContext.INSTANCE.setActive(true);
}

protected void endDeploy(BeanStore requestBeanStore)
{
RequestContext.INSTANCE.setBeanStore(null);
RequestContext.INSTANCE.setActive(false);
}

protected void endApplication(String id, BeanStore applicationBeanStore)
{
log.trace("Ending application " + id);
ApplicationContext.INSTANCE.destroy();
ApplicationContext.INSTANCE.setActive(false);
ApplicationContext.INSTANCE.setBeanStore(null);
}

protected void beginSession(String id, BeanStore sessionBeanStore)
{
log.trace("Starting session " + id);
Expand Down
Expand Up @@ -54,12 +54,6 @@ public static ServletLifecycle instance()

private static LogProvider log = Logging.getLogProvider(ServletLifecycle.class);

@Override
public void initialize()
{
// No-op, we'll do the init ourselves!
}

/**
* Starts the application
*
Expand All @@ -69,21 +63,21 @@ public void initialize()
*/
public void beginApplication(ServletContext servletContext)
{
ServletInitialization servletInitialization = new ServletInitialization(servletContext).initialize();
/*ServletInitialization servletInitialization = new ServletInitialization(servletContext).initialize();
super.initialize();
super.beginApplication(servletContext.getServletContextName(), new ApplicationBeanStore(servletContext));
BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
super.beginDeploy(requestBeanStore);
servletInitialization.start();
super.endDeploy(requestBeanStore);
super.endDeploy(requestBeanStore);*/
}

/**
* Ends the application
*/
public void endApplication(ServletContext servletContext)
{
super.endApplication(servletContext.getServletContextName(), new ApplicationBeanStore(servletContext));
//super.endApplication(servletContext.getServletContextName(), new ApplicationBeanStore(servletContext));
}

/**
Expand Down

This file was deleted.

Expand Up @@ -43,7 +43,6 @@ public class WebBeansListener implements ServletContextListener, HttpSessionList
public WebBeansListener()
{
lifecycle = ServletLifecycle.instance();
lifecycle.initialize();
}

/**
Expand Down
Expand Up @@ -72,7 +72,6 @@ public final void run() throws Exception
public void before() throws Exception
{
lifecycle = new MockLifecycle();
lifecycle.initialize();
this.discovery = lifecycle.getWebBeanDiscovery();
this.manager = lifecycle.getBootstrap().getManager();
lifecycle.beginApplication();
Expand Down

0 comments on commit bfe595e

Please sign in to comment.