Skip to content

Commit

Permalink
rationalize SPI, switch to a returning singleton on manager deseriali…
Browse files Browse the repository at this point in the history
…zation (and remove implements Serializable on helper classes), add AnnotatedMember and alter InjectionPointImpl to take AnnotatedMember, wire in EjbResolver to SimpleBean field injection, refactor bootstrap slightly to inject externally specified helper classes into Manager

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@798 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jan 6, 2009
1 parent 028f3dc commit d6eb8ff
Show file tree
Hide file tree
Showing 28 changed files with 298 additions and 212 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -85,6 +85,12 @@
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>org.scannotation</groupId>
Expand Down
@@ -1,5 +1,9 @@
package org.jboss.webbeans.ejb.spi;

import java.lang.annotation.Annotation;

import javax.webbeans.InjectionPoint;

/**
* A container should implement this interface to allow the Web Beans RI to
* resolve EJBs and JPA persistence units
Expand All @@ -9,41 +13,27 @@
*/
public interface EjbResolver
{

public static final String PROPERTY_NAME = EjbResolver.class.getName();

/**
* Resolve the EJB for the given parameters
* Resolve the JNDI name for the @EJB injection point
*
* @param name
* The logical name of the ejb reference within the declaring
* component's (java:comp/env) environment.
* @param beanName
* The ejb-name of the Enterprise Java Bean to which this reference
* is mapped. Only applicable if the target EJB is defined within
* the same application or stand-alone module as the declaring
* component.
* @param beanInterface
* Holds one of the following interface types of the target EJB : [
* Local business interface, Remote business interface, Local Home
* interface, Remote Home interface ]
* @param mappedName
* The product specific name of the EJB component to which this ejb
* reference should be mapped. This mapped name is often a global
* JNDI name, but may be a name of any form. Application servers
* are not required to support any particular form or type of
* mapped name, nor the ability to use mapped names. The mapped
* name is product-dependent and often installation-dependent. No
* use of a mapped name is portable.
* @return
* @param injectionPoint The injection point metadata
* @return the JNDI name
*/
public Object resolveEjb(String name, String beanName, Class<?> beanInterface, String mappedName);
public String resolveEjb(InjectionPoint injectionPoint);

/**
* Resolve the persistence unit for the given peristence unit name
* Resolve the JNDI name for the @PersistenceContext injection point
*
* @param persistenceUnitName
* the name of the persistence unit to resolve, if null, the
* default persistence unit for the application should be resolved
* @return the resolved persistence unit
* @param injectionPoint The injection point metadata
* @return the JNDI name
*/
public Object resolvePersistenceUnit(String persistenceUnitName);
public String resolvePersistenceUnit(InjectionPoint injectionPoint);

public Class<? extends Annotation> getEJBAnnotation();

public Class<? extends Annotation> getPersistenceContextAnnotation();

}

This file was deleted.

Expand Up @@ -17,10 +17,7 @@

package org.jboss.webbeans.resources.spi;

import java.io.Serializable;


