Skip to content

Commit

Permalink
wire resource beans through to XMLEnvironment
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2389 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Apr 10, 2009
1 parent 2da180c commit 04e25be
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Expand Up @@ -66,6 +66,15 @@ public <T> BeanDeployer addBean(RIBean<T> bean)
return this;
}

public BeanDeployer addBeans(Iterable<? extends RIBean<?>> beans)
{
for (RIBean<?> bean : beans)
{
addBean(bean);
}
return this;
}

public BeanDeployer addClass(Class<?> clazz)
{
if (!clazz.isAnnotation() && !clazz.isEnum())
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.jboss.webbeans.BeanValidator;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.ee.AbstractJavaEEResourceBean;
import org.jboss.webbeans.bean.standard.EventBean;
import org.jboss.webbeans.bean.standard.InjectionPointBean;
import org.jboss.webbeans.bean.standard.InstanceBean;
Expand Down Expand Up @@ -161,7 +162,7 @@ public ManagerImpl getManager()
*
* @param classes The classes to register as Web Beans
*/
protected void registerBeans(Iterable<Class<?>> classes, Collection<AnnotatedClass<?>> xmlClasses, EjbDescriptorCache ejbDescriptors)
protected void registerBeans(Iterable<Class<?>> classes, Collection<AnnotatedClass<?>> xmlClasses, Iterable<AbstractJavaEEResourceBean<?>> resourceBeans, EjbDescriptorCache ejbDescriptors)
{
BeanDeployer beanDeployer = new BeanDeployer(manager, ejbDescriptors);
beanDeployer.addClasses(classes);
Expand All @@ -178,6 +179,7 @@ protected void registerBeans(Iterable<Class<?>> classes, Collection<AnnotatedCla
beanDeployer.addClass(NumericConversationIdGenerator.class);
beanDeployer.addClass(HttpSessionManager.class);
}
beanDeployer.addBeans(resourceBeans);
beanDeployer.createBeans().deploy();
}

Expand Down Expand Up @@ -205,7 +207,7 @@ public void boot()
ejbDescriptors.addAll(getServices().get(EjbServices.class).discoverEjbs());
}

XmlEnvironment xmlEnvironmentImpl = new XmlEnvironment(getServices(), ejbDescriptors);
XmlEnvironment xmlEnvironmentImpl = new XmlEnvironment(getServices(), ejbDescriptors, manager);
XmlParser parser = new XmlParser(xmlEnvironmentImpl);
parser.parse();

Expand All @@ -215,7 +217,7 @@ public void boot()
manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
log.info("Deployment types: " + manager.getEnabledDeploymentTypes());
registerBeans(getServices().get(WebBeanDiscovery.class).discoverWebBeanClasses(), xmlEnvironmentImpl.getClasses(), ejbDescriptors);
registerBeans(getServices().get(WebBeanDiscovery.class).discoverWebBeanClasses(), xmlEnvironmentImpl.getClasses(), xmlEnvironmentImpl.getResourceBeans(), ejbDescriptors);
manager.fireEvent(manager, new InitializedLiteral());
log.info("Web Beans initialized. Validating beans.");
manager.getResolver().resolveInjectionPoints();
Expand Down
Expand Up @@ -2,6 +2,7 @@

import java.net.URL;

import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.api.helpers.SimpleServiceRegistry;
import org.jboss.webbeans.ejb.EjbDescriptorCache;
Expand All @@ -24,7 +25,7 @@ public class MockXmlEnvironment extends XmlEnvironment

public MockXmlEnvironment(Iterable<URL> beansXmlUrls, EjbDescriptorCache ejbDescriptors)
{
super(services, beansXmlUrls, ejbDescriptors);
super(services, beansXmlUrls, ejbDescriptors, CurrentManager.rootManager());
}

}
30 changes: 26 additions & 4 deletions impl/src/main/java/org/jboss/webbeans/xml/XmlEnvironment.java
Expand Up @@ -3,14 +3,17 @@
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.ee.AbstractJavaEEResourceBean;
import org.jboss.webbeans.bootstrap.api.ServiceRegistry;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.introspector.AnnotatedAnnotation;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.resources.ClassTransformer;
import org.jboss.webbeans.resources.spi.ResourceLoader;

Expand All @@ -23,20 +26,24 @@ public class XmlEnvironment
private final List<Class<? extends Annotation>> enabledDeploymentTypes;
private final Iterable<URL> beansXmlUrls;
private final EjbDescriptorCache ejbDescriptors;
private final Set<AbstractJavaEEResourceBean<?>> resourceBeans;
private final ManagerImpl manager;

public XmlEnvironment(ServiceRegistry serviceRegistry, EjbDescriptorCache ejbDescriptors)
public XmlEnvironment(ServiceRegistry serviceRegistry, EjbDescriptorCache ejbDescriptors, ManagerImpl manager)
{
this(serviceRegistry, serviceRegistry.get(WebBeanDiscovery.class).discoverWebBeansXml(), ejbDescriptors);
this(serviceRegistry, serviceRegistry.get(WebBeanDiscovery.class).discoverWebBeansXml(), ejbDescriptors, manager);
}

protected XmlEnvironment(ServiceRegistry serviceRegistry, Iterable<URL> beanXmlUrls, EjbDescriptorCache ejbDescriptors)
protected XmlEnvironment(ServiceRegistry serviceRegistry, Iterable<URL> beanXmlUrls, EjbDescriptorCache ejbDescriptors, ManagerImpl manager)
{
this.classes = new ArrayList<AnnotatedClass<?>>();
this.annotations = new ArrayList<AnnotatedAnnotation<?>>();
this.enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
this.resourceBeans = new HashSet<AbstractJavaEEResourceBean<?>>();
this.serviceRegistry = serviceRegistry;
this.beansXmlUrls = beanXmlUrls;
this.ejbDescriptors = ejbDescriptors;
this.manager = manager;
}

public List<AnnotatedClass<?>> getClasses()
Expand Down Expand Up @@ -83,4 +90,19 @@ public URL loadFileByUrn(String urn, String fileName)
return serviceRegistry.get(ResourceLoader.class).getResource(filePath);
}

public ServiceRegistry getServiceRegistry()
{
return serviceRegistry;
}

public Set<AbstractJavaEEResourceBean<?>> getResourceBeans()
{
return resourceBeans;
}

public ManagerImpl getManager()
{
return manager;
}

}

0 comments on commit 04e25be

Please sign in to comment.