Skip to content

Commit

Permalink
WBRI-175, WBRI-178
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2000 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Mar 15, 2009
1 parent f6ba790 commit 4f53ade
Show file tree
Hide file tree
Showing 41 changed files with 751 additions and 191 deletions.
47 changes: 26 additions & 21 deletions impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
Expand Up @@ -268,26 +268,28 @@ protected void initResourceInjectionPoints()
*/
protected void injectEjbAndCommonFields(T beanInstance)
{
NamingContext namingContext = manager.getServices().get(NamingContext.class);
EjbServices ejbServices = manager.getServices().get(EjbServices.class);
for (AnnotatedInjectionPoint<?, ?> injectionPoint : ejbInjectionPoints)
if (getManager().getServices().contains(EjbServices.class))
{
Object ejbInstance = ejbServices.resolveEjb(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, ejbInstance);
}

for (AnnotatedInjectionPoint<?, ?> injectionPoint : persistenceUnitInjectionPoints)
{
Object puInstance = ejbServices.resolvePersistenceContext(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, puInstance);
}

for (AnnotatedInjectionPoint<?, ?> injectionPoint : resourceInjectionPoints)
{
Object resourceInstance = ejbServices.resolveResource(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, resourceInstance);
EjbServices ejbServices = manager.getServices().get(EjbServices.class);
NamingContext namingContext = manager.getServices().get(NamingContext.class);
for (AnnotatedInjectionPoint<?, ?> injectionPoint : ejbInjectionPoints)
{
Object ejbInstance = ejbServices.resolveEjb(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, ejbInstance);
}

for (AnnotatedInjectionPoint<?, ?> injectionPoint : persistenceUnitInjectionPoints)
{
Object puInstance = ejbServices.resolvePersistenceContext(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, puInstance);
}

for (AnnotatedInjectionPoint<?, ?> injectionPoint : resourceInjectionPoints)
{
Object resourceInstance = ejbServices.resolveResource(injectionPoint, namingContext);
injectionPoint.inject(beanInstance, resourceInstance);
}
}

}

/**
Expand All @@ -302,9 +304,12 @@ protected void init()
initInjectionPoints();
initPostConstruct();
initPreDestroy();
initEjbInjectionPoints();
initPersistenceUnitInjectionPoints();
initResourceInjectionPoints();
if (getManager().getServices().contains(EjbServices.class))
{
initEjbInjectionPoints();
initPersistenceUnitInjectionPoints();
initResourceInjectionPoints();
}
}

/**
Expand Down
Expand Up @@ -27,6 +27,7 @@
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.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.ApplicationContext;
import org.jboss.webbeans.context.ConversationContext;
import org.jboss.webbeans.context.DependentContext;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void initialize()
}
if (!getServices().contains(EjbServices.class))
{
log.info("EJB services not available. Session beans, injection into non-contextual EJBs, injection of @Resource, @PersistenceContext and @EJB in simple beans, injection of Java EE resources and JMS resources will not be available.");
log.info("EJB services not available. Session beans will be simple beans, injection into non-contextual EJBs, injection of @Resource, @PersistenceContext and @EJB in simple beans, injection of Java EE resources and JMS resources will not be available.");
}
this.manager = new ManagerImpl(getServices());
getServices().get(NamingContext.class).bind(ManagerImpl.JNDI_KEY, getManager());
Expand Down Expand Up @@ -122,37 +123,28 @@ public void boot()
{
throw new IllegalStateException("Manager has not been initialized");
}
if (getWebBeanDiscovery() == null)
{
throw new IllegalStateException("WebBeanDiscovery not set");
}
if (getEjbDiscovery() == null)
{
throw new IllegalStateException("EjbDiscovery is not set");
}
if (getResourceLoader() == null)
{
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());
BeansXmlParser parser = new BeansXmlParser(getResourceLoader(), getWebBeanDiscovery().discoverWebBeansXml());
if (getServices().contains(EjbServices.class))
{
// Must populate EJB cache first, as we need it to detect whether a
// bean is an EJB!
manager.getEjbDescriptorCache().addAll(getServices().get(EjbServices.class).discoverEjbs());
}
BeansXmlParser parser = new BeansXmlParser(getServices().get(ResourceLoader.class), getServices().get(WebBeanDiscovery.class).discoverWebBeansXml());
parser.parse();
List<Class<? extends Annotation>> enabledDeploymentTypes = parser.getEnabledDeploymentTypes();
if (enabledDeploymentTypes != null)
{
manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
log.info("Deployment types: " + manager.getEnabledDeploymentTypes());
registerBeans(getWebBeanDiscovery().discoverWebBeanClasses());
registerBeans(getServices().get(WebBeanDiscovery.class).discoverWebBeanClasses());
manager.fireEvent(manager, new InitializedLiteral());
log.info("Web Beans initialized. Validating beans.");
manager.getResolver().resolveInjectionPoints();
Expand Down
Expand Up @@ -14,30 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.webbeans.mock;

package org.jboss.webbeans.bootstrap.spi;
import org.jboss.webbeans.bootstrap.api.Environments;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.transaction.spi.TransactionServices;

import org.jboss.webbeans.bootstrap.api.Service;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;



/**
* A container should implement this interface to allow the Web Beans RI to
* discover the EJBs the application contains
*
* @author Pete Muir
*
*/
public interface EjbDiscovery extends Service
public class MockEELifecycle extends MockServletLifecycle
{
public static final String PROPERTY_NAME = EjbDiscovery.class.getName();

/**
* Gets a descriptor for each EJB in the application
*
* @return The bean class to descriptor map
*/
public Iterable<EjbDescriptor<?>> discoverEjbs();
private static final TransactionServices MOCK_TRANSACTION_SERVICES = new MockTransactionServices();

public MockEELifecycle()
{
super();
getBootstrap().getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
getBootstrap().getServices().add(EjbServices.class, new MockEjBServices(getWebBeanDiscovery()));
getBootstrap().setEnvironment(Environments.EE);
}



}
16 changes: 15 additions & 1 deletion impl/src/main/java/org/jboss/webbeans/mock/MockEjBServices.java
Expand Up @@ -11,13 +11,22 @@
import javax.inject.manager.InjectionPoint;
import javax.persistence.PersistenceContext;

