Skip to content

Commit

Permalink
WELD-329
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jan 7, 2010
1 parent 63708c8 commit 354f6bb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 63 deletions.
40 changes: 39 additions & 1 deletion impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
Expand Up @@ -22,6 +22,7 @@
import static org.jboss.weld.logging.messages.BeanMessage.INVOCATION_ERROR;
import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
import static org.jboss.weld.logging.messages.BeanMessage.ONLY_ONE_SCOPE_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
import static org.jboss.weld.logging.messages.BeanMessage.SPECIALIZING_BEAN_MUST_EXTEND_A_BEAN;
Expand All @@ -40,6 +41,8 @@
import javax.enterprise.context.Dependent;
import javax.enterprise.context.NormalScope;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
Expand All @@ -63,6 +66,7 @@
import org.jboss.weld.context.SerializableContextualImpl;
import org.jboss.weld.context.SerializableContextualInstanceImpl;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.injection.ConstructorInjectionPoint;
import org.jboss.weld.injection.FieldInjectionPoint;
import org.jboss.weld.injection.MethodInjectionPoint;
import org.jboss.weld.introspector.WeldClass;
Expand All @@ -74,7 +78,6 @@
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.Strings;
import org.jboss.weld.util.Proxies.TypeInfo;
import org.jboss.weld.util.reflection.Reflections;
import org.jboss.weld.util.reflection.SecureReflections;
import org.slf4j.cal10n.LocLogger;

Expand Down Expand Up @@ -116,6 +119,8 @@ public abstract class AbstractClassBean<T> extends AbstractBean<T, Class<T>>
// Injection target for the bean
private InjectionTarget<T> injectionTarget;

private ConstructorInjectionPoint<T> constructor;

/**
* Constructor
*
Expand Down Expand Up @@ -168,6 +173,7 @@ public void initializeAfterBeanDiscovery()
}
}

@Override
public void checkType()
{

Expand Down Expand Up @@ -625,5 +631,37 @@ protected void initDirectlyDefinedInterceptors()
}
}

protected void checkConstructor()
{
if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())
{
throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Disposes", constructor);
}
if (!constructor.getAnnotatedWBParameters(Observes.class).isEmpty())
{
throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Observes", constructor);
}
}

/**
* Initializes the constructor
*/
protected void initConstructor()
{
this.constructor = Beans.getBeanConstructor(this, getAnnotatedItem());
// TODO We loop unecessarily many times here, I want to probably introduce some callback mechanism. PLM.
addInjectionPoints(Beans.getParameterInjectionPoints(this, constructor));
}

/**
* Returns the constructor
*
* @return The constructor
*/
public ConstructorInjectionPoint<T> getConstructor()
{
return constructor;
}


}
41 changes: 1 addition & 40 deletions impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
Expand Up @@ -24,7 +24,6 @@
import static org.jboss.weld.logging.messages.BeanMessage.FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.FINAL_DECORATED_BEAN_METHOD_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.NON_CONTAINER_DECORATOR;
import static org.jboss.weld.logging.messages.BeanMessage.PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR;
import static org.jboss.weld.logging.messages.BeanMessage.PASSIVATING_BEAN_NEEDS_SERIALIZABLE_IMPL;
import static org.jboss.weld.logging.messages.BeanMessage.PUBLIC_FIELD_ON_NORMAL_SCOPED_BEAN_NOT_ALLOWED;
import static org.jboss.weld.logging.messages.BeanMessage.SIMPLE_BEAN_AS_NON_STATIC_INNER_CLASS_NOT_ALLOWED;
Expand All @@ -36,8 +35,6 @@

import javax.enterprise.context.Dependent;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.spi.Decorator;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
Expand All @@ -56,7 +53,6 @@
import org.jboss.weld.bean.interceptor.CdiInterceptorHandlerFactory;
import org.jboss.weld.bean.interceptor.ClassInterceptionHandlerFactory;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.injection.ConstructorInjectionPoint;
import org.jboss.weld.injection.InjectionContextImpl;
import org.jboss.weld.injection.WeldInjectionPoint;
import org.jboss.weld.introspector.WeldClass;
Expand Down Expand Up @@ -84,9 +80,6 @@ public class ManagedBean<T> extends AbstractClassBean<T>
private static final LocLogger log = loggerFactory().getLogger(BEAN);
private static final XLogger xLog = loggerFactory().getXLogger(BEAN);

