[webbeans-commits] Webbeans SVN: r3596 - in ri/trunk: impl/src/main/java/org/jboss/webbeans/bootstrap and 8 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Wed Aug 26 11:57:56 EDT 2009
Author: pete.muir at jboss.org
Date: 2009-08-26 11:57:55 -0400 (Wed, 26 Aug 2009)
New Revision: 3596
Removed:
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterBeanDiscoveryImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterDeploymentValidationImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/BeanDeploymentArchive.java
ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/Deployment.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java
ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockDeployment.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockBeanDeploymentArchive.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockDeployment.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java
ri/trunk/tests/src/main/java/org/jboss/webbeans/test/harness/AbstractStandaloneContainersImpl.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java
Log:
WBRI-372
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/BeanManagerImpl.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -301,10 +301,10 @@
* @param serviceRegistry
* @return
*/
- public static BeanManagerImpl newManager(BeanManagerImpl rootManager)
+ public static BeanManagerImpl newManager(BeanManagerImpl rootManager, ServiceRegistry services)
{
return new BeanManagerImpl(
- rootManager.getServices(),
+ services,
new CopyOnWriteArrayList<Bean<?>>(),
new CopyOnWriteArrayList<DecoratorBean<?>>(),
new CopyOnWriteArrayList<ObserverMethod<?,?>>(),
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/CurrentManager.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -65,7 +65,7 @@
public static boolean isAvailable()
{
- return rootManager.isSet();
+ return rootManager.isSet() && beanDeploymentArchives.isSet();
}
/**
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterBeanDiscoveryImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterBeanDiscoveryImpl.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterBeanDiscoveryImpl.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -16,7 +16,6 @@
*/
package org.jboss.webbeans.bootstrap;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -30,29 +29,22 @@
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.webbeans.bootstrap.spi.Deployment;
-public class AfterBeanDiscoveryImpl implements AfterBeanDiscovery
+public class AfterBeanDiscoveryImpl extends AbstractBeanDiscoveryEvent implements AfterBeanDiscovery
{
-
- private final List<Throwable> definitionErrors = new ArrayList<Throwable>();
- private final Map<BeanDeploymentArchive, BeanDeployment> beanDeployments;
- private final BeanManagerImpl deploymentManager;
- private final Deployment deployment;
-
- public AfterBeanDiscoveryImpl(BeanManagerImpl deploymentManager, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
+
+ public AfterBeanDiscoveryImpl(BeanManagerImpl deploymentManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
- this.beanDeployments = beanDeployments;
- this.deploymentManager = deploymentManager;
- this.deployment = deploymentManager.getServices().get(Deployment.class);
+ super(beanDeployments, deploymentManager, deployment);
}
public void addDefinitionError(Throwable t)
{
- definitionErrors.add(t);
+ getErrors().add(t);
}
public List<Throwable> getDefinitionErrors()
{
- return Collections.unmodifiableList(definitionErrors);
+ return Collections.unmodifiableList(getErrors());
}
public void addBean(Bean<?> bean)
@@ -62,35 +54,12 @@
public void addContext(Context context)
{
- deploymentManager.addContext(context);
+ getDeploymentManager().addContext(context);
}
public void addObserverMethod(ObserverMethod<?, ?> observerMethod)
{
getOrCreateBeanDeployment(observerMethod.getBean().getBeanClass()).getBeanManager().addObserver(observerMethod);
}
-
- private BeanDeployment getOrCreateBeanDeployment(Class<?> clazz)
- {
- BeanDeploymentArchive beanDeploymentArchive = deployment.loadBeanDeploymentArchive(clazz);
- if (beanDeploymentArchive == null)
- {
- throw new IllegalStateException("Unable to find Bean Deployment Archive for " + clazz);
- }
- else
- {
- if (beanDeployments.containsKey(beanDeploymentArchive))
- {
- return beanDeployments.get(beanDeploymentArchive);
- }
- else
- {
- BeanDeployment beanDeployment = new BeanDeployment(beanDeploymentArchive, deploymentManager);
- beanDeployments.put(beanDeploymentArchive, beanDeployment);
- return beanDeployment;
- }
- }
-
- }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterDeploymentValidationImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterDeploymentValidationImpl.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AfterDeploymentValidationImpl.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -16,22 +16,21 @@
*/
package org.jboss.webbeans.bootstrap;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.enterprise.inject.spi.AfterDeploymentValidation;
-public class AfterDeploymentValidationImpl implements AfterDeploymentValidation
+public class AfterDeploymentValidationImpl extends AbstractContainerEvent implements AfterDeploymentValidation
{
- private List<Throwable> deploymentProblems = new ArrayList<Throwable>();
public void addDeploymentProblem(Throwable t)
{
- deploymentProblems.add(t);
+ getErrors().add(t);
}
public List<Throwable> getDeploymentProblems()
{
- return deploymentProblems;
+ return Collections.unmodifiableList(getErrors());
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployment.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -17,7 +17,6 @@
package org.jboss.webbeans.bootstrap;
import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.bean.builtin.DefaultValidatorBean;
import org.jboss.webbeans.bean.builtin.DefaultValidatorFactoryBean;
import org.jboss.webbeans.bean.builtin.InjectionPointBean;
@@ -28,6 +27,8 @@
import org.jboss.webbeans.bean.builtin.facade.InstanceBean;
import org.jboss.webbeans.bootstrap.api.Environment;
import org.jboss.webbeans.bootstrap.api.Environments;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
+import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.webbeans.conversation.ConversationImpl;
import org.jboss.webbeans.conversation.JavaSEConversationTerminator;
@@ -60,9 +61,12 @@
public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerImpl deploymentManager)
{
this.beanDeploymentArchive = beanDeploymentArchive;
- this.beanManager = BeanManagerImpl.newManager(CurrentManager.rootManager());
+ ServiceRegistry services = new SimpleServiceRegistry();
+ services.addAll(deploymentManager.getServices().entrySet());
+ services.addAll(beanDeploymentArchive.getServices().entrySet());
+ this.beanManager = BeanManagerImpl.newManager(deploymentManager, services);
EjbDescriptorCache ejbDescriptors = new EjbDescriptorCache();
- if (deploymentManager.getServices().contains(EjbServices.class))
+ if (beanManager.getServices().contains(EjbServices.class))
{
// Must populate EJB cache first, as we need it to detect whether a
// bean is an EJB!
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -28,38 +28,29 @@
import org.jboss.webbeans.literal.BindingTypeLiteral;
import org.jboss.webbeans.literal.InterceptorBindingTypeLiteral;
import org.jboss.webbeans.literal.ScopeTypeLiteral;
-import org.jboss.webbeans.metadata.TypeStore;
-public class BeforeBeanDiscoveryImpl implements BeforeBeanDiscovery
+public class BeforeBeanDiscoveryImpl extends AbstractBeanDiscoveryEvent implements BeforeBeanDiscovery
{
- private final TypeStore typeStore;
- private final Map<BeanDeploymentArchive, BeanDeployment> beanDeployments;
- private final BeanManagerImpl deploymentManager;
- private final Deployment deployment;
-
- public BeforeBeanDiscoveryImpl(BeanManagerImpl deploymentManager, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
+ public BeforeBeanDiscoveryImpl(BeanManagerImpl deploymentManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
- this.typeStore = deploymentManager.getServices().get(TypeStore.class);
- this.beanDeployments = beanDeployments;
- this.deployment = deploymentManager.getServices().get(Deployment.class);
- this.deploymentManager = deploymentManager;
+ super(beanDeployments, deploymentManager, deployment);
}
public void addBindingType(Class<? extends Annotation> bindingType)
{
- typeStore.add(bindingType, new BindingTypeLiteral());
+ getTypeStore().add(bindingType, new BindingTypeLiteral());
}
public void addInterceptorBindingType(Class<? extends Annotation> bindingType)
{
- typeStore.add(bindingType, new InterceptorBindingTypeLiteral());
+ getTypeStore().add(bindingType, new InterceptorBindingTypeLiteral());
}
public void addScopeType(Class<? extends Annotation> scopeType,
boolean normal, boolean passivating)
{
- typeStore.add(scopeType, new ScopeTypeLiteral(normal, passivating));
+ getTypeStore().add(scopeType, new ScopeTypeLiteral(normal, passivating));
}
public void addStereotype(Class<? extends Annotation> stereotype,
@@ -70,23 +61,7 @@
public void addAnnotatedType(AnnotatedType<?> type)
{
- BeanDeploymentArchive beanDeploymentArchive = deployment.loadBeanDeploymentArchive(type.getJavaClass());
- if (beanDeploymentArchive == null)
- {
- throw new IllegalStateException("Unable to find Bean Deployment Archive for " + type);
- }
- else
- {
- if (beanDeployments.containsKey(beanDeploymentArchive))
- {
- beanDeployments.get(beanDeploymentArchive).getBeanDeployer().addClass(type);
- }
- else
- {
- BeanDeployment beanDeployment = new BeanDeployment(beanDeploymentArchive, deploymentManager);
- beanDeployments.put(beanDeploymentArchive, beanDeployment);
- }
- }
+ getOrCreateBeanDeployment(type.getJavaClass()).getBeanDeployer().addClass(type);
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -34,7 +34,9 @@
import org.jboss.webbeans.Validator;
import org.jboss.webbeans.bean.builtin.ManagerBean;
import org.jboss.webbeans.bootstrap.api.Bootstrap;
-import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
+import org.jboss.webbeans.bootstrap.api.Environment;
+import org.jboss.webbeans.bootstrap.api.Service;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.api.helpers.ServiceRegistries;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.webbeans.bootstrap.spi.Deployment;
@@ -45,7 +47,6 @@
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.ejb.EJBApiAbstraction;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.jsf.JsfApiAbstraction;
@@ -69,7 +70,7 @@
*
* @author Pete Muir
*/
-public class WebBeansBootstrap extends AbstractBootstrap implements Bootstrap
+public class WebBeansBootstrap implements Bootstrap
{
/**
@@ -84,17 +85,21 @@
{
private final BeanManagerImpl deploymentManager;
+ private final Environment environment;
+ private final Deployment deployment;
- public DeploymentVisitor(BeanManagerImpl deploymentManager)
+ public DeploymentVisitor(BeanManagerImpl deploymentManager, Environment environment, Deployment deployment)
{
this.deploymentManager = deploymentManager;
+ this.environment = environment;
+ this.deployment = deployment;
}
public Map<BeanDeploymentArchive, BeanDeployment> visit()
{
Set<BeanDeploymentArchive> seenBeanDeploymentArchives = new HashSet<BeanDeploymentArchive>();
Map<BeanDeploymentArchive, BeanDeployment> managerAwareBeanDeploymentArchives = new HashMap<BeanDeploymentArchive, BeanDeployment>();
- for (BeanDeploymentArchive archvive : deploymentManager.getServices().get(Deployment.class).getBeanDeploymentArchives())
+ for (BeanDeploymentArchive archvive : deployment.getBeanDeploymentArchives())
{
visit(archvive, managerAwareBeanDeploymentArchives, seenBeanDeploymentArchives);
}
@@ -103,6 +108,10 @@
private BeanDeployment visit(BeanDeploymentArchive beanDeploymentArchive, Map<BeanDeploymentArchive, BeanDeployment> managerAwareBeanDeploymentArchives, Set<BeanDeploymentArchive> seenBeanDeploymentArchives)
{
+ // Check that the required services are specified
+ verifyServices(beanDeploymentArchive.getServices(), environment.getRequiredBeanDeploymentArchiveServices());
+
+ // Create the BeanDeployment and attach
BeanDeployment parent = new BeanDeployment(beanDeploymentArchive, deploymentManager);
managerAwareBeanDeploymentArchives.put(beanDeploymentArchive, parent);
seenBeanDeploymentArchives.add(beanDeploymentArchive);
@@ -131,60 +140,79 @@
// The Web Beans manager
private BeanManagerImpl deploymentManager;
private Map<BeanDeploymentArchive, BeanDeployment> beanDeployments;
- private DeploymentVisitor deploymentVisitor;
- private BeanStore requestBeanStore;
+ private Environment environment;
+ private Deployment deployment;
- public WebBeansBootstrap()
+ public Bootstrap startContainer(Environment environment, Deployment deployment, BeanStore applicationBeanStore)
{
- // initialize default services
- getServices().add(ResourceLoader.class, new DefaultResourceLoader());
- }
-
- public Bootstrap startContainer()
- {
synchronized (this)
{
- verify();
- if (!getServices().contains(TransactionServices.class))
+ if (deployment == null)
{
+ throw new IllegalArgumentException("Must start the container with a deployment");
+ }
+ if (!deployment.getServices().contains(ResourceLoader.class))
+ {
+ deployment.getServices().add(ResourceLoader.class, new DefaultResourceLoader());
+ }
+
+ verifyServices(deployment.getServices(), environment.getRequiredDeploymentServices());
+
+ if (!deployment.getServices().contains(TransactionServices.class))
+ {
log.info("Transactional services not available. Injection of @Current UserTransaction not available. Transactional observers will be invoked synchronously.");
}
- if (!getServices().contains(EjbServices.class))
+ if (!deployment.getServices().contains(EjbServices.class))
{
log.info("EJB services not available. Session beans will be simple beans, CDI-style injection into non-contextual EJBs, injection of remote EJBs and injection of @EJB in simple beans will not be available");
}
- if (!getServices().contains(JpaServices.class))
+ if (!deployment.getServices().contains(JpaServices.class))
{
log.info("JPA services not available. Injection of @PersistenceContext will not occur. Entity beans will be discovered as simple beans.");
}
- if (!getServices().contains(ResourceServices.class))
+ if (!deployment.getServices().contains(ResourceServices.class))
{
log.info("@Resource injection not available.");
}
- addImplementationServices();
+ if (applicationBeanStore == null)
+ {
+ throw new IllegalStateException("No application context BeanStore set");
+ }
+
+ this.deployment = deployment;
+ addImplementationServices(deployment.getServices());
+
+
+ this.environment = environment;
+ this.deploymentManager = BeanManagerImpl.newRootManager(ServiceRegistries.unmodifiableServiceRegistry(deployment.getServices()));
+ CurrentManager.setRootManager(deploymentManager);
+
createContexts();
- this.deploymentManager = BeanManagerImpl.newRootManager(ServiceRegistries.unmodifiableServiceRegistry(getServices()));
- CurrentManager.setRootManager(deploymentManager);
initializeContexts();
- this.deploymentVisitor = new DeploymentVisitor(deploymentManager);
+ // Start the application context
+ beginApplication(applicationBeanStore);
+
+ DeploymentVisitor deploymentVisitor = new DeploymentVisitor(deploymentManager, environment, deployment);
+ beanDeployments = deploymentVisitor.visit();
+
return this;
}
}
- private void addImplementationServices()
+ private void addImplementationServices(ServiceRegistry services)
{
- ResourceLoader resourceLoader = getServices().get(ResourceLoader.class);
- getServices().add(EJBApiAbstraction.class, new EJBApiAbstraction(resourceLoader));
- getServices().add(JsfApiAbstraction.class, new JsfApiAbstraction(resourceLoader));
- getServices().add(PersistenceApiAbstraction.class, new PersistenceApiAbstraction(resourceLoader));
- getServices().add(ServletApiAbstraction.class, new ServletApiAbstraction(resourceLoader));
+ ResourceLoader resourceLoader = services.get(ResourceLoader.class);
+ services.add(EJBApiAbstraction.class, new EJBApiAbstraction(resourceLoader));
+ services.add(JsfApiAbstraction.class, new JsfApiAbstraction(resourceLoader));
+ services.add(PersistenceApiAbstraction.class, new PersistenceApiAbstraction(resourceLoader));
+ services.add(ServletApiAbstraction.class, new ServletApiAbstraction(resourceLoader));
// Temporary workaround to provide context for building annotated class
// TODO expose AnnotatedClass on SPI and allow container to provide impl of this via ResourceLoader
- getServices().add(Validator.class, new Validator());
- getServices().add(TypeStore.class, new TypeStore());
- getServices().add(ClassTransformer.class, new ClassTransformer(getServices().get(TypeStore.class)));
- getServices().add(MetaAnnotationStore.class, new MetaAnnotationStore(getServices().get(ClassTransformer.class)));
- getServices().add(ContextualIdStore.class, new ContextualIdStore());
+ services.add(Validator.class, new Validator());
+ services.add(TypeStore.class, new TypeStore());
+ services.add(ClassTransformer.class, new ClassTransformer(services.get(TypeStore.class)));
+ services.add(MetaAnnotationStore.class, new MetaAnnotationStore(services.get(ClassTransformer.class)));
+ services.add(ContextualIdStore.class, new ContextualIdStore());
}
public BeanManagerImpl getManager(BeanDeploymentArchive beanDeploymentArchive)
@@ -207,18 +235,7 @@
{
throw new IllegalStateException("Manager has not been initialized");
}
- if (getApplicationContext() == null)
- {
- throw new IllegalStateException("No application context BeanStore set");
- }
- // Set up the contexts before we start creating bean deployers
- // This allows us to throw errors in the parser
- beginApplication(getApplicationContext());
- requestBeanStore = new ConcurrentHashMapBeanStore();
-
- beanDeployments = deploymentVisitor.visit();
-
ExtensionBeanDeployer extensionBeanDeployer = new ExtensionBeanDeployer(deploymentManager);
extensionBeanDeployer.addExtensions(ServiceLoader.load(Extension.class));
extensionBeanDeployer.createBeans().deploy();
@@ -237,7 +254,7 @@
{
for (Entry<BeanDeploymentArchive, BeanDeployment> entry : beanDeployments.entrySet())
{
- entry.getValue().deployBeans(getEnvironment());
+ entry.getValue().deployBeans(environment);
}
fireAfterBeanDiscoveryEvent();
log.debug("Web Beans initialized. Validating beans.");
@@ -251,7 +268,7 @@
{
for (Entry<BeanDeploymentArchive, BeanDeployment> entry : beanDeployments.entrySet())
{
- getServices().get(Validator.class).validateDeployment(entry.getValue().getBeanManager(), entry.getValue().getBeanDeployer().getEnvironment());
+ deploymentManager.getServices().get(Validator.class).validateDeployment(entry.getValue().getBeanManager(), entry.getValue().getBeanDeployer().getEnvironment());
}
fireAfterDeploymentValidationEvent();
}
@@ -270,7 +287,7 @@
private void fireBeforeBeanDiscoveryEvent()
{
- BeforeBeanDiscovery event = new BeforeBeanDiscoveryImpl(deploymentManager, beanDeployments);
+ BeforeBeanDiscovery event = new BeforeBeanDiscoveryImpl(deploymentManager, deployment, beanDeployments);
try
{
deploymentManager.fireEvent(event);
@@ -296,7 +313,7 @@
private void fireAfterBeanDiscoveryEvent()
{
- AfterBeanDiscoveryImpl event = new AfterBeanDiscoveryImpl(deploymentManager, beanDeployments);
+ AfterBeanDiscoveryImpl event = new AfterBeanDiscoveryImpl(deploymentManager, deployment, beanDeployments);
try
{
deploymentManager.fireEvent(event);
@@ -346,21 +363,21 @@
protected void initializeContexts()
{
- deploymentManager.addContext(getServices().get(DependentContext.class));
- deploymentManager.addContext(getServices().get(RequestContext.class));
- deploymentManager.addContext(getServices().get(ConversationContext.class));
- deploymentManager.addContext(getServices().get(SessionContext.class));
- deploymentManager.addContext(getServices().get(ApplicationContext.class));
+ deploymentManager.addContext(deploymentManager.getServices().get(DependentContext.class));
+ deploymentManager.addContext(deploymentManager.getServices().get(RequestContext.class));
+ deploymentManager.addContext(deploymentManager.getServices().get(ConversationContext.class));
+ deploymentManager.addContext(deploymentManager.getServices().get(SessionContext.class));
+ deploymentManager.addContext(deploymentManager.getServices().get(ApplicationContext.class));
}
protected void createContexts()
{
- getServices().add(ContextLifecycle.class, new ContextLifecycle());
- getServices().add(DependentContext.class, new DependentContext());
- getServices().add(RequestContext.class, new RequestContext());
- getServices().add(ConversationContext.class, new ConversationContext());
- getServices().add(SessionContext.class, new SessionContext());
- getServices().add(ApplicationContext.class, new ApplicationContext());
+ deployment.getServices().add(ContextLifecycle.class, new ContextLifecycle());
+ deployment.getServices().add(DependentContext.class, new DependentContext());
+ deployment.getServices().add(RequestContext.class, new RequestContext());
+ deployment.getServices().add(ConversationContext.class, new ConversationContext());
+ deployment.getServices().add(SessionContext.class, new SessionContext());
+ deployment.getServices().add(ApplicationContext.class, new ApplicationContext());
}
protected void beginApplication(BeanStore applicationBeanStore)
@@ -383,5 +400,16 @@
deploymentManager.shutdown();
}
}
+
+ protected static void verifyServices(ServiceRegistry services, Set<Class<? extends Service>> requiredServices)
+ {
+ for (Class<? extends Service> serviceType : requiredServices)
+ {
+ if (!services.contains(serviceType))
+ {
+ throw new IllegalStateException("Required service " + serviceType.getName() + " has not been specified");
+ }
+ }
+ }
}
Modified: ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java
===================================================================
--- ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/porting-package/src/main/java/org/jboss/webbeans/tck/BeansImpl.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -5,7 +5,6 @@
import org.jboss.jsr299.tck.spi.Beans;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
-import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.util.Proxies;
/**
@@ -70,13 +69,7 @@
public <T> T getEnterpriseBean(Class<? extends T> beanType, Class<T> localInterface)
{
- // Get the EJB Descriptor and resolve it
- if (CurrentManager.rootManager().getNewEnterpriseBeanMap().containsKey(beanType))
- {
- EjbDescriptor<?> ejbDescriptor = CurrentManager.rootManager().getNewEnterpriseBeanMap().get(beanType).getEjbDescriptor().delegate();
- return CurrentManager.rootManager().getServices().get(EjbServices.class).resolveEjb(ejbDescriptor).getBusinessObject(localInterface);
- }
- throw new NullPointerException("No EJB found for " + localInterface.getName() + " on bean " + beanType.getName());
+ throw new UnsupportedOperationException();
}
public <T> T createBeanInstance(Bean<T> bean)
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Bootstrap.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -49,20 +49,6 @@
{
/**
- * Set the bean store to use as backing for the application context
- *
- * @param beanStore the bean store to use
- */
- public void setApplicationContext(BeanStore beanStore);
-
- /**
- * Set the environment in use, by default {@link Environments.EE}
- *
- * @param environment the environment to use
- */
- public void setEnvironment(Environment environment);
-
- /**
* Creates the application container:
* <ul>
* <li>Checks that the services required by the environment have been
@@ -72,13 +58,16 @@
* <li>Creates the manager</li>
* </ul>
*
- * This method name is a workaround for weird JBoss MC behavior, calling
- *
- *
+ * @param beanStore the bean store to use as backing for the application
+ * context
+ * @param environment the environment in use, by default
+ * {@link Environments.EE}
+ * @param deployment the Deployment to be booted
* @throws IllegalStateException if not all the services required for the
* given environment are available
+ *
*/
- public Bootstrap startContainer();
+ public Bootstrap startContainer(Environment environment, Deployment deployment, BeanStore beanStore);
/**
* Starts the application container initialization process:
@@ -130,13 +119,6 @@
public void shutdown();
/**
- * Get the services available to this bootstrap
- *
- * @return the services available
- */
- public ServiceRegistry getServices();
-
- /**
* Get the manager used for this beanDeploymentArchive.
*
* If {@link #startContainer()} has not been called, this method will return
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environment.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -19,8 +19,8 @@
import java.util.Set;
/**
- * Represents an environment. Used to control which services Web Beans will require
- * in order to boot
+ * Represents an environment. Specifies the services Web Beans requires
+ *
* @author Pete Muir
*
*/
@@ -28,10 +28,12 @@
{
/**
- * The services to require for this environment
+ * The deployment scoped services required for this environment
*
* @return the services to require
*/
- public Set<Class<? extends Service>> getRequiredServices();
+ public Set<Class<? extends Service>> getRequiredDeploymentServices();
+
+ public Set<Class<? extends Service>> getRequiredBeanDeploymentArchiveServices();
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/Environments.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -16,11 +16,9 @@
*/
package org.jboss.webbeans.bootstrap.api;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
-import org.jboss.webbeans.bootstrap.spi.Deployment;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.jsf.spi.JSFServices;
import org.jboss.webbeans.persistence.spi.JpaServices;
@@ -43,33 +41,87 @@
/**
* Java EE5 or Java EE6
*/
- EE(Deployment.class, EjbServices.class, JpaServices.class, ResourceServices.class, TransactionServices.class, ResourceLoader.class, SecurityServices.class, ValidationServices.class, ServletServices.class, JSFServices.class),
+ EE(new EnvironmentBuilder()
+ .addRequiredDeploymentService(TransactionServices.class)
+ .addRequiredDeploymentService(ResourceLoader.class)
+ .addRequiredDeploymentService(SecurityServices.class)
+ .addRequiredDeploymentService(ValidationServices.class)
+ .addRequiredDeploymentService(ServletServices.class)
+ .addRequiredDeploymentService(JSFServices.class)
+ .addRequiredBeanDeploymentArchiveService(JpaServices.class)
+ .addRequiredBeanDeploymentArchiveService(ResourceServices.class)
+ .addRequiredBeanDeploymentArchiveService(EjbServices.class)
+ ),
/**
- * Java EE6 Web Profile
- */
- EE_WEB_PROFILE(Deployment.class, EjbServices.class, JpaServices.class, ResourceServices.class, TransactionServices.class, ResourceLoader.class, SecurityServices.class, ValidationServices.class, ServletServices.class, JSFServices.class),
-
- /**
* Servlet container such as Tomcat
*/
- SERVLET(Deployment.class, ResourceLoader.class, ServletServices.class),
+ SERVLET(new EnvironmentBuilder()
+ .addRequiredDeploymentService(ResourceLoader.class)
+ .addRequiredDeploymentService(ServletServices.class)
+ ),
/**
* Java SE
*/
- SE(Deployment.class, ResourceLoader.class);
+ SE(new EnvironmentBuilder()
+ );
- private final Set<Class<? extends Service>> requiredServices;
+ private final Set<Class<? extends Service>> requiredDeploymentServices;
- private Environments(Class<? extends Service>... requiredServices)
+ private final Set<Class<? extends Service>> requiredBeanDeploymentArchiveServices;
+
+ private Environments(EnvironmentBuilder builder)
{
- this.requiredServices = new HashSet<Class<? extends Service>>(Arrays.asList(requiredServices));
+ this.requiredDeploymentServices = builder.getRequiredDeploymentServices();
+ this.requiredBeanDeploymentArchiveServices = builder.getRequiredBeanDeploymentArchiveServices();
}
- public Set<Class<? extends Service>> getRequiredServices()
+ public Set<Class<? extends Service>> getRequiredDeploymentServices()
{
- return requiredServices;
+ return requiredDeploymentServices;
}
+ public Set<Class<? extends Service>> getRequiredBeanDeploymentArchiveServices()
+ {
+ return requiredBeanDeploymentArchiveServices;
+ }
+
+ private static class EnvironmentBuilder
+ {
+
+ private final Set<Class<? extends Service>> requiredDeploymentServices;
+
+ private final Set<Class<? extends Service>> requiredBeanDeploymentArchiveServices;
+
+ public EnvironmentBuilder()
+ {
+ this.requiredBeanDeploymentArchiveServices = new HashSet<Class<? extends Service>>();
+ this.requiredDeploymentServices = new HashSet<Class<? extends Service>>();
+ }
+
+ public Set<Class<? extends Service>> getRequiredBeanDeploymentArchiveServices()
+ {
+ return requiredBeanDeploymentArchiveServices;
+ }
+
+ public Set<Class<? extends Service>> getRequiredDeploymentServices()
+ {
+ return requiredDeploymentServices;
+ }
+
+ public EnvironmentBuilder addRequiredDeploymentService(Class<? extends Service> service)
+ {
+ this.requiredDeploymentServices.add(service);
+ return this;
+ }
+
+ public EnvironmentBuilder addRequiredBeanDeploymentArchiveService(Class<? extends Service> service)
+ {
+ this.requiredBeanDeploymentArchiveServices.add(service);
+ return this;
+ }
+
+ }
+
}
\ No newline at end of file
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/ServiceRegistry.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -1,5 +1,9 @@
package org.jboss.webbeans.bootstrap.api;
+import java.util.Collection;
+import java.util.Set;
+import java.util.Map.Entry;
+
/**
* A service registry
*
@@ -10,7 +14,7 @@
{
/**
- * Add a service to bootstrap
+ * Add a service
*
* @see Service
*
@@ -21,6 +25,15 @@
public <S extends Service> void add(Class<S> type, S service);
/**
+ * Add services
+ *
+ * @param services
+ */
+ public void addAll(Collection<Entry<Class<? extends Service>, Service>> services);
+
+ public Set<Entry<Class<? extends Service>, Service>> entrySet();
+
+ /**
* Retrieve a service implementation
*
* @param <S> the service type
@@ -38,4 +51,6 @@
*/
public <S extends Service> boolean contains(Class<S> type);
+
+
}
\ No newline at end of file
Deleted: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/AbstractBootstrap.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -1,87 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.webbeans.bootstrap.api.helpers;
-
-import static org.jboss.webbeans.bootstrap.api.Environments.EE;
-
-import org.jboss.webbeans.bootstrap.api.Bootstrap;
-import org.jboss.webbeans.bootstrap.api.Environment;
-import org.jboss.webbeans.bootstrap.api.Service;
-import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
-import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
-import org.jboss.webbeans.context.api.BeanStore;
-import org.jboss.webbeans.ejb.spi.EjbServices;
-import org.jboss.webbeans.resources.spi.ResourceLoader;
-import org.jboss.webbeans.transaction.spi.TransactionServices;
-
-/**
- * A common implementation of {@link Bootstrap}.
- *
- * Not threadsafe
- *
- * @author Pete Muir
- *
- */
-public abstract class AbstractBootstrap implements Bootstrap
-{
- private final ServiceRegistry simpleServiceRegistry;
- private Environment environment = EE;
-
- private BeanStore applicationContext;
-
- public AbstractBootstrap()
- {
- this.simpleServiceRegistry = new SimpleServiceRegistry();
- }
-
- public BeanStore getApplicationContext()
- {
- return applicationContext;
- }
-
- public void setApplicationContext(BeanStore applicationContext)
- {
- this.applicationContext = applicationContext;
- }
-
- public Environment getEnvironment()
- {
- return environment;
- }
-
- public void setEnvironment(Environment environment)
- {
- this.environment = environment;
- }
-
- protected void verify()
- {
- for (Class<? extends Service> serviceType : environment.getRequiredServices())
- {
- if (!getServices().contains(serviceType))
- {
- throw new IllegalStateException("Required service " + serviceType.getName() + " has not been specified");
- }
- }
- }
-
- public ServiceRegistry getServices()
- {
- return simpleServiceRegistry;
- }
-
-}
\ No newline at end of file
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingBootstrap.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -18,8 +18,8 @@
import org.jboss.webbeans.bootstrap.api.Bootstrap;
import org.jboss.webbeans.bootstrap.api.Environment;
-import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.webbeans.bootstrap.spi.Deployment;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.manager.api.WebBeansManager;
@@ -37,11 +37,10 @@
{
return delegate().getManager(beanDeploymentArchive);
}
-
- public void setApplicationContext(BeanStore beanStore)
+ public Bootstrap startContainer(Environment environment, Deployment deployment, BeanStore beanStore)
{
- delegate().setApplicationContext(beanStore);
+ return delegate().startContainer(environment, deployment, beanStore);
}
public void shutdown()
@@ -77,16 +76,6 @@
return delegate().endInitialization();
}
- public ServiceRegistry getServices()
- {
- return delegate().getServices();
- }
-
- public void setEnvironment(Environment environment)
- {
- delegate().setEnvironment(environment);
- }
-
public Bootstrap startInitialization()
{
return delegate().startInitialization();
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/ForwardingServiceRegistry.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -1,6 +1,9 @@
package org.jboss.webbeans.bootstrap.api.helpers;
+import java.util.Collection;
import java.util.Iterator;
+import java.util.Set;
+import java.util.Map.Entry;
import org.jboss.webbeans.bootstrap.api.Service;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
@@ -29,5 +32,15 @@
{
return delegate().iterator();
}
+
+ public void addAll(Collection<Entry<Class<? extends Service>, Service>> services)
+ {
+ delegate().addAll(services);
+ }
+
+ public Set<Entry<Class<? extends Service>, Service>> entrySet()
+ {
+ return delegate().entrySet();
+ }
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/api/helpers/SimpleServiceRegistry.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -16,9 +16,11 @@
*/
package org.jboss.webbeans.bootstrap.api.helpers;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.Map.Entry;
import org.jboss.webbeans.bootstrap.api.Service;
@@ -42,16 +44,27 @@
public <S extends Service> void add(java.lang.Class<S> type, S service)
{
- if (service == null)
- {
- services.remove(type);
- }
- else
- {
- services.put(type, service);
- }
+ services.put(type, service);
}
+ public void addAll(Collection<Entry<Class<? extends Service>, Service>> services)
+ {
+ for (Entry<Class<? extends Service >, Service> entry : services)
+ {
+ this.services.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ public Set<Entry<Class<? extends Service>, Service>> entrySet()
+ {
+ return services.entrySet();
+ }
+
+ protected Map<Class<? extends Service>, Service> get()
+ {
+ return services;
+ }
+
@SuppressWarnings("unchecked")
public <S extends Service> S get(Class<S> type)
{
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/BeanDeploymentArchive.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/BeanDeploymentArchive.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/BeanDeploymentArchive.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -19,6 +19,7 @@
import java.net.URL;
import java.util.Collection;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
/**
@@ -87,5 +88,12 @@
* this is not an EJB archive
*/
public Collection<EjbDescriptor<?>> getEjbs();
+
+ /**
+ * Get the Bean Deployment Archive scoped services
+ *
+ * @return
+ */
+ public ServiceRegistry getServices();
}
Modified: ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/Deployment.java
===================================================================
--- ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/Deployment.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/main/java/org/jboss/webbeans/bootstrap/spi/Deployment.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -18,7 +18,7 @@
import java.util.Collection;
-import org.jboss.webbeans.bootstrap.api.Service;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
/**
* Represents a deployment of a CDI application.
@@ -112,7 +112,7 @@
* @author Pete Muir
*
*/
-public interface Deployment extends Service
+public interface Deployment
{
/**
@@ -142,5 +142,13 @@
* @return the {@link BeanDeploymentArchive} containing the bean class
*/
public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass);
+
+ /**
+ * Get the services available to this deployment
+ *
+ * @return the services available
+ */
+ public ServiceRegistry getServices();
+
}
Modified: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/BootstrapTest.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -1,9 +1,11 @@
package org.jboss.webbeans.bootstrap.api.test;
+import org.jboss.webbeans.bootstrap.api.Bootstrap;
import org.jboss.webbeans.bootstrap.api.Environments;
-import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
+import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.webbeans.bootstrap.api.test.MockDeployment.MockBeanDeploymentArchive;
import org.jboss.webbeans.bootstrap.spi.Deployment;
-import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.jsf.spi.JSFServices;
import org.jboss.webbeans.persistence.spi.JpaServices;
@@ -17,220 +19,209 @@
public class BootstrapTest
{
-
- @Test(expectedExceptions=IllegalStateException.class)
- public void testMissingDeployment()
- {
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.SE);
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.startContainer();
- }
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingEjbServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingJpaServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingSecurityServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingValidationServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
+
@Test
public void testEEEnv()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
- @Test
- public void testEEWebProfileEnv()
- {
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE_WEB_PROFILE);
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
- }
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingTxServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingResourceServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingJSFServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
- @Test(expectedExceptions=IllegalStateException.class)
+
+ @Test(expectedExceptions = IllegalStateException.class)
public void testMissingServletServices()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.EE);
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(EjbServices.class, new MockEjbServices());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(JpaServices.class, new MockJpaServices());
- bootstrap.getServices().add(TransactionServices.class, new MockTransactionServices());
- bootstrap.getServices().add(SecurityServices.class, new MockSecurityServices());
- bootstrap.getServices().add(ValidationServices.class, new MockValidationServices());
- bootstrap.getServices().add(ResourceServices.class, new MockResourceServices());
- bootstrap.getServices().add(JSFServices.class, new MockJSFServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(TransactionServices.class, new MockTransactionServices());
+ deploymentServices.add(SecurityServices.class, new MockSecurityServices());
+ deploymentServices.add(ValidationServices.class, new MockValidationServices());
+ deploymentServices.add(JSFServices.class, new MockJSFServices());
+
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ bdaServices.add(EjbServices.class, new MockEjbServices());
+ bdaServices.add(JpaServices.class, new MockJpaServices());
+ bdaServices.add(ResourceServices.class, new MockResourceServices());
+
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.EE, deployment, null);
}
-
+
@Test
public void testSEEnv()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.SE);
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.SE, deployment, null);
}
-
+
@Test
public void testServletEnv()
{
- AbstractBootstrap bootstrap = new MockBootstrap();
- bootstrap.setEnvironment(Environments.SERVLET);
- bootstrap.getServices().add(ResourceLoader.class, new MockResourceLoader());
- bootstrap.setApplicationContext(new ConcurrentHashMapBeanStore());
- bootstrap.getServices().add(Deployment.class, new MockDeployment());
- bootstrap.getServices().add(ServletServices.class, new MockServletServices());
- bootstrap.startContainer();
+ Bootstrap bootstrap = new MockBootstrap();
+ ServiceRegistry deploymentServices = new SimpleServiceRegistry();
+ deploymentServices.add(ResourceLoader.class, new MockResourceLoader());
+ deploymentServices.add(ServletServices.class, new MockServletServices());
+ ServiceRegistry bdaServices = new SimpleServiceRegistry();
+ Deployment deployment = new MockDeployment(deploymentServices, new MockBeanDeploymentArchive(bdaServices));
+ bootstrap.startContainer(Environments.SERVLET, deployment, null);
}
-
+
}
Modified: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockBootstrap.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -1,11 +1,17 @@
package org.jboss.webbeans.bootstrap.api.test;
+import java.util.Set;
+
import org.jboss.webbeans.bootstrap.api.Bootstrap;
-import org.jboss.webbeans.bootstrap.api.helpers.AbstractBootstrap;
+import org.jboss.webbeans.bootstrap.api.Environment;
+import org.jboss.webbeans.bootstrap.api.Service;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.webbeans.bootstrap.spi.Deployment;
+import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.manager.api.WebBeansManager;
-public class MockBootstrap extends AbstractBootstrap
+public class MockBootstrap implements Bootstrap
{
public WebBeansManager getManager(BeanDeploymentArchive beanDeploymentArchive)
@@ -13,14 +19,6 @@
return null;
}
- public Bootstrap startContainer()
- {
- verify();
- return this;
- }
-
-
-
public void shutdown()
{
}
@@ -45,4 +43,23 @@
return this;
}
+ protected static void verifyServices(ServiceRegistry services, Set<Class<? extends Service>> requiredServices)
+ {
+ for (Class<? extends Service> serviceType : requiredServices)
+ {
+ if (!services.contains(serviceType))
+ {
+ throw new IllegalStateException("Required service " + serviceType.getName() + " has not been specified");
+ }
+ }
+ }
+
+ public Bootstrap startContainer(Environment environment, Deployment deployment, BeanStore beanStore)
+ {
+ verifyServices(deployment.getServices(), environment.getRequiredDeploymentServices());
+ verifyServices(deployment.getBeanDeploymentArchives().iterator().next().getServices(), environment.getRequiredBeanDeploymentArchiveServices());
+ return this;
+ }
+
+
}
Modified: ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockDeployment.java
===================================================================
--- ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockDeployment.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/spi/src/test/java/org/jboss/webbeans/bootstrap/api/test/MockDeployment.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -16,10 +16,15 @@
*/
package org.jboss.webbeans.bootstrap.api.test;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.webbeans.bootstrap.spi.Deployment;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
/**
* @author pmuir
@@ -27,10 +32,56 @@
*/
public class MockDeployment implements Deployment
{
+
+ static class MockBeanDeploymentArchive implements BeanDeploymentArchive
+ {
+ private final ServiceRegistry services;
+
+ public MockBeanDeploymentArchive(ServiceRegistry services)
+ {
+ this.services = services;
+ }
+
+ public Collection<Class<?>> getBeanClasses()
+ {
+ return Collections.emptySet();
+ }
+
+ public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
+ {
+ return Collections.emptySet();
+ }
+
+ public Collection<URL> getBeansXml()
+ {
+ return Collections.emptySet();
+ }
+
+ public Collection<EjbDescriptor<?>> getEjbs()
+ {
+ return Collections.emptySet();
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return services;
+ }
+
+ }
+
+ private final ServiceRegistry services;
+ private final BeanDeploymentArchive beanDeploymentArchive;
+
+ public MockDeployment(ServiceRegistry services, MockBeanDeploymentArchive beanDeploymentArchive)
+ {
+ this.services = services;
+ this.beanDeploymentArchive = beanDeploymentArchive;
+ }
+
public List<BeanDeploymentArchive> getBeanDeploymentArchives()
{
- return null;
+ return Collections.singletonList(beanDeploymentArchive);
}
public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass)
@@ -38,4 +89,9 @@
return null;
}
+ public ServiceRegistry getServices()
+ {
+ return services;
+ }
+
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockBeanDeploymentArchive.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockBeanDeploymentArchive.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockBeanDeploymentArchive.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -29,6 +29,8 @@
import javax.ejb.Stateful;
import javax.ejb.Stateless;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
+import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
@@ -40,14 +42,36 @@
{
- private Set<Class<?>> beanClasses = new HashSet<Class<?>>();
+ private Set<Class<?>> beanClasses;
+ private Collection<URL> webBeansXmlFiles;
+ private List<EjbDescriptor<?>> ejbs;
+ private final ServiceRegistry services;
+
+ public MockBeanDeploymentArchive()
+ {
+ this.services = new SimpleServiceRegistry();
+ this.beanClasses = new HashSet<Class<?>>();
+ this.webBeansXmlFiles = new HashSet<URL>();
+ }
- private Collection<URL> webBeansXmlFiles = new HashSet<URL>();
-
public Collection<Class<?>> getBeanClasses()
{
return beanClasses;
}
+
+ public void setBeanClasses(Iterable<Class<?>> beanClasses)
+ {
+ this.beanClasses.clear();
+ for (Class<?> clazz : beanClasses)
+ {
+ this.beanClasses.add(clazz);
+ }
+ ejbs = new ArrayList<EjbDescriptor<?>>();
+ for (Class<?> ejbClass : discoverEjbs(getBeanClasses()))
+ {
+ ejbs.add(MockEjbDescriptor.of(ejbClass));
+ }
+ }
public Collection<URL> getBeansXml()
{
@@ -68,22 +92,6 @@
return Collections.emptyList();
}
- private List<EjbDescriptor<?>> ejbs;
-
- public void setBeanClasses(Iterable<Class<?>> beanClasses)
- {
- this.beanClasses.clear();
- for (Class<?> clazz : beanClasses)
- {
- this.beanClasses.add(clazz);
- }
- ejbs = new ArrayList<EjbDescriptor<?>>();
- for (Class<?> ejbClass : discoverEjbs(getBeanClasses()))
- {
- ejbs.add(MockEjbDescriptor.of(ejbClass));
- }
- }
-
public Collection<EjbDescriptor<?>> getEjbs()
{
return ejbs;
@@ -101,5 +109,10 @@
}
return ejbs;
}
+
+ public ServiceRegistry getServices()
+ {
+ return services;
+ }
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockDeployment.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockDeployment.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockDeployment.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -19,19 +19,22 @@
import java.util.ArrayList;
import java.util.List;
+import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
+import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.webbeans.bootstrap.spi.Deployment;
public class MockDeployment implements Deployment
{
- private MockBeanDeploymentArchive archive;
+ private final MockBeanDeploymentArchive archive;
+ private final List<BeanDeploymentArchive> beanDeploymentArchives;
+ private final ServiceRegistry services;
- private List<BeanDeploymentArchive> beanDeploymentArchives;
-
public MockDeployment()
{
this.archive = new MockBeanDeploymentArchive();
+ this.services = new SimpleServiceRegistry();
this.beanDeploymentArchives = new ArrayList<BeanDeploymentArchive>();
this.beanDeploymentArchives.add(archive);
}
@@ -51,4 +54,9 @@
return archive;
}
+ public ServiceRegistry getServices()
+ {
+ return services;
+ }
+
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockEELifecycle.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -16,6 +16,7 @@
*/
package org.jboss.webbeans.mock;
+import org.jboss.webbeans.bootstrap.api.Environment;
import org.jboss.webbeans.bootstrap.api.Environments;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.jsf.spi.JSFServices;
@@ -33,16 +34,18 @@
public MockEELifecycle()
{
super();
- getBootstrap().getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
- getBootstrap().getServices().add(EjbServices.class, new MockEjBServices());
- getBootstrap().getServices().add(JpaServices.class, new MockJpaServices(getDeployment()));
- getBootstrap().getServices().add(ResourceServices.class, new MockResourceServices());
- getBootstrap().getServices().add(SecurityServices.class, new MockSecurityServices());
- getBootstrap().getServices().add(ValidationServices.class, new MockValidationServices());
- getBootstrap().getServices().add(JSFServices.class, new MockJSFServices());
- getBootstrap().setEnvironment(Environments.EE);
+ getDeployment().getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
+ getDeployment().getServices().add(SecurityServices.class, new MockSecurityServices());
+ getDeployment().getServices().add(ValidationServices.class, new MockValidationServices());
+ getDeployment().getServices().add(JSFServices.class, new MockJSFServices());
+ getDeployment().getArchive().getServices().add(EjbServices.class, new MockEjBServices());
+ getDeployment().getArchive().getServices().add(JpaServices.class, new MockJpaServices(getDeployment()));
+ getDeployment().getArchive().getServices().add(ResourceServices.class, new MockResourceServices());
}
-
+ public Environment getEnvironment()
+ {
+ return Environments.EE;
+ }
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/mock/MockServletLifecycle.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -1,8 +1,8 @@
package org.jboss.webbeans.mock;
import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
+import org.jboss.webbeans.bootstrap.api.Environment;
import org.jboss.webbeans.bootstrap.api.Environments;
-import org.jboss.webbeans.bootstrap.spi.Deployment;
import org.jboss.webbeans.context.ContextLifecycle;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
@@ -27,16 +27,13 @@
throw new IllegalStateException("No WebBeanDiscovery is available");
}
bootstrap = new WebBeansBootstrap();
- bootstrap.setEnvironment(Environments.SERVLET);
- bootstrap.getServices().add(ResourceLoader.class, MOCK_RESOURCE_LOADER);
- bootstrap.getServices().add(Deployment.class, deployment);
- bootstrap.getServices().add(ServletServices.class, new MockServletServices(deployment.getArchive()));
- bootstrap.setApplicationContext(applicationBeanStore);
+ deployment.getServices().add(ResourceLoader.class, MOCK_RESOURCE_LOADER);
+ deployment.getServices().add(ServletServices.class, new MockServletServices(deployment.getArchive()));
}
public void initialize()
{
- bootstrap.startContainer();
+ bootstrap.startContainer(getEnvironment(), getDeployment(), getApplicationBeanStore());
}
public MockDeployment getDeployment()
@@ -59,6 +56,11 @@
bootstrap.shutdown();
}
+ public BeanStore getApplicationBeanStore()
+ {
+ return applicationBeanStore;
+ }
+
public void resetContexts()
{
@@ -84,4 +86,9 @@
// TODO Conversation handling breaks this :-(
//super.endSession("Mock", sessionBeanStore);
}
+
+ public Environment getEnvironment()
+ {
+ return Environments.SERVLET;
+ }
}
Modified: ri/trunk/tests/src/main/java/org/jboss/webbeans/test/harness/AbstractStandaloneContainersImpl.java
===================================================================
--- ri/trunk/tests/src/main/java/org/jboss/webbeans/test/harness/AbstractStandaloneContainersImpl.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/tests/src/main/java/org/jboss/webbeans/test/harness/AbstractStandaloneContainersImpl.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -17,7 +17,7 @@
public boolean deploy(Iterable<Class<?>> classes, Iterable<URL> beansXml)
{
this.lifecycle = newLifecycle();
- lifecycle.initialize();
+
try
{
MockBeanDeploymentArchive archive = lifecycle.getDeployment().getArchive();
@@ -26,6 +26,7 @@
{
archive.setWebBeansXmlFiles(beansXml);
}
+ lifecycle.initialize();
lifecycle.beginApplication();
}
catch (Exception e)
Modified: ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java
===================================================================
--- ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java 2009-08-26 15:54:38 UTC (rev 3595)
+++ ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/DiscoverFailsBootstrapTest.java 2009-08-26 15:57:55 UTC (rev 3596)
@@ -1,17 +1,16 @@
package org.jboss.webbeans.test.unit.bootstrap;
-import org.jboss.webbeans.bootstrap.spi.Deployment;
import org.jboss.webbeans.mock.MockEELifecycle;
import org.testng.annotations.Test;
public class DiscoverFailsBootstrapTest
{
- @Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
+ @Test(groups="bootstrap", expectedExceptions=IllegalArgumentException.class)
public void testDiscoverFails()
{
MockEELifecycle lifecycle = new MockEELifecycle();
- lifecycle.getBootstrap().getServices().add(Deployment.class, null);
+ lifecycle.getBootstrap().startContainer(lifecycle.getEnvironment(), null, lifecycle.getApplicationBeanStore());
lifecycle.initialize();
lifecycle.beginApplication();
}
More information about the weld-commits
mailing list