import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.api.EjbReference;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.resources.spi.NamingContext;

final class MockEjBServices implements EjbServices
public class MockEjBServices implements EjbServices
{

private final MockEjbDiscovery ejbDiscovery;

public MockEjBServices(WebBeanDiscovery webBeanDiscovery)
{
this.ejbDiscovery = new MockEjbDiscovery(webBeanDiscovery);
}

public Class<? extends Annotation> getEJBAnnotation()
{
return EJB.class;
Expand Down Expand Up @@ -52,6 +61,11 @@ public void removeEjb(Collection<Object> instance)
{
// No-op
}

public Iterable<EjbDescriptor<?>> discoverEjbs()
{
return ejbDiscovery.discoverEjbs();
}

public <T> EjbReference<T> resolveEJB(EjbDescriptor<T> ejbDescriptor, NamingContext naming)
{
Expand Down
Expand Up @@ -26,11 +26,10 @@
import javax.ejb.Stateful;
import javax.ejb.Stateless;

import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;

public class MockEjbDiscovery implements EjbDiscovery
public class MockEjbDiscovery
{

private final WebBeanDiscovery webBeanDiscovery;
Expand Down
@@ -1,67 +1,41 @@
/*
* 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.mock;



import org.jboss.webbeans.bootstrap.WebBeansBootstrap;
import org.jboss.webbeans.bootstrap.spi.EjbDiscovery;
import org.jboss.webbeans.bootstrap.api.Environments;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.context.api.BeanStore;
import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.webbeans.ejb.spi.EjbServices;
import org.jboss.webbeans.resources.spi.NamingContext;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.AbstractLifecycle;
import org.jboss.webbeans.transaction.spi.TransactionServices;

public class MockLifecycle extends AbstractLifecycle
{

private static final EjbServices MOCK_EJB_RESOLVER = new MockEjBServices();
public class MockServletLifecycle extends AbstractLifecycle
{
private static final ResourceLoader MOCK_RESOURCE_LOADER = new MockResourceLoader();
private static final TransactionServices MOCK_TRANSACTION_SERVICES = new MockTransactionServices();

private final WebBeansBootstrap bootstrap;
private final MockWebBeanDiscovery webBeanDiscovery;
private final BeanStore applicationBeanStore = new ConcurrentHashMapBeanStore();
private final BeanStore sessionBeanStore = new ConcurrentHashMapBeanStore();
private final BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();

public MockLifecycle()
{
this(new MockWebBeanDiscovery());
}

public MockLifecycle(MockWebBeanDiscovery mockWebBeanDiscovery)
public MockServletLifecycle()
{
this.webBeanDiscovery = mockWebBeanDiscovery;
this.webBeanDiscovery = new MockWebBeanDiscovery();
if (webBeanDiscovery == null)
{
throw new IllegalStateException("No WebBeanDiscovery is available");
}
bootstrap = new WebBeansBootstrap();
bootstrap.setEnvironment(Environments.SERVLET);
bootstrap.getServices().add(NamingContext.class, new MockNamingContext(null));
bootstrap.getServices().add(EjbServices.class, MOCK_EJB_RESOLVER);
bootstrap.getServices().add(ResourceLoader.class, MOCK_RESOURCE_LOADER);
bootstrap.getServices().add(WebBeanDiscovery.class, webBeanDiscovery);
bootstrap.setApplicationContext(applicationBeanStore);
bootstrap.getServices().add(TransactionServices.class, MOCK_TRANSACTION_SERVICES);
bootstrap.getServices().add(EjbDiscovery.class, new MockEjbDiscovery(webBeanDiscovery));
}

public void initialize()
{
bootstrap.initialize();
}

Expand Down Expand Up @@ -110,5 +84,4 @@ public void endSession()
// TODO Conversation handling breaks this :-(
//super.endSession("Mock", sessionBeanStore);
}

}
Expand Up @@ -5,17 +5,33 @@
import org.jboss.testharness.api.DeploymentException;
import org.jboss.testharness.spi.StandaloneContainers;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.mock.MockLifecycle;
import org.jboss.webbeans.mock.MockEELifecycle;
import org.jboss.webbeans.mock.MockServletLifecycle;
import org.jboss.webbeans.mock.MockWebBeanDiscovery;

public class StandaloneContainersImpl implements StandaloneContainers
{

private MockLifecycle lifecycle;
// TODO this is a hack ;-)
public static Class<? extends MockServletLifecycle> lifecycleClass = MockEELifecycle.class;

private MockServletLifecycle lifecycle;

public void deploy(Iterable<Class<?>> classes, Iterable<URL> beansXml) throws DeploymentException
{
this.lifecycle = new MockLifecycle();
try
{
this.lifecycle = lifecycleClass.newInstance();
}
catch (InstantiationException e1)
{
throw new DeploymentException("Error instantiating lifeycle", e1);
}
catch (IllegalAccessException e1)
{
throw new DeploymentException("Error instantiating lifeycle", e1);
}
lifecycle.initialize();
try
{
MockWebBeanDiscovery discovery = lifecycle.getWebBeanDiscovery();
Expand Down
@@ -1,6 +1,7 @@
package org.jboss.webbeans.test.unit.bootstrap;

import org.jboss.webbeans.mock.MockLifecycle;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.mock.MockEELifecycle;
import org.testng.annotations.Test;

public class DiscoverFailsBootstrapTest
Expand All @@ -9,7 +10,9 @@ public class DiscoverFailsBootstrapTest
@Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
public void testDiscoverFails()
{
MockLifecycle lifecycle = new MockLifecycle(null);
MockEELifecycle lifecycle = new MockEELifecycle();
lifecycle.getBootstrap().getServices().add(WebBeanDiscovery.class, null);
lifecycle.initialize();
lifecycle.beginApplication();
}

Expand Down
@@ -0,0 +1,6 @@
package org.jboss.webbeans.test.unit.bootstrap.environments;

interface Animal
{

}
@@ -0,0 +1,6 @@
package org.jboss.webbeans.test.unit.bootstrap.environments;

interface DeadlyAnimal
{

}
@@ -0,0 +1,6 @@
package org.jboss.webbeans.test.unit.bootstrap.environments;

interface DeadlySpider extends DeadlyAnimal
{

}
@@ -0,0 +1,6 @@
package org.jboss.webbeans.test.unit.bootstrap.environments;

class DefangedTarantula extends Tarantula
{

}

0 comments on commit 4f53ade

Please sign in to comment.