Author: danielc.roth
Date: 2009-04-05 18:01:20 -0400 (Sun, 05 Apr 2009)
New Revision: 2306
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethodBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
Log:
Disposal Methods update
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethodBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethodBean.java 2009-04-05
20:16:46 UTC (rev 2305)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethodBean.java 2009-04-05
22:01:20 UTC (rev 2306)
@@ -29,10 +29,10 @@
public class DisposalMethodBean<T> extends AbstractBean<T, Method>
{
- protected DisposalMethodBean(ManagerImpl manager, AnnotatedMethod<T>
disposalMethod, Bean<?> declaringBean)
+ protected DisposalMethodBean(ManagerImpl manager, AnnotatedMethod<T>
disposalMethod, AbstractClassBean<?> declaringBean)
{
super(manager);
- this.disposalMethod = disposalMethod;
+ this.disposalMethodInjectionPoint = MethodInjectionPoint.of(this, disposalMethod);
this.declaringBean = declaringBean;
checkDisposalMethod();
initInjectionPoints();
@@ -42,27 +42,22 @@
}
- protected Bean<?> declaringBean;
- protected AnnotatedMethod<T> disposalMethod;
+ protected AbstractClassBean<?> declaringBean;
+ private ProducerMethodBean<?> specializedBean;
+ protected MethodInjectionPoint<T> disposalMethodInjectionPoint;
protected Set<AnnotatedInjectionPoint<?, ?>> disposalInjectionPoints;
private String id;
- @Override
- protected void initTypes()
+ protected void initType()
{
- Set<Type> types = new HashSet<Type>();
- types = new HashSet<Type>();
- types.add(getType());
- types.add(Object.class); // FODO: Maybe not?
- super.types = types;
+ this.type = (Class<T>)
disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).get(0).getRawType();
}
- protected void initType()
- {
- this.type = (Class<T>)
disposalMethod.getAnnotatedParameters(Disposes.class).get(0).getRawType();
+ public AnnotatedMethod<T> getAnnotatedItem() {
+ return disposalMethodInjectionPoint;
}
-
- public static <T> DisposalMethodBean<T> of(ManagerImpl manager,
AnnotatedMethod<T> disposalMethod, Bean<?> declaringBean)
+
+ public static <T> DisposalMethodBean<T> of(ManagerImpl manager,
AnnotatedMethod<T> disposalMethod, AbstractClassBean<?> declaringBean)
{
return new DisposalMethodBean<T>(manager, disposalMethod, declaringBean);
}
@@ -71,7 +66,7 @@
{
disposalInjectionPoints = new HashSet<AnnotatedInjectionPoint<?,
?>>();
- List<? extends AnnotatedParameter<?>> disposalMethodParameters =
disposalMethod.getParameters();
+ List<? extends AnnotatedParameter<?>> disposalMethodParameters =
disposalMethodInjectionPoint.getParameters();
// First one must be @Disposes, if more, register injectionpoints
if (disposalMethodParameters.size() > 1)
@@ -83,7 +78,7 @@
}
}
- injectionPoints.add(MethodInjectionPoint.of(declaringBean, disposalMethod));
+ injectionPoints.add(MethodInjectionPoint.of(declaringBean,
disposalMethodInjectionPoint));
}
@@ -91,7 +86,7 @@
public Set<Annotation> getBindings()
{
// At least 1 parameter exists, already checked in constructor
- return disposalMethod.getParameters().get(0).getBindings();
+ return disposalMethodInjectionPoint.getParameters().get(0).getBindings();
}
@Override
@@ -108,7 +103,7 @@
@Override
public String getName()
{
- return disposalMethod.getPropertyName();
+ return disposalMethodInjectionPoint.getPropertyName();
}
@Override
@@ -126,7 +121,7 @@
@Override
public String toString()
{
- return disposalMethod.toString();
+ return disposalMethodInjectionPoint.toString();
}
@Override
@@ -148,6 +143,7 @@
public void invokeDisposeMethod(Object instance)
{
+
List<Object> parameters = new LinkedList<Object>();
parameters.add(instance);
@@ -158,11 +154,11 @@
parameters.add(injectionObject);
}
- Object beanInstance = disposalMethod.isStatic() ? declaringBean :
getManager().getInstance(declaringBean);
+ Object beanInstance = disposalMethodInjectionPoint.isStatic() ? declaringBean :
getManager().getInstance(declaringBean);
try
{
- disposalMethod.invoke(beanInstance, parameters.toArray());
+ disposalMethodInjectionPoint.invoke(beanInstance, parameters.toArray());
}
catch (Exception e)
{
@@ -173,25 +169,25 @@
private void checkDisposalMethod()
{
- if (!disposalMethod.getParameters().get(0).isAnnotationPresent(Disposes.class))
+ if
(!disposalMethodInjectionPoint.getParameters().get(0).isAnnotationPresent(Disposes.class))
{
- throw new DefinitionException(disposalMethod.toString() + " doesn't
have @Dispose as first parameter");
+ throw new DefinitionException(disposalMethodInjectionPoint.toString() + "
doesn't have @Dispose as first parameter");
}
- if (disposalMethod.getAnnotatedParameters(Disposes.class).size() > 1)
+ if (disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).size() >
1)
{
- throw new DefinitionException(disposalMethod.toString() + " has more than
one @Dispose parameters");
+ throw new DefinitionException(disposalMethodInjectionPoint.toString() + "
has more than one @Dispose parameters");
}
- if (disposalMethod.getAnnotatedParameters(Observes.class).size() > 0)
+ if (disposalMethodInjectionPoint.getAnnotatedParameters(Observes.class).size() >
0)
{
- throw new DefinitionException("@Observes is not allowed on disposal method,
see " + disposalMethod.toString());
+ throw new DefinitionException("@Observes is not allowed on disposal method,
see " + disposalMethodInjectionPoint.toString());
}
- if (disposalMethod.getAnnotation(Initializer.class) != null)
+ if (disposalMethodInjectionPoint.getAnnotation(Initializer.class) != null)
{
- throw new DefinitionException("@Intitializer is not allowed on a disposal
method, see " + disposalMethod.toString());
+ throw new DefinitionException("@Intitializer is not allowed on a disposal
method, see " + disposalMethodInjectionPoint.toString());
}
- if (disposalMethod.getAnnotation(Produces.class) != null)
+ if (disposalMethodInjectionPoint.getAnnotation(Produces.class) != null)
{
- throw new DefinitionException("@Produces is not allowed on a disposal
method, see " + disposalMethod.toString());
+ throw new DefinitionException("@Produces is not allowed on a disposal
method, see " + disposalMethodInjectionPoint.toString());
}
if (declaringBean instanceof EnterpriseBean)
{
@@ -204,7 +200,7 @@
Class<?> clazz = (Class<?>) type;
try
{
- clazz.getDeclaredMethod(disposalMethod.getName(),
disposalMethod.getParameterTypesAsArray());
+ clazz.getDeclaredMethod(disposalMethodInjectionPoint.getName(),
disposalMethodInjectionPoint.getParameterTypesAsArray());
methodDeclaredOnTypes = true;
}
catch (NoSuchMethodException nsme)
@@ -221,6 +217,26 @@
}
@Override
+ protected void preSpecialize(BeanDeployerEnvironment environment)
+ {
+ if
(declaringBean.getAnnotatedItem().getSuperclass().getDeclaredMethod(getAnnotatedItem().getAnnotatedMethod())
== null)
+ {
+ throw new DefinitionException("Specialized disposal method does not
override a method on the direct superclass");
+ }
+ }
+
+ @Override
+ protected void specialize(BeanDeployerEnvironment environment)
+ {
+ AnnotatedMethod<?> superClassMethod =
declaringBean.getAnnotatedItem().getSuperclass().getMethod(getAnnotatedItem().getAnnotatedMethod());
+ if (environment.getProducerMethod(superClassMethod) == null)
+ {
+ throw new IllegalStateException(toString() + " does not specialize a
bean");
+ }
+ this.specializedBean = environment.getProducerMethod(superClassMethod);
+ }
+
+ @Override
public Class<T> getType()
{
return type;
@@ -251,12 +267,6 @@
}
@Override
- protected AnnotatedItem<T, Method> getAnnotatedItem()
- {
- return disposalMethod;
- }
-
- @Override
protected Class<? extends Annotation> getDefaultDeploymentType()
{
return declaringBean.getDeploymentType();
@@ -265,7 +275,7 @@
@Override
protected String getDefaultName()
{
- return disposalMethod.getPropertyName();
+ return disposalMethodInjectionPoint.getPropertyName();
}
@Override
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2009-04-05
20:16:46 UTC (rev 2305)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2009-04-05
22:01:20 UTC (rev 2306)
@@ -75,7 +75,7 @@
initType();
initTypes();
initBindings();
- this.id = createId("ProducerField-" + declaringBean.getType().getName() +
"-" + method.getSignature().toString());
+ this.id = createId("ProducerMethod-" + declaringBean.getType().getName()
+ "-" + method.getSignature().toString());
}
protected T produceInstance(CreationalContext<T> creationalContext)
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java 2009-04-05
20:16:46 UTC (rev 2305)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java 2009-04-05
22:01:20 UTC (rev 2306)
@@ -25,7 +25,8 @@
private static final AnnotatedItem<?, ?> OTHER_BEANS_ANNOTATED_ITEM =
ResolvableAnnotatedClass.of(BeanDeployerEnvironment.class, new Annotation[0]);
private final Map<AnnotatedClass<?>, AbstractClassBean<?>>
classBeanMap;
- private final Map<AnnotatedMethod<?>, ProducerMethodBean<?>>
methodBeanMap;
+ private final Map<AnnotatedMethod<?>, ProducerMethodBean<?>>
producerMethodBeanMap;
+ private final Map<AnnotatedMethod<?>, DisposalMethodBean<?>>
disposalMethodBeanMap;
private final Set<RIBean<?>> beans;
private final Set<ObserverImpl<?>> observers;
private final Set<DisposalMethodBean<?>> allDisposalBeans;
@@ -35,7 +36,8 @@
public BeanDeployerEnvironment(EjbDescriptorCache ejbDescriptors)
{
this.classBeanMap = new HashMap<AnnotatedClass<?>,
AbstractClassBean<?>>();
- this.methodBeanMap = new HashMap<AnnotatedMethod<?>,
ProducerMethodBean<?>>();
+ this.producerMethodBeanMap = new HashMap<AnnotatedMethod<?>,
ProducerMethodBean<?>>();
+ this.disposalMethodBeanMap = new HashMap<AnnotatedMethod<?>,
DisposalMethodBean<?>>();
this.allDisposalBeans = new HashSet<DisposalMethodBean<?>>();
this.resolvedDisposalBeans = new HashSet<DisposalMethodBean<?>>();
this.beans = new HashSet<RIBean<?>>();
@@ -45,13 +47,13 @@
public ProducerMethodBean<?> getProducerMethod(AnnotatedMethod<?> method)
{
- if (!methodBeanMap.containsKey(method))
+ if (!producerMethodBeanMap.containsKey(method))
{
return null;
}
else
{
- ProducerMethodBean<?> bean = methodBeanMap.get(method);
+ ProducerMethodBean<?> bean = producerMethodBeanMap.get(method);
bean.initialize(this);
return bean;
}
@@ -81,8 +83,11 @@
}
else if (value instanceof ProducerMethodBean)
{
- ProducerMethodBean<?> bean = (ProducerMethodBean<?>) value;
- methodBeanMap.put(bean.getAnnotatedItem(), bean);
+ ProducerMethodBean<?> bean = (ProducerMethodBean<?>) value;
+ producerMethodBeanMap.put(bean.getAnnotatedItem(), bean);
+ } else if (value instanceof DisposalMethodBean) {
+ DisposalMethodBean<?> bean = (DisposalMethodBean<?>) value;
+ disposalMethodBeanMap.put(bean.getAnnotatedItem(), bean);
}
beans.add(value);
}