// The constructor
private ConstructorInjectionPoint<T> constructor;

// The Java EE style injection points
private Set<WeldInjectionPoint<?, ?>> ejbInjectionPoints;
private Set<WeldInjectionPoint<?, ?>> persistenceContextInjectionPoints;
Expand Down Expand Up @@ -273,7 +266,7 @@ public T produce(CreationalContext<T> ctx)

protected T createInstance(CreationalContext<T> ctx)
{
return constructor.newInstance(manager, ctx);
return getConstructor().newInstance(manager, ctx);
}

@Override
Expand Down Expand Up @@ -425,18 +418,6 @@ protected void checkBeanImplementation()
}
}

protected void checkConstructor()
{
if (!constructor.getAnnotatedWBParameters(Disposes.class).isEmpty())
{
throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Disposes", constructor);
}
if (!constructor.getAnnotatedWBParameters(Observes.class).isEmpty())
{
throw new DefinitionException(PARAMETER_ANNOTATION_NOT_ALLOWED_ON_CONSTRUCTOR, "@Observes", constructor);
}
}

@Override
protected void preSpecialize(BeanDeployerEnvironment environment)
{
Expand Down Expand Up @@ -465,26 +446,6 @@ protected void specialize(BeanDeployerEnvironment environment)
}


/**
* Initializes the constructor
*/
protected void initConstructor()
{
this.constructor = Beans.getBeanConstructor(this, getAnnotatedItem());
// TODO We loop unecessarily many times here, I want to probably introduce some callback mechanism. PLM.
addInjectionPoints(Beans.getParameterInjectionPoints(this, constructor));
}

/**
* Returns the constructor
*
* @return The constructor
*/
public ConstructorInjectionPoint<T> getConstructor()
{
return constructor;
}

/**
* Gets a string representation
*
Expand Down
52 changes: 30 additions & 22 deletions impl/src/main/java/org/jboss/weld/bean/SessionBean.java
Expand Up @@ -125,6 +125,7 @@ protected SessionBean(WeldClass<T> type, InternalEjbDescriptor<T> ejbDescriptor,
this.ejbDescriptor = ejbDescriptor;
initTypes();
initBindings();
initConstructor();
}

/**
Expand All @@ -135,6 +136,7 @@ public void initialize(BeanDeployerEnvironment environment)
{
if (!isInitialized())
{
checkConstructor();
super.initialize(environment);
initProxyClass();
checkEJBTypeAllowed();
Expand Down Expand Up @@ -180,29 +182,17 @@ public Set<InjectionPoint> getInjectionPoints()

public T produce(CreationalContext<T> ctx)
{
try
{
T instance = SecureReflections.newInstance(proxyClass);
ctx.push(instance);
return Proxies.attachMethodHandler(instance, new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, ctx));
}
catch (InstantiationException e)
{
throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
}
catch (IllegalAccessException e)
{
throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
}
catch (Exception e)
{
throw new CreationException(EJB_NOT_FOUND, e, proxyClass);
}
return SessionBean.this.createInstance(ctx);
}

});
}
}

protected T createInstance(CreationalContext<T> ctx)
{
return getConstructor().newInstance(manager, ctx);
}

@Override
protected void initTypes()
Expand Down Expand Up @@ -299,12 +289,30 @@ protected void specialize(BeanDeployerEnvironment environment)
*/
public T create(final CreationalContext<T> creationalContext)
{
T instance = getInjectionTarget().produce(creationalContext);
if (hasDecorators())
try
{
T instance = SecureReflections.newInstance(proxyClass);
creationalContext.push(instance);
Proxies.attachMethodHandler(instance, new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, creationalContext));
if (hasDecorators())
{
instance = applyDecorators(instance, creationalContext, null);
}
return instance;
}
catch (InstantiationException e)
{
instance = applyDecorators(instance, creationalContext, null);
throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
}
return instance;
catch (IllegalAccessException e)
{
throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
}
catch (Exception e)
{
throw new CreationException(EJB_NOT_FOUND, e, proxyClass);
}

}

public void destroy(T instance, CreationalContext<T> creationalContext)
Expand Down

0 comments on commit 354f6bb

Please sign in to comment.