[weld-commits] Weld SVN: r4526 - in core/trunk: impl/src/main/java/org/jboss/weld/bootstrap and 14 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Sun Nov 1 17:19:24 EST 2009
Author: pete.muir at jboss.org
Date: 2009-11-01 17:19:24 -0500 (Sun, 01 Nov 2009)
New Revision: 4526
Added:
core/trunk/impl/src/main/java/org/jboss/weld/util/DeploymentStructures.java
core/trunk/impl/src/main/java/org/jboss/weld/util/log/Message.java
core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java
core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoaderFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/PackageServiceLoaderFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoaderFactory.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ExtensionOutsideBDATest.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Foo.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer1.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer2.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ObserverBase.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cat.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Chicken.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cow.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Horse.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Pig.java
core/trunk/tests/src/test/resources/org/jboss/weld/test/unit/deployment/
core/trunk/tests/src/test/resources/org/jboss/weld/test/unit/deployment/structure/
core/trunk/tests/src/test/resources/org/jboss/weld/test/unit/deployment/structure/extensions/
core/trunk/tests/src/test/resources/org/jboss/weld/test/unit/deployment/structure/extensions/javax.enterprise.inject.spi.Extension
Removed:
core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoader.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cat.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Chicken.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cow.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Horse.java
core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Pig.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractBeanDiscoveryEvent.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterBeanDiscoveryImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterDeploymentValidationImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/BeforeBeanDiscoveryImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/util/log/MessageConveyerFactoryLoader.java
core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/AtInjectTCK.java
core/trunk/tests/src/main/java/org/jboss/weld/mock/MockBeanDeploymentArchive.java
core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java
core/trunk/tests/unit-tests.xml
Log:
WELD-212, WELD-233
Modified: core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -540,13 +540,7 @@
accessibleManagers.add(accessibleBeanManager);
beanResolver.clear();
}
-
- protected Set<BeanManagerImpl> getAccessibleManagers()
- {
- return accessibleManagers;
- }
-
public void addBean(Bean<?> bean)
{
if (beans.contains(bean))
@@ -899,7 +893,6 @@
public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> creationalContext)
{
-
if (!Reflections.isAssignableFrom(bean.getTypes(), beanType))
{
throw new IllegalArgumentException("The given beanType is not a type " + beanType +" of the bean " + bean );
@@ -977,6 +970,10 @@
{
Set<Bean<?>> beans = getBeans(beanType, bindings);
Bean<?> bean = resolve(beans);
+ if (bean == null)
+ {
+ throw new UnsatisfiedResolutionException("Unable to resolve any beans. Class: " + beanType + "; Qualifiers: " + Arrays.toString(bindings));
+ }
Object reference = getReference(bean, beanType, createCreationalContext(bean));
@SuppressWarnings("unchecked")
@@ -1092,6 +1089,26 @@
buffer.append("Specialized beans: " + specializedBeans.size() + "\n");
return buffer.toString();
}
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof BeanManagerImpl)
+ {
+ BeanManagerImpl that = (BeanManagerImpl) obj;
+ return this.getId().equals(that.getId());
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getId().hashCode();
+ }
public BeanManagerImpl createActivity()
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -150,7 +150,6 @@
ProcessObserverMethodImpl.fire(manager, observer);
manager.addObserver(observer);
}
-
return this;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -39,18 +39,16 @@
public class BeanDeployer extends AbstractBeanDeployer<BeanDeployerEnvironment>
{
- private final BeanManagerImpl deploymentManager;
private final Set<WeldClass<?>> classes;
/**
* @param manager
* @param ejbDescriptors
*/
- public BeanDeployer(BeanManagerImpl manager, BeanManagerImpl deploymentManager, EjbDescriptors ejbDescriptors)
+ public BeanDeployer(BeanManagerImpl manager, EjbDescriptors ejbDescriptors)
{
super(manager, new BeanDeployerEnvironment(ejbDescriptors, manager));
this.classes = new HashSet<WeldClass<?>>();
- this.deploymentManager = deploymentManager;
}
public BeanDeployer addClass(Class<?> clazz)
@@ -58,7 +56,7 @@
ClassTransformer classTransformer = Container.instance().deploymentServices().get(ClassTransformer.class);
if (!clazz.isAnnotation() && !clazz.isEnum())
{
- ProcessAnnotatedTypeImpl<?> event = ProcessAnnotatedTypeImpl.fire(deploymentManager, classTransformer.loadClass(clazz));
+ ProcessAnnotatedTypeImpl<?> event = ProcessAnnotatedTypeImpl.fire(getManager(), classTransformer.loadClass(clazz));
if (!event.isVeto())
{
if (event.getAnnotatedType() instanceof WeldClass<?>)
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployment.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -25,7 +25,6 @@
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.bean.builtin.DefaultValidatorBean;
import org.jboss.weld.bean.builtin.DefaultValidatorFactoryBean;
-import org.jboss.weld.bean.builtin.ExtensionBean;
import org.jboss.weld.bean.builtin.InjectionPointBean;
import org.jboss.weld.bean.builtin.ManagerBean;
import org.jboss.weld.bean.builtin.PrincipalBean;
@@ -37,14 +36,12 @@
import org.jboss.weld.bootstrap.api.ServiceRegistry;
import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
-import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.conversation.ConversationImpl;
import org.jboss.weld.conversation.JavaSEConversationTerminator;
import org.jboss.weld.conversation.NumericConversationIdGenerator;
import org.jboss.weld.conversation.ServletConversationManager;
import org.jboss.weld.ejb.EjbDescriptors;
import org.jboss.weld.ejb.spi.EjbServices;
-import org.jboss.weld.event.ObserverMethodImpl;
import org.jboss.weld.resources.spi.ResourceLoader;
import org.jboss.weld.security.spi.SecurityServices;
import org.jboss.weld.servlet.HttpSessionManager;
@@ -64,14 +61,10 @@
private final BeanDeploymentArchive beanDeploymentArchive;
private final BeanManagerImpl beanManager;
- private final ExtensionBeanDeployerEnvironment extensionBeanDeployerEnvironment;
private final BeanDeployer beanDeployer;
- private final Deployment deployment;
- public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerImpl deploymentManager, Deployment deployment, ExtensionBeanDeployerEnvironment extensionBeanDeployerEnvironment, ServiceRegistry deploymentServices)
+ public BeanDeployment(BeanDeploymentArchive beanDeploymentArchive, BeanManagerImpl deploymentManager, ServiceRegistry deploymentServices)
{
- this.extensionBeanDeployerEnvironment = extensionBeanDeployerEnvironment;
- this.deployment = deployment;
this.beanDeploymentArchive = beanDeploymentArchive;
EjbDescriptors ejbDescriptors = new EjbDescriptors();
beanDeploymentArchive.getServices().add(EjbDescriptors.class, ejbDescriptors);
@@ -86,7 +79,7 @@
ejbDescriptors.addAll(beanDeploymentArchive.getEjbs());
}
- beanDeployer = new BeanDeployer(beanManager, deploymentManager, ejbDescriptors);
+ beanDeployer = new BeanDeployer(beanManager, ejbDescriptors);
parseBeansXml();
}
@@ -137,25 +130,6 @@
// TODO read EJB descriptors after reading classes
public void deployBeans(Environment environment)
{
- for (ExtensionBean bean : extensionBeanDeployerEnvironment.getBeans())
- {
- BeanDeploymentArchive classBeanDeploymentArchive = deployment.loadBeanDeploymentArchive(bean.getBeanClass());
- if (classBeanDeploymentArchive == null)
- {
- throw new IllegalStateException("deployment.loadBeanDeploymentArchive() returned null for " + bean.getBeanClass());
- }
- if (classBeanDeploymentArchive.equals(beanDeploymentArchive))
- {
- beanDeployer.getManager().addBean(bean);
- }
- }
- for (ObserverMethodImpl<?, ?> observerMethod : extensionBeanDeployerEnvironment.getObservers())
- {
- if (deployment.loadBeanDeploymentArchive(observerMethod.getBeanClass()).equals(beanDeploymentArchive))
- {
- beanDeployer.getManager().addObserver(observerMethod);
- }
- }
beanDeployer.addClasses(beanDeploymentArchive.getBeanClasses());
beanDeployer.getEnvironment().addBuiltInBean(new ManagerBean(beanManager));
beanDeployer.getEnvironment().addBuiltInBean(new InjectionPointBean(beanManager));
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/ExtensionBeanDeployer.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -17,33 +17,48 @@
package org.jboss.weld.bootstrap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Extension;
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.Container;
+import org.jboss.weld.bean.RIBean;
import org.jboss.weld.bean.builtin.ExtensionBean;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
+import org.jboss.weld.event.ObserverFactory;
+import org.jboss.weld.event.ObserverMethodImpl;
import org.jboss.weld.introspector.WeldClass;
+import org.jboss.weld.introspector.WeldMethod;
import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.util.DeploymentStructures;
/**
* @author pmuir
*
*/
-public class ExtensionBeanDeployer extends AbstractBeanDeployer<ExtensionBeanDeployerEnvironment>
+public class ExtensionBeanDeployer
{
-
+ private final BeanManagerImpl beanManager;
+ private final Set<ObserverMethodImpl<?, ?>> observerMethods;
private final Set<Extension> extensions;
+ private final Deployment deployment;
+ private final Map<BeanDeploymentArchive, BeanDeployment> beanDeployments;
- public ExtensionBeanDeployer(BeanManagerImpl manager, ExtensionBeanDeployerEnvironment environment)
+ public ExtensionBeanDeployer(BeanManagerImpl manager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
- super(manager, environment);
+ this.beanManager = manager;
this.extensions = new HashSet<Extension>();
+ this.observerMethods = new HashSet<ObserverMethodImpl<?,?>>();
+ this.deployment = deployment;
+ this.beanDeployments = beanDeployments;
}
- public ExtensionBeanDeployer createBeans()
+ public ExtensionBeanDeployer deployBeans()
{
ClassTransformer classTransformer = Container.instance().deploymentServices().get(ClassTransformer.class);
for (Extension extension : extensions)
@@ -51,14 +66,22 @@
@SuppressWarnings("unchecked")
WeldClass<Extension> clazz = (WeldClass<Extension>) classTransformer.loadClass(extension.getClass());
- ExtensionBean bean = new ExtensionBean(getManager(), clazz, extension);
- this.
- getEnvironment().addExtension(bean);
- createObserverMethods(bean, clazz);
+ // Locate the BeanDeployment for this extension
+ BeanDeployment beanDeployment = DeploymentStructures.getOrCreateBeanDeployment(deployment, beanManager, beanDeployments, clazz.getJavaClass());
+
+ ExtensionBean bean = new ExtensionBean(beanDeployment.getBeanManager(), clazz, extension);
+ createObserverMethods(bean, beanDeployment.getBeanManager(), clazz);
+ beanDeployment.getBeanManager().addBean(bean);
+ for (ObserverMethodImpl<?, ?> observerMethod : observerMethods)
+ {
+ observerMethod.initialize();
+ beanDeployment.getBeanManager().addObserver(observerMethod);
+ }
}
return this;
}
+
public void addExtensions(Iterable<Extension> extensions)
{
for (Extension extension : extensions)
@@ -71,5 +94,19 @@
{
this.extensions.add(extension);
}
+
+ protected <X> void createObserverMethods(RIBean<X> declaringBean, BeanManagerImpl beanManager, WeldClass<X> annotatedClass)
+ {
+ for (WeldMethod<?, X> method : annotatedClass.getDeclaredWeldMethodsWithAnnotatedParameters(Observes.class))
+ {
+ createObserverMethod(declaringBean, beanManager, method);
+ }
+ }
+
+ protected <T, X> void createObserverMethod(RIBean<X> declaringBean, BeanManagerImpl beanManager, WeldMethod<T, X> method)
+ {
+ ObserverMethodImpl<T, X> observer = ObserverFactory.create(method, declaringBean, beanManager);
+ this.observerMethods.add(observer);
+ }
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -70,7 +70,8 @@
import org.jboss.weld.servlet.ServletApiAbstraction;
import org.jboss.weld.transaction.spi.TransactionServices;
import org.jboss.weld.util.Names;
-import org.jboss.weld.util.serviceProvider.ServiceLoader;
+import org.jboss.weld.util.serviceProvider.DefaultServiceLoaderFactory;
+import org.jboss.weld.util.serviceProvider.ServiceLoaderFactory;
import org.jboss.weld.ws.WSApiAbstraction;
import org.slf4j.cal10n.LocLogger;
@@ -99,19 +100,18 @@
private final BeanManagerImpl deploymentManager;
private final Environment environment;
private final Deployment deployment;
- private final ExtensionBeanDeployerEnvironment extensionBeanDeployerEnvironment;
+ private final Map<BeanDeploymentArchive, BeanDeployment> managerAwareBeanDeploymentArchives;
- public DeploymentVisitor(BeanManagerImpl deploymentManager, Environment environment, Deployment deployment, ExtensionBeanDeployerEnvironment extensionBeanDeployerEnvironment)
+ public DeploymentVisitor(BeanManagerImpl deploymentManager, Environment environment, Deployment deployment)
{
this.deploymentManager = deploymentManager;
this.environment = environment;
this.deployment = deployment;
- this.extensionBeanDeployerEnvironment = extensionBeanDeployerEnvironment;
+ this.managerAwareBeanDeploymentArchives = new HashMap<BeanDeploymentArchive, BeanDeployment>();
}
public Map<BeanDeploymentArchive, BeanDeployment> visit()
{
- Map<BeanDeploymentArchive, BeanDeployment> managerAwareBeanDeploymentArchives = new HashMap<BeanDeploymentArchive, BeanDeployment>();
for (BeanDeploymentArchive archvive : deployment.getBeanDeploymentArchives())
{
visit(archvive, managerAwareBeanDeploymentArchives, new HashSet<BeanDeploymentArchive>());
@@ -130,9 +130,13 @@
throw new IllegalArgumentException("BeanDeploymentArchive must not be null " + beanDeploymentArchive);
}
- // Create the BeanDeployment and attach
- BeanDeployment parent = new BeanDeployment(beanDeploymentArchive, deploymentManager, deployment, extensionBeanDeployerEnvironment, deployment.getServices());
- managerAwareBeanDeploymentArchives.put(beanDeploymentArchive, parent);
+ BeanDeployment parent = managerAwareBeanDeploymentArchives.get(beanDeploymentArchive);
+ if (parent == null)
+ {
+ // Create the BeanDeployment and attach
+ parent = new BeanDeployment(beanDeploymentArchive, deploymentManager, deployment.getServices());
+ managerAwareBeanDeploymentArchives.put(beanDeploymentArchive, parent);
+ }
seenBeanDeploymentArchives.add(beanDeploymentArchive);
for (BeanDeploymentArchive archive : beanDeploymentArchive.getBeanDeploymentArchives())
{
@@ -159,6 +163,7 @@
private Environment environment;
private Deployment deployment;
private ExtensionBeanDeployerEnvironment extensionDeployerEnvironment;
+ private DeploymentVisitor deploymentVisitor;
public Bootstrap startContainer(Environment environment, Deployment deployment, BeanStore applicationBeanStore)
{
@@ -216,10 +221,10 @@
initializeContexts();
// Start the application context
Container.instance().deploymentServices().get(ContextLifecycle.class).beginApplication(applicationBeanStore);
-
this.extensionDeployerEnvironment = new ExtensionBeanDeployerEnvironment(EjbDescriptors.EMPTY, deploymentManager);
+ this.deploymentVisitor = new DeploymentVisitor(deploymentManager, environment, deployment);
- DeploymentVisitor deploymentVisitor = new DeploymentVisitor(deploymentManager, environment, deployment, extensionDeployerEnvironment);
+ // Read the deployment structure, this will be the physical structure as caused by the presence of beans.xml
beanDeployments = deploymentVisitor.visit();
return this;
@@ -241,6 +246,7 @@
services.add(ClassTransformer.class, new ClassTransformer(services.get(TypeStore.class)));
services.add(MetaAnnotationStore.class, new MetaAnnotationStore(services.get(ClassTransformer.class)));
services.add(ContextualStore.class, new ContextualStoreImpl());
+ services.add(ServiceLoaderFactory.class, new DefaultServiceLoaderFactory());
return services;
}
@@ -265,15 +271,24 @@
throw new IllegalStateException("Manager has not been initialized");
}
- ExtensionBeanDeployer extensionBeanDeployer = new ExtensionBeanDeployer(deploymentManager, extensionDeployerEnvironment);
- extensionBeanDeployer.addExtensions(ServiceLoader.load(Extension.class));
- extensionBeanDeployer.createBeans().deploy();
+ ExtensionBeanDeployer extensionBeanDeployer = new ExtensionBeanDeployer(deploymentManager, deployment, beanDeployments);
+ extensionBeanDeployer.addExtensions(deployment.getServices().get(ServiceLoaderFactory.class).load(Extension.class));
+ extensionBeanDeployer.deployBeans();
// Add the Deployment BeanManager Bean to the Deployment BeanManager
deploymentManager.addBean(new ManagerBean(deploymentManager));
- // TODO keep a list of new bdas, add them all in, and deploy beans for them, then merge into existing
- BeforeBeanDiscoveryImpl.fire(deploymentManager, deployment, beanDeployments, extensionDeployerEnvironment);
+ // Re-Read the deployment structure, this will be the physical structure, and will add in BDAs for any extensions outside a physical BDA
+ beanDeployments = deploymentVisitor.visit();
+
+ for (BeanDeployment beanDeployment : beanDeployments.values())
+ {
+ BeforeBeanDiscoveryImpl.fire(beanDeployment.getBeanManager(), deployment, beanDeployments);
+ }
+
+ // Re-Read the deployment structure, this will be the physical structure, extensions and any classes added using addAnnotatedType outside the physical BDA
+ beanDeployments = deploymentVisitor.visit();
+
}
return this;
}
@@ -287,7 +302,12 @@
{
entry.getValue().deployBeans(environment);
}
- AfterBeanDiscoveryImpl.fire(deploymentManager, deployment, beanDeployments, extensionDeployerEnvironment);
+ for (BeanDeployment beanDeployment : beanDeployments.values())
+ {
+ AfterBeanDiscoveryImpl.fire(beanDeployment.getBeanManager(), deployment, beanDeployments);
+ }
+ // Re-read the deployment structure, this will be the physical structure, extensions, classes, and any beans added using addBean outside the physical structure
+ beanDeployments = deploymentVisitor.visit();
log.debug(VALIDATING_BEANS);
}
return this;
@@ -301,7 +321,11 @@
{
deployment.getServices().get(Validator.class).validateDeployment(entry.getValue().getBeanManager(), entry.getValue().getBeanDeployer().getEnvironment());
}
- AfterDeploymentValidationImpl.fire(deploymentManager);
+ for (BeanDeployment beanDeployment : beanDeployments.values())
+ {
+ AfterDeploymentValidationImpl.fire(beanDeployment.getBeanManager());
+ }
+
}
return this;
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractBeanDiscoveryEvent.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractBeanDiscoveryEvent.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractBeanDiscoveryEvent.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -25,6 +25,7 @@
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.metadata.TypeStore;
+import org.jboss.weld.util.DeploymentStructures;
/**
* @author pmuir
@@ -34,14 +35,12 @@
private final Map<BeanDeploymentArchive, BeanDeployment> beanDeployments;
private final Deployment deployment;
- private final ExtensionBeanDeployerEnvironment extensionBeanDeployerEnvironment;
- public AbstractBeanDiscoveryEvent(BeanManagerImpl deploymentManager, Type rawType, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, Deployment deployment, ExtensionBeanDeployerEnvironment extensionBeanDeployerEnvironment)
+ public AbstractBeanDiscoveryEvent(BeanManagerImpl beanManager, Type rawType, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, Deployment deployment)
{
- super(deploymentManager, rawType, EMPTY_TYPE_ARRAY);
+ super(beanManager, rawType, EMPTY_TYPE_ARRAY);
this.beanDeployments = beanDeployments;
this.deployment = deployment;
- this.extensionBeanDeployerEnvironment = extensionBeanDeployerEnvironment;
}
/**
@@ -68,24 +67,7 @@
protected BeanDeployment getOrCreateBeanDeployment(Class<?> clazz)
{
- BeanDeploymentArchive beanDeploymentArchive = getDeployment().loadBeanDeploymentArchive(clazz);
- if (beanDeploymentArchive == null)
- {
- throw new IllegalStateException("Unable to find Bean Deployment Archive for " + clazz);
- }
- else
- {
- if (getBeanDeployments().containsKey(beanDeploymentArchive))
- {
- return getBeanDeployments().get(beanDeploymentArchive);
- }
- else
- {
- BeanDeployment beanDeployment = new BeanDeployment(beanDeploymentArchive, getBeanManager(), getDeployment(), extensionBeanDeployerEnvironment, getDeployment().getServices());
- getBeanDeployments().put(beanDeploymentArchive, beanDeployment);
- return beanDeployment;
- }
- }
+ return DeploymentStructures.getOrCreateBeanDeployment(deployment, getBeanManager(), beanDeployments, clazz);
}
}
\ No newline at end of file
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterBeanDiscoveryImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterBeanDiscoveryImpl.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterBeanDiscoveryImpl.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -27,21 +27,20 @@
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.bootstrap.BeanDeployment;
-import org.jboss.weld.bootstrap.ExtensionBeanDeployerEnvironment;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.Deployment;
public class AfterBeanDiscoveryImpl extends AbstractBeanDiscoveryEvent implements AfterBeanDiscovery
{
- public static void fire(BeanManagerImpl deploymentManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, ExtensionBeanDeployerEnvironment extensionDeployerEnvironment)
+ public static void fire(BeanManagerImpl beanManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
- new AfterBeanDiscoveryImpl(deploymentManager, deployment, beanDeployments, extensionDeployerEnvironment).fire();
+ new AfterBeanDiscoveryImpl(beanManager, deployment, beanDeployments).fire();
}
- protected AfterBeanDiscoveryImpl(BeanManagerImpl deploymentManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, ExtensionBeanDeployerEnvironment extensionDeployerEnvironment)
+ protected AfterBeanDiscoveryImpl(BeanManagerImpl beanManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
- super(deploymentManager, AfterBeanDiscovery.class, beanDeployments, deployment, extensionDeployerEnvironment);
+ super(beanManager, AfterBeanDiscovery.class, beanDeployments, deployment);
}
public void addDefinitionError(Throwable t)
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterDeploymentValidationImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterDeploymentValidationImpl.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/AfterDeploymentValidationImpl.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -24,9 +24,9 @@
public class AfterDeploymentValidationImpl extends AbstractDeploymentContainerEvent implements AfterDeploymentValidation
{
- public static void fire(BeanManagerImpl deploymentManager)
+ public static void fire(BeanManagerImpl beanManager)
{
- new AfterDeploymentValidationImpl(deploymentManager).fire();
+ new AfterDeploymentValidationImpl(beanManager).fire();
}
protected AfterDeploymentValidationImpl(BeanManagerImpl beanManager)
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/BeforeBeanDiscoveryImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/BeforeBeanDiscoveryImpl.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/events/BeforeBeanDiscoveryImpl.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -24,7 +24,6 @@
import org.jboss.weld.BeanManagerImpl;
import org.jboss.weld.bootstrap.BeanDeployment;
-import org.jboss.weld.bootstrap.ExtensionBeanDeployerEnvironment;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.bootstrap.spi.Deployment;
import org.jboss.weld.literal.BindingTypeLiteral;
@@ -35,14 +34,14 @@
public class BeforeBeanDiscoveryImpl extends AbstractBeanDiscoveryEvent implements BeforeBeanDiscovery
{
- public static void fire(BeanManagerImpl deploymentManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, ExtensionBeanDeployerEnvironment extensionDeployerEnvironment)
+ public static void fire(BeanManagerImpl beanManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
- new BeforeBeanDiscoveryImpl(deploymentManager, deployment, beanDeployments, extensionDeployerEnvironment).fire();
+ new BeforeBeanDiscoveryImpl(beanManager, deployment, beanDeployments).fire();
}
- protected BeforeBeanDiscoveryImpl(BeanManagerImpl deploymentManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, ExtensionBeanDeployerEnvironment extensionBeanDeployerEnvironment)
+ protected BeforeBeanDiscoveryImpl(BeanManagerImpl beanManager, Deployment deployment, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments)
{
- super(deploymentManager, BeforeBeanDiscovery.class, beanDeployments, deployment, extensionBeanDeployerEnvironment);
+ super(beanManager, BeforeBeanDiscovery.class, beanDeployments, deployment);
}
public void addQualifier(Class<? extends Annotation> bindingType)
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/DeploymentStructures.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/DeploymentStructures.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/DeploymentStructures.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,37 @@
+package org.jboss.weld.util;
+
+import java.util.Map;
+
+import org.jboss.weld.BeanManagerImpl;
+import org.jboss.weld.bootstrap.BeanDeployment;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
+
+public class DeploymentStructures
+{
+
+ private DeploymentStructures() {}
+
+ public static BeanDeployment getOrCreateBeanDeployment(Deployment deployment, BeanManagerImpl deploymentManager, Map<BeanDeploymentArchive, BeanDeployment> beanDeployments, 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, deployment.getServices());
+ beanDeployments.put(beanDeploymentArchive, beanDeployment);
+ return beanDeployment;
+ }
+ }
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/DeploymentStructures.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/log/Message.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/log/Message.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/log/Message.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,8 @@
+package org.jboss.weld.util.log;
+
+public interface Message
+{
+
+ public String getErrorId();
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/log/Message.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/log/MessageConveyerFactoryLoader.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/log/MessageConveyerFactoryLoader.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/log/MessageConveyerFactoryLoader.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -2,7 +2,7 @@
import java.util.Locale;
-import org.jboss.weld.util.serviceProvider.ServiceLoader;
+import org.jboss.weld.util.serviceProvider.DefaultServiceLoader;
import ch.qos.cal10n.IMessageConveyor;
import ch.qos.cal10n.MessageConveyor;
@@ -21,7 +21,7 @@
private static IMessageConveyerFactory load()
{
- ServiceLoader<IMessageConveyerFactory> serviceLoader = ServiceLoader.load(IMessageConveyerFactory.class);
+ DefaultServiceLoader<IMessageConveyerFactory> serviceLoader = DefaultServiceLoader.load(IMessageConveyerFactory.class);
int i = 0;
for (IMessageConveyerFactory f : serviceLoader)
{
Copied: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java (from rev 4492, core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoader.java)
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,310 @@
+/*
+ * 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.weld.util.serviceProvider;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.jboss.weld.util.Reflections;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+import org.slf4j.ext.XLogger.Level;
+
+/**
+ * This class handles looking up service providers on the class path. It
+ * implements the <a href="http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider"
+ * >Service Provider section of the JAR File Specification</a>.
+ *
+ * The Service Provider programmatic lookup was not specified prior to Java 6 so
+ * this interface allows use of the specification prior to Java 6.
+ *
+ * The API is copied from <a
+ * href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html"
+ * >java.util.ServiceLoader</a>
+ *
+ * @author Pete Muir
+ * @author <a href="mailto:dev at avalon.apache.org">Avalon Development Team</a>
+ */
+public class DefaultServiceLoader<S> implements Iterable<S>
+{
+
+ private static Logger log = LoggerFactory.getLogger(DefaultServiceLoader.class);
+ private static XLogger xLog = XLoggerFactory.getXLogger(DefaultServiceLoader.class);
+
+ private static final String SERVICES = "META-INF/services";
+
+ /**
+ * Creates a new service loader for the given service type, using the current
+ * thread's context class loader.
+ *
+ * An invocation of this convenience method of the form
+ *
+ * {@code ServiceLoader.load(service)</code>}
+ *
+ * is equivalent to
+ *
+ * <code>ServiceLoader.load(service,
+ * Thread.currentThread().getContextClassLoader())</code>
+ *
+ * @param service The interface or abstract class representing the service
+ * @return A new service loader
+ */
+ public static <S> DefaultServiceLoader<S> load(Class<S> service)
+ {
+ return load(SERVICES, service, Thread.currentThread().getContextClassLoader());
+ }
+
+ public static <S> DefaultServiceLoader<S> load(String directoryName, Class<S> service)
+ {
+ return load(directoryName, service, Thread.currentThread().getContextClassLoader());
+ }
+
+ public static <S> DefaultServiceLoader<S> load(String directoryName, Class<S> service, ClassLoader loader)
+ {
+ if (loader == null)
+ {
+ loader = service.getClassLoader();
+ }
+ return new DefaultServiceLoader<S>(directoryName, service, loader);
+ }
+
+ /**
+ * Creates a new service loader for the given service type and class loader.
+ *
+ * @param service The interface or abstract class representing the service
+ * @param loader The class loader to be used to load provider-configuration
+ * files and provider classes, or null if the system class loader
+ * (or, failing that, the bootstrap class loader) is to be used
+ * @return A new service loader
+ */
+ public static <S> DefaultServiceLoader<S> load(Class<S> service, ClassLoader loader)
+ {
+ return load(SERVICES, service, loader);
+ }
+
+ /**
+ * Creates a new service loader for the given service type, using the
+ * extension class loader.
+ *
+ * This convenience method simply locates the extension class loader, call it
+ * extClassLoader, and then returns
+ *
+ * <code>ServiceLoader.load(service, extClassLoader)</code>
+ *
+ * If the extension class loader cannot be found then the system class loader
+ * is used; if there is no system class loader then the bootstrap class
+ * loader is used.
+ *
+ * This method is intended for use when only installed providers are desired.
+ * The resulting service will only find and load providers that have been
+ * installed into the current Java virtual machine; providers on the
+ * application's class path will be ignored.
+ *
+ * @param service The interface or abstract class representing the service
+ * @return A new service loader
+ */
+ public static <S> DefaultServiceLoader<S> loadInstalled(Class<S> service)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ private final String serviceFile;
+ private Class<S> expectedType;
+ private final ClassLoader loader;
+
+ private Set<S> providers;
+
+ private DefaultServiceLoader(String prefix, Class<S> service, ClassLoader loader)
+ {
+ this.loader = loader;
+ this.serviceFile = prefix + "/" + service.getName();
+ this.expectedType = service;
+ }
+
+ /**
+ * Clear this loader's provider cache so that all providers will be reloaded.
+ *
+ * After invoking this method, subsequent invocations of the iterator method
+ * will lazily look up and instantiate providers from scratch, just as is
+ * done by a newly-created loader.
+ *
+ * This method is intended for use in situations in which new providers can
+ * be installed into a running Java virtual machine.
+ */
+ public void reload()
+ {
+ providers = new HashSet<S>();
+ Enumeration<URL> enumeration = null;
+ boolean errorOccurred = false;
+
+ try
+ {
+ enumeration = loader.getResources(serviceFile);
+ }
+ catch (IOException ioe)
+ {
+ errorOccurred = true;
+ }
+
+ if (!errorOccurred)
+ {
+ while (enumeration.hasMoreElements())
+ {
+ try
+ {
+ final URL url = enumeration.nextElement();
+ final InputStream is = url.openStream();
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+
+ String line = reader.readLine();
+ while (null != line)
+ {
+ try
+ {
+ final int comment = line.indexOf('#');
+
+ if (comment > -1)
+ {
+ line = line.substring(0, comment);
+ }
+
+ line.trim();
+
+ if (line.length() > 0)
+ {
+ try
+ {
+ Class<?> clazz = loader.loadClass(line);
+ Class<? extends S> serviceClass;
+ try
+ {
+ serviceClass = clazz.asSubclass(expectedType);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IllegalStateException("Extension " + line + " does not implement Extension");
+ }
+ Constructor<? extends S> constructor = Reflections.ensureAccessible(serviceClass.getConstructor());
+ S instance = constructor.newInstance();
+ providers.add(instance);
+ }
+ catch (NoClassDefFoundError e)
+ {
+ log.warn("Error loading line", line);
+ xLog.throwing(Level.DEBUG, e);
+ throw e;
+ }
+ catch (InstantiationException e)
+ {
+ log.warn("Error loading line", line);
+ xLog.throwing(Level.DEBUG, e);
+ throw e;
+ }
+ catch (IllegalAccessException e)
+ {
+ log.warn("Error loading line", line);
+ xLog.throwing(Level.DEBUG, e);
+ throw e;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ // TODO Don't use exceptions for flow control!
+ // try the next line
+ }
+
+ line = reader.readLine();
+ }
+ }
+ catch (Exception e)
+ {
+ // try the next file
+ }
+ }
+ }
+ }
+
+
+
+ /**
+ * Lazily loads the available providers of this loader's service.
+ *
+ * The iterator returned by this method first yields all of the elements of
+ * the provider cache, in instantiation order. It then lazily loads and
+ * instantiates any remaining providers, adding each one to the cache in
+ * turn.
+ *
+ * To achieve laziness the actual work of parsing the available
+ * provider-configuration files and instantiating providers must be done by
+ * the iterator itself. Its hasNext and next methods can therefore throw a
+ * ServiceConfigurationError if a provider-configuration file violates the
+ * specified format, or if it names a provider class that cannot be found and
+ * instantiated, or if the result of instantiating the class is not
+ * assignable to the service type, or if any other kind of exception or error
+ * is thrown as the next provider is located and instantiated. To write
+ * robust code it is only necessary to catch ServiceConfigurationError when
+ * using a service iterator.
+ *
+ * If such an error is thrown then subsequent invocations of the iterator
+ * will make a best effort to locate and instantiate the next available
+ * provider, but in general such recovery cannot be guaranteed.
+ *
+ * Design Note Throwing an error in these cases may seem extreme. The
+ * rationale for this behavior is that a malformed provider-configuration
+ * file, like a malformed class file, indicates a serious problem with the
+ * way the Java virtual machine is configured or is being used. As such it is
+ * preferable to throw an error rather than try to recover or, even worse,
+ * fail silently.
+ *
+ * The iterator returned by this method does not support removal. Invoking
+ * its remove method will cause an UnsupportedOperationException to be
+ * thrown.
+ *
+ * @return An iterator that lazily loads providers for this loader's service
+ */
+ public Iterator<S> iterator()
+ {
+ if (providers == null)
+ {
+ reload();
+ }
+ return providers.iterator();
+ }
+
+ /**
+ * Returns a string describing this service.
+ *
+ * @return A descriptive string
+ */
+ @Override
+ public String toString()
+ {
+ return "Services for " + serviceFile;
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoaderFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoaderFactory.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoaderFactory.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,18 @@
+package org.jboss.weld.util.serviceProvider;
+
+public class DefaultServiceLoaderFactory implements ServiceLoaderFactory
+{
+
+ public void cleanup() {}
+
+ public <S> DefaultServiceLoader<S> load(Class<S> service)
+ {
+ return DefaultServiceLoader.load(service);
+ }
+
+ public <S> DefaultServiceLoader<S> load(Class<S> service, ClassLoader loader)
+ {
+ return DefaultServiceLoader.load(service, loader);
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoaderFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/PackageServiceLoaderFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/PackageServiceLoaderFactory.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/PackageServiceLoaderFactory.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,45 @@
+package org.jboss.weld.util.serviceProvider;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+
+public class PackageServiceLoaderFactory extends DefaultServiceLoaderFactory
+{
+
+ private final String directoryName;
+ private final Collection<Class<?>> classes;
+
+ public PackageServiceLoaderFactory(Package pkg, Class<?>... classes)
+ {
+ this.directoryName = pkg.getName().replace(".", "/");
+ this.classes = Arrays.asList(classes);
+ }
+
+ @Override
+ public <S> DefaultServiceLoader<S> load(Class<S> service)
+ {
+ if (classes.contains(service))
+ {
+ return DefaultServiceLoader.load(directoryName, service);
+ }
+ else
+ {
+ return super.load(service);
+ }
+ }
+
+ @Override
+ public <S> DefaultServiceLoader<S> load(Class<S> service, ClassLoader loader)
+ {
+ if (classes.contains(service))
+ {
+ return DefaultServiceLoader.load(directoryName, service, loader);
+ }
+ else
+ {
+ return super.load(service, loader);
+ }
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/PackageServiceLoaderFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Deleted: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoader.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoader.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoader.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,301 +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.weld.util.serviceProvider;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Constructor;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.jboss.weld.util.Reflections;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.ext.XLogger;
-import org.slf4j.ext.XLoggerFactory;
-import org.slf4j.ext.XLogger.Level;
-
-/**
- * This class handles looking up service providers on the class path. It
- * implements the <a href="http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider"
- * >Service Provider section of the JAR File Specification</a>.
- *
- * The Service Provider programmatic lookup was not specified prior to Java 6 so
- * this interface allows use of the specification prior to Java 6.
- *
- * The API is copied from <a
- * href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html"
- * >java.util.ServiceLoader</a>
- *
- * @author Pete Muir
- * @author <a href="mailto:dev at avalon.apache.org">Avalon Development Team</a>
- */
-public class ServiceLoader<S> implements Iterable<S>
-{
-
- private static Logger log = LoggerFactory.getLogger(ServiceLoader.class);
- private static XLogger xLog = XLoggerFactory.getXLogger(ServiceLoader.class);
-
- private static final String SERVICES = "META-INF/services/";
-
- /**
- * Creates a new service loader for the given service type, using the current
- * thread's context class loader.
- *
- * An invocation of this convenience method of the form
- *
- * {@code ServiceLoader.load(service)</code>}
- *
- * is equivalent to
- *
- * <code>ServiceLoader.load(service,
- * Thread.currentThread().getContextClassLoader())</code>
- *
- * @param service The interface or abstract class representing the service
- * @return A new service loader
- */
- public static <S> ServiceLoader<S> load(Class<S> service)
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- return load(service, loader);
- }
-
- /**
- * Creates a new service loader for the given service type and class loader.
- *
- * @param service The interface or abstract class representing the service
- * @param loader The class loader to be used to load provider-configuration
- * files and provider classes, or null if the system class loader
- * (or, failing that, the bootstrap class loader) is to be used
- * @return A new service loader
- */
- public static <S> ServiceLoader<S> load(Class<S> service, ClassLoader loader)
- {
- if (loader == null)
- {
- loader = service.getClassLoader();
- }
- return new ServiceLoader<S>(service, loader);
- }
-
- /**
- * Creates a new service loader for the given service type, using the
- * extension class loader.
- *
- * This convenience method simply locates the extension class loader, call it
- * extClassLoader, and then returns
- *
- * <code>ServiceLoader.load(service, extClassLoader)</code>
- *
- * If the extension class loader cannot be found then the system class loader
- * is used; if there is no system class loader then the bootstrap class
- * loader is used.
- *
- * This method is intended for use when only installed providers are desired.
- * The resulting service will only find and load providers that have been
- * installed into the current Java virtual machine; providers on the
- * application's class path will be ignored.
- *
- * @param service The interface or abstract class representing the service
- * @return A new service loader
- */
- public static <S> ServiceLoader<S> loadInstalled(Class<S> service)
- {
- throw new UnsupportedOperationException();
- }
-
- private final String serviceFile;
- private Class<S> expectedType;
- private final ClassLoader loader;
-
- private Set<S> providers;
-
- private ServiceLoader(Class<S> service, ClassLoader loader)
- {
- this.loader = loader;
- this.serviceFile = SERVICES + service.getName();
- this.expectedType = service;
- }
-
- /**
- * Clear this loader's provider cache so that all providers will be reloaded.
- *
- * After invoking this method, subsequent invocations of the iterator method
- * will lazily look up and instantiate providers from scratch, just as is
- * done by a newly-created loader.
- *
- * This method is intended for use in situations in which new providers can
- * be installed into a running Java virtual machine.
- */
- public void reload()
- {
- providers = new HashSet<S>();
- Enumeration<URL> enumeration = null;
- boolean errorOccurred = false;
-
- try
- {
- enumeration = loader.getResources(serviceFile);
- }
- catch (IOException ioe)
- {
- errorOccurred = true;
- }
-
- if (!errorOccurred)
- {
- while (enumeration.hasMoreElements())
- {
- try
- {
- final URL url = enumeration.nextElement();
- final InputStream is = url.openStream();
- final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-
- String line = reader.readLine();
- while (null != line)
- {
- try
- {
- final int comment = line.indexOf('#');
-
- if (comment > -1)
- {
- line = line.substring(0, comment);
- }
-
- line.trim();
-
- if (line.length() > 0)
- {
- try
- {
- Class<?> clazz = loader.loadClass(line);
- Class<? extends S> serviceClass;
- try
- {
- serviceClass = clazz.asSubclass(expectedType);
- }
- catch (ClassCastException e)
- {
- throw new IllegalStateException("Extension " + line + " does not implement Extension");
- }
- Constructor<? extends S> constructor = Reflections.ensureAccessible(serviceClass.getConstructor());
- S instance = constructor.newInstance();
- providers.add(instance);
- }
- catch (NoClassDefFoundError e)
- {
- log.warn("Error loading line", line);
- xLog.throwing(Level.DEBUG, e);
- throw e;
- }
- catch (InstantiationException e)
- {
- log.warn("Error loading line", line);
- xLog.throwing(Level.DEBUG, e);
- throw e;
- }
- catch (IllegalAccessException e)
- {
- log.warn("Error loading line", line);
- xLog.throwing(Level.DEBUG, e);
- throw e;
- }
- }
- }
- catch (Exception e)
- {
- // TODO Don't use exceptions for flow control!
- // try the next line
- }
-
- line = reader.readLine();
- }
- }
- catch (Exception e)
- {
- // try the next file
- }
- }
- }
- }
-
-
-
- /**
- * Lazily loads the available providers of this loader's service.
- *
- * The iterator returned by this method first yields all of the elements of
- * the provider cache, in instantiation order. It then lazily loads and
- * instantiates any remaining providers, adding each one to the cache in
- * turn.
- *
- * To achieve laziness the actual work of parsing the available
- * provider-configuration files and instantiating providers must be done by
- * the iterator itself. Its hasNext and next methods can therefore throw a
- * ServiceConfigurationError if a provider-configuration file violates the
- * specified format, or if it names a provider class that cannot be found and
- * instantiated, or if the result of instantiating the class is not
- * assignable to the service type, or if any other kind of exception or error
- * is thrown as the next provider is located and instantiated. To write
- * robust code it is only necessary to catch ServiceConfigurationError when
- * using a service iterator.
- *
- * If such an error is thrown then subsequent invocations of the iterator
- * will make a best effort to locate and instantiate the next available
- * provider, but in general such recovery cannot be guaranteed.
- *
- * Design Note Throwing an error in these cases may seem extreme. The
- * rationale for this behavior is that a malformed provider-configuration
- * file, like a malformed class file, indicates a serious problem with the
- * way the Java virtual machine is configured or is being used. As such it is
- * preferable to throw an error rather than try to recover or, even worse,
- * fail silently.
- *
- * The iterator returned by this method does not support removal. Invoking
- * its remove method will cause an UnsupportedOperationException to be
- * thrown.
- *
- * @return An iterator that lazily loads providers for this loader's service
- */
- public Iterator<S> iterator()
- {
- if (providers == null)
- {
- reload();
- }
- return providers.iterator();
- }
-
- /**
- * Returns a string describing this service.
- *
- * @return A descriptive string
- */
- @Override
- public String toString()
- {
- return "Services for " + serviceFile;
- }
-
-}
Added: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoaderFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoaderFactory.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoaderFactory.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,12 @@
+package org.jboss.weld.util.serviceProvider;
+
+import org.jboss.weld.bootstrap.api.Service;
+
+public interface ServiceLoaderFactory extends Service
+{
+
+ public <S> DefaultServiceLoader<S> load(Class<S> service);
+
+ public <S> DefaultServiceLoader<S> load(Class<S> service, ClassLoader loader);
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/ServiceLoaderFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/AtInjectTCK.java
===================================================================
--- core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/AtInjectTCK.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/inject-tck-runner/src/test/java/org/jboss/weld/atinject/tck/AtInjectTCK.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,7 +1,4 @@
package org.jboss.weld.atinject.tck;
-import java.util.Arrays;
-import java.util.List;
-
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@@ -26,19 +23,6 @@
*/
public class AtInjectTCK
{
- /**
- * The classes that should be deployed as Managed Beans
- */
- public static final List<Class<?>> classes = Arrays.<Class<?>>asList(
- Convertible.class,
- Seat.class,
- V8Engine.class,
- Cupholder.class,
- FuelTank.class,
- Tire.class,
- // Producer Methods allowing to expose DriversSeat, SpareTire, @Named("spare") SpareTire, @Drivers Seat
- Producers.class
- );
/**
* Create JUnit TestSuite
@@ -49,7 +33,18 @@
{
// Create and start the TestContainer, which takes care of starting the container, deploying the
// classes, starting the contexts etc.
- TestContainer container = new TestContainer(new MockEELifecycle(), classes, null);
+ TestContainer container = new TestContainer(new MockEELifecycle(),
+
+ // The classes to deploy as beans
+ Convertible.class,
+ Seat.class,
+ V8Engine.class,
+ Cupholder.class,
+ FuelTank.class,
+ Tire.class,
+ // Producer Methods allowing to expose DriversSeat, SpareTire, @Named("spare") SpareTire, @Drivers Seat
+ Producers.class
+ );
container.startContainer();
BeanManager beanManager = container.getBeanManager();
Modified: core/trunk/tests/src/main/java/org/jboss/weld/mock/MockBeanDeploymentArchive.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/mock/MockBeanDeploymentArchive.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/main/java/org/jboss/weld/mock/MockBeanDeploymentArchive.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -19,7 +19,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -47,12 +46,21 @@
private Collection<URL> beansXmlFiles;
private List<EjbDescriptor<?>> ejbs;
private final ServiceRegistry services;
+ private final Collection<BeanDeploymentArchive> bdas;
+ private final String id;
public MockBeanDeploymentArchive()
{
+ this("test");
+ }
+
+ public MockBeanDeploymentArchive(String id)
+ {
this.services = new SimpleServiceRegistry();
this.beanClasses = new HashSet<Class<?>>();
this.beansXmlFiles = new HashSet<URL>();
+ this.bdas = new HashSet<BeanDeploymentArchive>();
+ this.id = id;
}
public Collection<Class<?>> getBeanClasses()
@@ -80,9 +88,9 @@
this.beansXmlFiles = beansXmlFiles;
}
- public List<BeanDeploymentArchive> getBeanDeploymentArchives()
+ public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
{
- return Collections.emptyList();
+ return bdas;
}
public Collection<EjbDescriptor<?>> getEjbs()
@@ -110,7 +118,7 @@
public String getId()
{
- return "test";
+ return id;
}
}
Modified: core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/main/java/org/jboss/weld/mock/TestContainer.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,6 +1,7 @@
package org.jboss.weld.mock;
import java.net.URL;
+import java.util.Arrays;
import java.util.Collection;
import org.jboss.weld.BeanManagerImpl;
@@ -68,6 +69,16 @@
configureArchive();
}
+ public TestContainer(MockServletLifecycle lifecycle, Class<?>[] classes, URL[] beansXml)
+ {
+ this(lifecycle, classes == null ? null : Arrays.asList(classes), beansXml == null ? null : Arrays.asList(beansXml));
+ }
+
+ public TestContainer(MockServletLifecycle lifecycle, Class<?>... classes)
+ {
+ this(lifecycle, classes == null ? null : Arrays.asList(classes), null);
+ }
+
/**
* Start the container, returning the container state
*
Deleted: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/AccessibleManagerResolutionTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/AccessibleManagerResolutionTest.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/AccessibleManagerResolutionTest.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,153 +0,0 @@
-package org.jboss.weld.test.unit.deployment.structure;
-
-import java.util.Set;
-
-import javax.enterprise.inject.spi.Bean;
-
-import org.jboss.weld.BeanManagerImpl;
-
-import org.jboss.weld.ContextualStoreImpl;
-import org.jboss.weld.serialization.spi.ContextualStore;
-import org.jboss.weld.bean.ManagedBean;
-import org.jboss.weld.bean.RIBean;
-import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
-import org.jboss.weld.bootstrap.api.ServiceRegistry;
-import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
-import org.jboss.weld.ejb.EjbDescriptors;
-import org.jboss.weld.introspector.WeldClass;
-import org.jboss.weld.introspector.jlr.WeldClassImpl;
-import org.jboss.weld.metadata.TypeStore;
-import org.jboss.weld.metadata.cache.MetaAnnotationStore;
-import org.jboss.weld.resources.ClassTransformer;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class AccessibleManagerResolutionTest
-{
-
- private ClassTransformer classTransformer;
- private ServiceRegistry services;
-
- @BeforeMethod
- public void beforeMethod()
- {
- this.classTransformer = new ClassTransformer(new TypeStore());
- this.services = new SimpleServiceRegistry();
- this.services.add(MetaAnnotationStore.class, new MetaAnnotationStore(classTransformer));
- this.services.add(ContextualStore.class, new ContextualStoreImpl());
- }
-
- private void addBean(BeanManagerImpl manager, Class<?> c)
- {
- WeldClass<?> clazz = WeldClassImpl.of(c, classTransformer);
- RIBean<?> bean = ManagedBean.of(clazz, manager);
- manager.addBean(bean);
- BeanDeployerEnvironment environment = new BeanDeployerEnvironment(new EjbDescriptors(), manager);
- bean.initialize(environment);
- }
-
- @Test
- public void testAccessibleDynamicallySingleLevel()
- {
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
- addBean(root, Cow.class);
- assert root.getBeans(Cow.class).size() == 1;
- assert child.getBeans(Cow.class).size() == 0;
- child.addAccessibleBeanManager(root);
- Set<Bean<?>> beans = child.getBeans(Cow.class);
- assert child.getBeans(Cow.class).size() == 1;
- addBean(child, Chicken.class);
- assert child.getBeans(Chicken.class).size() == 1;
- assert root.getBeans(Chicken.class).size() == 0;
- }
-
- @Test
- public void testAccessibleThreeLevelsWithMultiple()
- {
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
- BeanManagerImpl child1 = BeanManagerImpl.newRootManager("child1", services);
- BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
- BeanManagerImpl greatGrandchild = BeanManagerImpl.newRootManager("greatGrandchild", services);
- child.addAccessibleBeanManager(root);
- grandchild.addAccessibleBeanManager(child1);
- grandchild.addAccessibleBeanManager(child);
- addBean(greatGrandchild, Cat.class);
- greatGrandchild.addAccessibleBeanManager(grandchild);
- addBean(root, Cow.class);
- addBean(child, Chicken.class);
- addBean(grandchild, Pig.class);
- addBean(child1, Horse.class);
- assert root.getBeans(Pig.class).size() == 0;
- assert root.getBeans(Chicken.class).size() == 0;
- assert root.getBeans(Cow.class).size() == 1;
- assert root.getBeans(Horse.class).size() == 0;
- assert root.getBeans(Cat.class).size() == 0;
- assert child.getBeans(Pig.class).size() == 0;
- assert child.getBeans(Chicken.class).size() == 1;
- assert child.getBeans(Cow.class).size() == 1;
- assert child.getBeans(Horse.class).size() == 0;
- assert child.getBeans(Cat.class).size() == 0;
- assert child1.getBeans(Cow.class).size() == 0;
- assert child1.getBeans(Horse.class).size() == 1;
- assert grandchild.getBeans(Pig.class).size() == 1;
- assert grandchild.getBeans(Chicken.class).size() == 1;
- assert grandchild.getBeans(Cow.class).size() == 1;
- assert grandchild.getBeans(Horse.class).size() ==1;
- assert grandchild.getBeans(Cat.class).size() == 0;
- assert greatGrandchild.getBeans(Pig.class).size() == 1;
- assert greatGrandchild.getBeans(Chicken.class).size() == 1;
- assert greatGrandchild.getBeans(Cow.class).size() == 1;
- assert greatGrandchild.getBeans(Horse.class).size() ==1;
- assert greatGrandchild.getBeans(Cat.class).size() == 1;
- }
-
- @Test
- public void testSameManagerAddedTwice()
- {
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
- BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
- grandchild.addAccessibleBeanManager(child);
- child.addAccessibleBeanManager(root);
- grandchild.addAccessibleBeanManager(root);
- addBean(root, Cow.class);
- addBean(child, Chicken.class);
- addBean(grandchild, Pig.class);
- assert root.getBeans(Pig.class).size() == 0;
- assert root.getBeans(Chicken.class).size() == 0;
- assert root.getBeans(Cow.class).size() == 1;
- assert child.getBeans(Pig.class).size() == 0;
- assert child.getBeans(Chicken.class).size() == 1;
- assert child.getBeans(Cow.class).size() == 1;
- assert grandchild.getBeans(Pig.class).size() == 1;
- assert grandchild.getBeans(Chicken.class).size() == 1;
- assert grandchild.getBeans(Cow.class).size() == 1;
- }
-
- @Test
- public void testCircular()
- {
- BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
- BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
- BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
- grandchild.addAccessibleBeanManager(child);
- child.addAccessibleBeanManager(root);
- grandchild.addAccessibleBeanManager(root);
- root.addAccessibleBeanManager(grandchild);
- addBean(root, Cow.class);
- addBean(child, Chicken.class);
- addBean(grandchild, Pig.class);
- assert root.getBeans(Pig.class).size() == 1;
- assert root.getBeans(Chicken.class).size() == 1;
- assert root.getBeans(Cow.class).size() == 1;
- assert child.getBeans(Pig.class).size() == 1;
- assert child.getBeans(Chicken.class).size() == 1;
- assert child.getBeans(Cow.class).size() == 1;
- assert grandchild.getBeans(Pig.class).size() == 1;
- assert grandchild.getBeans(Chicken.class).size() == 1;
- assert grandchild.getBeans(Cow.class).size() == 1;
- }
-
-}
Deleted: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cat.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cat.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cat.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,26 +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.weld.test.unit.deployment.structure;
-
-/**
- * @author pmuir
- *
- */
-public class Cat
-{
-
-}
Deleted: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Chicken.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Chicken.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Chicken.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,26 +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.weld.test.unit.deployment.structure;
-
-/**
- * @author pmuir
- *
- */
-public class Chicken
-{
-
-}
Deleted: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cow.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cow.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cow.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,26 +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.weld.test.unit.deployment.structure;
-
-/**
- * @author pmuir
- *
- */
-public class Cow
-{
-
-}
Deleted: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Horse.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Horse.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Horse.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,26 +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.weld.test.unit.deployment.structure;
-
-/**
- * @author pmuir
- *
- */
-public class Horse
-{
-
-}
Deleted: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Pig.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Pig.java 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Pig.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -1,26 +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.weld.test.unit.deployment.structure;
-
-/**
- * @author pmuir
- *
- */
-public class Pig
-{
-
-}
Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ExtensionOutsideBDATest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ExtensionOutsideBDATest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ExtensionOutsideBDATest.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,112 @@
+package org.jboss.weld.test.unit.deployment.structure.extensions;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.jboss.weld.BeanManagerImpl;
+import org.jboss.weld.bootstrap.WeldBootstrap;
+import org.jboss.weld.bootstrap.api.Environments;
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.bootstrap.spi.Deployment;
+import org.jboss.weld.context.beanstore.HashMapBeanStore;
+import org.jboss.weld.mock.MockBeanDeploymentArchive;
+import org.jboss.weld.util.serviceProvider.PackageServiceLoaderFactory;
+import org.jboss.weld.util.serviceProvider.ServiceLoaderFactory;
+import org.testng.annotations.Test;
+
+public class ExtensionOutsideBDATest
+{
+
+ @Test(description="WELD-233")
+ public void test()
+ {
+ WeldBootstrap bootstrap = new WeldBootstrap();
+
+ // Create the BDA in which we will deploy Observer1 and Foo. This is equivalent to a war or ejb jar
+ final BeanDeploymentArchive bda1 = new MockBeanDeploymentArchive("1");
+ bda1.getBeanClasses().add(Observer1.class);
+ bda1.getBeanClasses().add(Foo.class);
+
+ // Create the BDA to return from loadBeanDeploymentArchive for Observer2, this is probably a library, though could be another war or ejb jar
+ // bda2 is accessible from bda1, but isn't added to it's accessibility graph by default. This similar to an archive which doesn't contain a beans.xml but does contain an extension
+ final BeanDeploymentArchive bda2 = new MockBeanDeploymentArchive("2");
+ bda2.getBeanClasses().add(Observer2.class);
+
+ // Create the Collection of BDAs to deploy
+ final Collection<BeanDeploymentArchive> deployedBdas = new ArrayList<BeanDeploymentArchive>();
+ deployedBdas.add(bda1);
+
+ // Create a deployment, that we can use to mirror the structure of one Extension inside a BDA, and one outside
+ Deployment deployment = new Deployment()
+ {
+
+ private ServiceRegistry serviceRegistry = new SimpleServiceRegistry();
+
+ public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass)
+ {
+ // Return bda2 if it is Observer2. Stick anything else which this test isn't about in bda1
+ if (beanClass.equals(Observer2.class))
+ {
+ // If Observer2 is requested, then we need to add bda2 to the accessibility graph of bda1
+ bda1.getBeanDeploymentArchives().add(bda2);
+ return bda2;
+ }
+ else
+ {
+ return bda1;
+ }
+ }
+
+ public ServiceRegistry getServices()
+ {
+ return serviceRegistry;
+ }
+
+ public Collection<BeanDeploymentArchive> getBeanDeploymentArchives()
+ {
+ return deployedBdas;
+ }
+ };
+
+
+ // Initialize the container, we use the SE env as we aren't going to interact with the servlet lifecycle really
+ bootstrap.startContainer(Environments.SE, deployment, new HashMapBeanStore());
+
+ // Add custom ServiceLoader so that we can load Extension services from current package, not META-INF/services
+ // We do this after startContainer() so we replace the default impl
+ deployment.getServices().add(ServiceLoaderFactory.class, new PackageServiceLoaderFactory(ExtensionOutsideBDATest.class.getPackage(), Extension.class));
+
+ // Cause the container to deploy the beans etc.
+ bootstrap.startInitialization().deployBeans().validateBeans().endInitialization();
+
+ // Get the bean manager for bda1 and bda2
+ BeanManagerImpl beanManager1 = bootstrap.getManager(bda1);
+ BeanManagerImpl beanManager2 = bootstrap.getManager(bda2);
+
+ Observer1 observer1 = beanManager1.getInstanceByType(Observer1.class);
+ assert observer1.isBeforeBeanDiscoveryCalled();
+ assert observer1.isAfterBeanDiscoveryCalled();
+ assert observer1.isAfterDeploymentValidationCalled();
+ assert observer1.isProcessInjectionTargetCalled();
+ assert observer1.isProcessManagedBeanCalled();
+ assert observer1.isProcessProducerCalled();
+
+ assert beanManager2.getBeans(Observer2.class).size() == 1;
+ // Also check that the accessibility graph has been updated
+ assert beanManager1.getBeans(Observer2.class).size() == 1;
+
+ Observer2 observer2 = beanManager2.getInstanceByType(Observer2.class);
+ assert observer2.isBeforeBeanDiscoveryCalled();
+ assert observer2.isAfterBeanDiscoveryCalled();
+ assert observer2.isAfterDeploymentValidationCalled();
+ assert observer2.isProcessInjectionTargetCalled();
+ assert observer2.isProcessManagedBeanCalled();
+ assert observer2.isProcessProducerCalled();
+
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ExtensionOutsideBDATest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Foo.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Foo.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Foo.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,14 @@
+package org.jboss.weld.test.unit.deployment.structure.extensions;
+
+import javax.enterprise.inject.Produces;
+
+public class Foo
+{
+
+ @Produces
+ public String get()
+ {
+ return "Foo!";
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Foo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer1.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer1.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer1.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,45 @@
+package org.jboss.weld.test.unit.deployment.structure.extensions;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+import javax.enterprise.inject.spi.ProcessManagedBean;
+import javax.enterprise.inject.spi.ProcessProducer;
+
+public class Observer1 extends ObserverBase implements Extension
+{
+
+ public void observeAfterBeanDiscovery(@Observes AfterBeanDiscovery event)
+ {
+ this.afterBeanDiscoveryCalled = true;
+ }
+
+ public void observeBeforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
+ {
+ this.beforeBeanDiscoveryCalled = true;
+ }
+
+ public void observeAfterDeploymentValidation(@Observes AfterDeploymentValidation event)
+ {
+ afterDeploymentValidationCalled = true;
+ }
+
+ public void observeProcessProducer(@Observes ProcessProducer<Foo, String> event)
+ {
+ processProducerCalled = true;
+ }
+
+ public void observeProcessInjectionTarget(@Observes ProcessInjectionTarget<Foo> event)
+ {
+ processInjectionTargetCalled = true;
+ }
+
+ public void observeProcessManagedBean(@Observes ProcessManagedBean<Foo> event)
+ {
+ processManagedBeanCalled = true;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer1.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer2.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer2.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer2.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,45 @@
+package org.jboss.weld.test.unit.deployment.structure.extensions;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+import javax.enterprise.inject.spi.ProcessManagedBean;
+import javax.enterprise.inject.spi.ProcessProducer;
+
+public class Observer2 extends ObserverBase implements Extension
+{
+
+ public void observeAfterBeanDiscovery(@Observes AfterBeanDiscovery event)
+ {
+ this.afterBeanDiscoveryCalled = true;
+ }
+
+ public void observeBeforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
+ {
+ this.beforeBeanDiscoveryCalled = true;
+ }
+
+ public void observeAfterDeploymentValidation(@Observes AfterDeploymentValidation event)
+ {
+ afterDeploymentValidationCalled = true;
+ }
+
+ public void observeProcessProducer(@Observes ProcessProducer<Foo, String> event)
+ {
+ processProducerCalled = true;
+ }
+
+ public void observeProcessInjectionTarget(@Observes ProcessInjectionTarget<Foo> event)
+ {
+ processInjectionTargetCalled = true;
+ }
+
+ public void observeProcessManagedBean(@Observes ProcessManagedBean<Foo> event)
+ {
+ processManagedBeanCalled = true;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/Observer2.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ObserverBase.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ObserverBase.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ObserverBase.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,50 @@
+package org.jboss.weld.test.unit.deployment.structure.extensions;
+
+import javax.enterprise.inject.spi.Extension;
+
+public class ObserverBase
+{
+
+ protected boolean afterBeanDiscoveryCalled;
+ protected boolean beforeBeanDiscoveryCalled;
+ protected boolean afterDeploymentValidationCalled;
+ protected boolean processProducerCalled;
+ protected boolean processInjectionTargetCalled;
+ protected boolean processManagedBeanCalled;
+
+ public ObserverBase()
+ {
+ super();
+ }
+
+ public boolean isAfterBeanDiscoveryCalled()
+ {
+ return afterBeanDiscoveryCalled;
+ }
+
+ public boolean isBeforeBeanDiscoveryCalled()
+ {
+ return beforeBeanDiscoveryCalled;
+ }
+
+ public boolean isAfterDeploymentValidationCalled()
+ {
+ return afterDeploymentValidationCalled;
+ }
+
+ public boolean isProcessProducerCalled()
+ {
+ return processProducerCalled;
+ }
+
+ public boolean isProcessInjectionTargetCalled()
+ {
+ return processInjectionTargetCalled;
+ }
+
+ public boolean isProcessManagedBeanCalled()
+ {
+ return processManagedBeanCalled;
+ }
+
+}
\ No newline at end of file
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/extensions/ObserverBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java (from rev 4492, core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/AccessibleManagerResolutionTest.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,157 @@
+package org.jboss.weld.test.unit.deployment.structure.resolution;
+
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.weld.BeanManagerImpl;
+import org.jboss.weld.Container;
+import org.jboss.weld.ContextualStoreImpl;
+import org.jboss.weld.bean.ManagedBean;
+import org.jboss.weld.bean.RIBean;
+import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
+import org.jboss.weld.bootstrap.api.ServiceRegistry;
+import org.jboss.weld.bootstrap.api.helpers.SimpleServiceRegistry;
+import org.jboss.weld.ejb.EjbDescriptors;
+import org.jboss.weld.introspector.WeldClass;
+import org.jboss.weld.introspector.jlr.WeldClassImpl;
+import org.jboss.weld.metadata.TypeStore;
+import org.jboss.weld.metadata.cache.MetaAnnotationStore;
+import org.jboss.weld.resources.ClassTransformer;
+import org.jboss.weld.serialization.spi.ContextualStore;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class AccessibleManagerResolutionTest
+{
+
+ private ClassTransformer classTransformer;
+ private ServiceRegistry services;
+
+ @BeforeMethod
+ public void beforeMethod()
+ {
+ this.classTransformer = new ClassTransformer(new TypeStore());
+ this.services = new SimpleServiceRegistry();
+ this.services.add(MetaAnnotationStore.class, new MetaAnnotationStore(classTransformer));
+ this.services.add(ContextualStore.class, new ContextualStoreImpl());
+ }
+
+ private void addBean(BeanManagerImpl manager, Class<?> c)
+ {
+ WeldClass<?> clazz = WeldClassImpl.of(c, classTransformer);
+ RIBean<?> bean = ManagedBean.of(clazz, manager);
+ manager.addBean(bean);
+ BeanDeployerEnvironment environment = new BeanDeployerEnvironment(new EjbDescriptors(), manager);
+ bean.initialize(environment);
+ }
+
+ @Test
+ public void testAccessibleDynamicallySingleLevel()
+ {
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ Container.initialize(root, services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
+ addBean(root, Cow.class);
+ assert root.getBeans(Cow.class).size() == 1;
+ assert child.getBeans(Cow.class).size() == 0;
+ child.addAccessibleBeanManager(root);
+ Set<Bean<?>> beans = child.getBeans(Cow.class);
+ assert child.getBeans(Cow.class).size() == 1;
+ addBean(child, Chicken.class);
+ assert child.getBeans(Chicken.class).size() == 1;
+ assert root.getBeans(Chicken.class).size() == 0;
+ }
+
+ @Test
+ public void testAccessibleThreeLevelsWithMultiple()
+ {
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ Container.initialize(root, services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
+ BeanManagerImpl child1 = BeanManagerImpl.newRootManager("child1", services);
+ BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
+ BeanManagerImpl greatGrandchild = BeanManagerImpl.newRootManager("greatGrandchild", services);
+ child.addAccessibleBeanManager(root);
+ grandchild.addAccessibleBeanManager(child1);
+ grandchild.addAccessibleBeanManager(child);
+ addBean(greatGrandchild, Cat.class);
+ greatGrandchild.addAccessibleBeanManager(grandchild);
+ addBean(root, Cow.class);
+ addBean(child, Chicken.class);
+ addBean(grandchild, Pig.class);
+ addBean(child1, Horse.class);
+ assert root.getBeans(Pig.class).size() == 0;
+ assert root.getBeans(Chicken.class).size() == 0;
+ assert root.getBeans(Cow.class).size() == 1;
+ assert root.getBeans(Horse.class).size() == 0;
+ assert root.getBeans(Cat.class).size() == 0;
+ assert child.getBeans(Pig.class).size() == 0;
+ assert child.getBeans(Chicken.class).size() == 1;
+ assert child.getBeans(Cow.class).size() == 1;
+ assert child.getBeans(Horse.class).size() == 0;
+ assert child.getBeans(Cat.class).size() == 0;
+ assert child1.getBeans(Cow.class).size() == 0;
+ assert child1.getBeans(Horse.class).size() == 1;
+ assert grandchild.getBeans(Pig.class).size() == 1;
+ assert grandchild.getBeans(Chicken.class).size() == 1;
+ assert grandchild.getBeans(Cow.class).size() == 1;
+ assert grandchild.getBeans(Horse.class).size() ==1;
+ assert grandchild.getBeans(Cat.class).size() == 0;
+ assert greatGrandchild.getBeans(Pig.class).size() == 1;
+ assert greatGrandchild.getBeans(Chicken.class).size() == 1;
+ assert greatGrandchild.getBeans(Cow.class).size() == 1;
+ assert greatGrandchild.getBeans(Horse.class).size() ==1;
+ assert greatGrandchild.getBeans(Cat.class).size() == 1;
+ }
+
+ @Test
+ public void testSameManagerAddedTwice()
+ {
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ Container.initialize(root, services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
+ BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
+ grandchild.addAccessibleBeanManager(child);
+ child.addAccessibleBeanManager(root);
+ grandchild.addAccessibleBeanManager(root);
+ addBean(root, Cow.class);
+ addBean(child, Chicken.class);
+ addBean(grandchild, Pig.class);
+ assert root.getBeans(Pig.class).size() == 0;
+ assert root.getBeans(Chicken.class).size() == 0;
+ assert root.getBeans(Cow.class).size() == 1;
+ assert child.getBeans(Pig.class).size() == 0;
+ assert child.getBeans(Chicken.class).size() == 1;
+ assert child.getBeans(Cow.class).size() == 1;
+ assert grandchild.getBeans(Pig.class).size() == 1;
+ assert grandchild.getBeans(Chicken.class).size() == 1;
+ assert grandchild.getBeans(Cow.class).size() == 1;
+ }
+
+ @Test
+ public void testCircular()
+ {
+ BeanManagerImpl root = BeanManagerImpl.newRootManager("root", services);
+ Container.initialize(root, services);
+ BeanManagerImpl child = BeanManagerImpl.newRootManager("child", services);
+ BeanManagerImpl grandchild = BeanManagerImpl.newRootManager("grandchild", services);
+ grandchild.addAccessibleBeanManager(child);
+ child.addAccessibleBeanManager(root);
+ grandchild.addAccessibleBeanManager(root);
+ root.addAccessibleBeanManager(grandchild);
+ addBean(root, Cow.class);
+ addBean(child, Chicken.class);
+ addBean(grandchild, Pig.class);
+ assert root.getBeans(Pig.class).size() == 1;
+ assert root.getBeans(Chicken.class).size() == 1;
+ assert root.getBeans(Cow.class).size() == 1;
+ assert child.getBeans(Pig.class).size() == 1;
+ assert child.getBeans(Chicken.class).size() == 1;
+ assert child.getBeans(Cow.class).size() == 1;
+ assert grandchild.getBeans(Pig.class).size() == 1;
+ assert grandchild.getBeans(Chicken.class).size() == 1;
+ assert grandchild.getBeans(Cow.class).size() == 1;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/AccessibleManagerResolutionTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cat.java (from rev 4492, core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cat.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cat.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cat.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,26 @@
+/*
+ * 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.weld.test.unit.deployment.structure.resolution;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Cat
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cat.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Chicken.java (from rev 4492, core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Chicken.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Chicken.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Chicken.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,26 @@
+/*
+ * 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.weld.test.unit.deployment.structure.resolution;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Chicken
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Chicken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cow.java (from rev 4492, core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Cow.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cow.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cow.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,26 @@
+/*
+ * 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.weld.test.unit.deployment.structure.resolution;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Cow
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Cow.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Horse.java (from rev 4492, core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Horse.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Horse.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Horse.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,26 @@
+/*
+ * 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.weld.test.unit.deployment.structure.resolution;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Horse
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Horse.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Pig.java (from rev 4492, core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/Pig.java)
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Pig.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Pig.java 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,26 @@
+/*
+ * 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.weld.test.unit.deployment.structure.resolution;
+
+/**
+ * @author pmuir
+ *
+ */
+public class Pig
+{
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/test/unit/deployment/structure/resolution/Pig.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/resources/org/jboss/weld/test/unit/deployment/structure/extensions/javax.enterprise.inject.spi.Extension
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/test/unit/deployment/structure/extensions/javax.enterprise.inject.spi.Extension (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/test/unit/deployment/structure/extensions/javax.enterprise.inject.spi.Extension 2009-11-01 22:19:24 UTC (rev 4526)
@@ -0,0 +1,3 @@
+org.jboss.weld.test.unit.deployment.structure.extensions.Observer1
+org.jboss.weld.test.unit.deployment.structure.extensions.Observer2
+org.jboss.weld.test.unit.deployment.structure.extensions.Observer3
\ No newline at end of file
Modified: core/trunk/tests/unit-tests.xml
===================================================================
--- core/trunk/tests/unit-tests.xml 2009-11-01 22:17:29 UTC (rev 4525)
+++ core/trunk/tests/unit-tests.xml 2009-11-01 22:19:24 UTC (rev 4526)
@@ -36,7 +36,7 @@
<package name="org.jboss.weld.test.unit.context" />
<package name="org.jboss.weld.test.unit.decorator.simple" />
<package name="org.jboss.weld.test.unit.definition" />
- <package name="org.jboss.weld.test.unit.deployment.structure" />
+ <package name="org.jboss.weld.test.unit.deployment.structure.resolution" />
<package name="org.jboss.weld.test.unit.environments.servlet" />
<package name="org.jboss.weld.test.unit.extensions" />
<package name="org.jboss.weld.test.unit.implementation" />
More information about the weld-commits
mailing list