public interface Naming extends Serializable
public interface Naming
{

public static final String PROPERTY_NAME = Naming.class.getName();
Expand Down
8 changes: 8 additions & 0 deletions webbeans-ri/pom.xml
Expand Up @@ -46,11 +46,19 @@
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb-api</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<optional>true</optional>
</dependency>

<dependency>
Expand Down
54 changes: 35 additions & 19 deletions webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Expand Up @@ -54,11 +54,13 @@
import org.jboss.webbeans.bean.proxy.ProxyPool;
import org.jboss.webbeans.context.ContextMap;
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.ejb.spi.EjbResolver;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.resources.spi.Naming;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.util.Reflections;

/**
Expand All @@ -80,40 +82,47 @@ public class ManagerImpl implements Manager, Serializable
public static final String JNDI_KEY = "java:comp/Manager";

// The enabled deployment types from web-beans.xml
private List<Class<? extends Annotation>> enabledDeploymentTypes;
private transient List<Class<? extends Annotation>> enabledDeploymentTypes;
// The Web Beans manager
private EventManager eventManager;
private transient final EventManager eventManager;

// The bean resolver
// The cache can be rebuilt at any time
private transient Resolver resolver;
private transient final Resolver resolver;

// The registered contexts
private ContextMap contextMap;
private transient final ContextMap contextMap;
// The client proxy pool
private ProxyPool proxyPool;
private transient final ProxyPool proxyPool;
// The registered beans
private List<Bean<?>> beans;
private transient List<Bean<?>> beans;
// The registered beans, mapped by implementation class
private Map<Class<?>, Bean<?>> beanMap;
private transient final Map<Class<?>, Bean<?>> beanMap;
// The registered decorators
private Set<Decorator> decorators;
private transient final Set<Decorator> decorators;
// The registered interceptors
private Set<Interceptor> interceptors;
private transient final Set<Interceptor> interceptors;

// The EJB resolver provided by the container
// TODO This can't be transient!
private transient final EjbResolver ejbResolver;

private EjbDescriptorCache ejbDescriptorCache;
private transient final EjbDescriptorCache ejbDescriptorCache;

private transient final ResourceLoader resourceLoader;

// The Naming (JNDI) access
private Naming naming;
private transient final Naming naming;

/**
* Constructor
* Create a new manager
*
* @param enabledDeploymentTypes any enabled deployment types, an empty set
* if none are specified
* @param ejbResolver the ejbResolver to use
*/
public ManagerImpl()
public ManagerImpl(Naming naming, EjbResolver ejbResolver, ResourceLoader resourceLoader)
{
this.ejbResolver = ejbResolver;
this.naming = naming;
this.resourceLoader = resourceLoader;
this.beans = new CopyOnWriteArrayList<Bean<?>>();
this.beanMap = new ConcurrentHashMap<Class<?>, Bean<?>>();
this.resolver = new Resolver(this);
Expand Down Expand Up @@ -736,10 +745,17 @@ public Naming getNaming()
{
return naming;
}

public void setNaming(Naming naming)
public EjbResolver getEjbResolver()
{
this.naming = naming;
return ejbResolver;
}

// Serialization

protected Object readResolve()
{
return CurrentManager.rootManager();
}

}
22 changes: 19 additions & 3 deletions webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
Expand Up @@ -25,11 +25,13 @@
import javax.annotation.PreDestroy;
import javax.webbeans.DefinitionException;
import javax.webbeans.Initializer;
import javax.webbeans.InjectionPoint;
import javax.webbeans.manager.Manager;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.MetaDataCache;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.injection.InjectionPointImpl;
import org.jboss.webbeans.introspector.AnnotatedConstructor;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
Expand Down Expand Up @@ -90,7 +92,7 @@ public T create()
T instance = constructor.newInstance(manager);
bindDecorators();
bindInterceptors();
injectEjbAndCommonFields();
injectEjbAndCommonFields(instance);
injectBoundFields(instance, manager);
callInitializers(instance);
callPostConstruct(instance);
Expand Down Expand Up @@ -185,9 +187,23 @@ protected void callInitializers(T instance)
/**
* Injects EJBs and common fields
*/
protected void injectEjbAndCommonFields()
protected void injectEjbAndCommonFields(T beanInstance)
{
// Support common and EJB annotations
for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getEJBAnnotation()))
{
InjectionPoint injectionPoint = new InjectionPointImpl(field, this, beanInstance);
String name = manager.getEjbResolver().resolveEjb(injectionPoint);
Object ejbInstance = manager.getNaming().lookup(name, Object.class);
field.inject(beanInstance, ejbInstance);
}

for (AnnotatedField<?> field : annotatedItem.getAnnotatedFields(manager.getEjbResolver().getPersistenceContextAnnotation()))
{
InjectionPoint injectionPoint = new InjectionPointImpl(field, this, beanInstance);
String name = manager.getEjbResolver().resolvePersistenceUnit(injectionPoint);
Object puInstance = manager.getNaming().lookup(name, Object.class);
field.inject(beanInstance, puInstance);
}
}

/**
Expand Down
Expand Up @@ -39,7 +39,7 @@
*
* @see org.jboss.webbeans.bean.proxy.ProxyMethodHandler
*/
public class ProxyPool implements Serializable
public class ProxyPool
{
private static final long serialVersionUID = 9029999149357529341L;

Expand Down
Expand Up @@ -24,8 +24,6 @@

import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.resource.DefaultNaming;
import org.jboss.webbeans.resources.spi.Naming;
import org.jboss.webbeans.resources.spi.ResourceLoader;
import org.jboss.webbeans.servlet.ServletBootstrap;
import org.jboss.webbeans.util.DeploymentProperties;
Expand All @@ -40,6 +38,7 @@
*/
public abstract class PropertiesBasedBootstrap extends WebBeansBootstrap
{

// The log provider
private static final LogProvider log = Logging.getLogProvider(ServletBootstrap.class);

Expand Down Expand Up @@ -100,25 +99,6 @@ protected static <T> T newInstance(Constructor<T> constructor, Object... paramet
}
}

/**
* Initializes the naming provider
*
* Only safe to call once resourceloader and deployment properties are set
*/
protected void initProperties()
{
Constructor<? extends Naming> namingConstructor = getClassConstructor(getDeploymentProperties(), getResourceLoader(), Naming.PROPERTY_NAME, Naming.class);
if (namingConstructor != null)
{
getManager().setNaming(newInstance(namingConstructor));
}
else
{
getManager().setNaming(new DefaultNaming());
}
}


/**
* Gets the deployment properties
*
Expand Down

0 comments on commit d6eb8ff

Please sign in to comment.