Author: pete.muir(a)jboss.org
Date: 2009-03-23 14:27:55 -0400 (Mon, 23 Mar 2009)
New Revision: 2149
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/AbstractStandardBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
Log:
WBRI-116, WBRI-157
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-03-23
18:26:06 UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -36,6 +36,7 @@
import javax.inject.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.context.DependentInstancesStore;
import org.jboss.webbeans.conversation.ConversationImpl;
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
@@ -132,13 +133,13 @@
/**
* Initializes the bean and its metadata
*/
- public void initialize()
+ public void initialize(BeanDeployerEnvironment environment)
{
mergedStereotypes = new MergedStereotypes<T,
E>(getAnnotatedItem().getMetaAnnotations(Stereotype.class));
if (isSpecializing())
{
preSpecialize();
- specialize();
+ specialize(environment);
postSpecialize();
}
initDefaultBindings();
@@ -348,7 +349,7 @@
}
- protected void specialize()
+ protected void specialize(BeanDeployerEnvironment environment)
{
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-03-23
18:26:06 UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -34,6 +34,7 @@
import javax.inject.Production;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.injection.FieldInjectionPoint;
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.injection.ParameterInjectionPoint;
@@ -82,9 +83,9 @@
* Initializes the bean and its metadata
*/
@Override
- public void initialize()
+ public void initialize(BeanDeployerEnvironment environment)
{
- super.initialize();
+ super.initialize(environment);
checkScopeAllowed();
checkBeanImplementation();
initInitializerMethods();
@@ -288,7 +289,7 @@
* @return The annotated item
*/
@Override
- protected AnnotatedClass<T> getAnnotatedItem()
+ public AnnotatedClass<T> getAnnotatedItem()
{
return annotatedItem;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-03-23
18:26:06 UTC (rev 2148)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -37,6 +37,7 @@
import javax.inject.manager.InjectionPoint;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.context.CreationalContextImpl;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.DependentStorageRequest;
@@ -174,9 +175,9 @@
* Initializes the bean and its metadata
*/
@Override
- public void initialize()
+ public void initialize(BeanDeployerEnvironment environment)
{
- super.initialize();
+ super.initialize(environment);
checkProducerReturnType();
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-23
18:26:06 UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -38,6 +38,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.proxy.EnterpriseBeanInstance;
import org.jboss.webbeans.bean.proxy.EnterpriseBeanProxyMethodHandler;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.DependentStorageRequest;
import org.jboss.webbeans.ejb.InternalEjbDescriptor;
@@ -115,9 +116,9 @@
* Initializes the bean and its metadata
*/
@Override
- public void initialize()
+ public void initialize(BeanDeployerEnvironment environment)
{
- super.initialize();
+ super.initialize(environment);
initProxyClass();
initInjectionPoints();
checkEJBTypeAllowed();
@@ -195,10 +196,20 @@
}
@Override
- protected void specialize()
+ protected void specialize(BeanDeployerEnvironment environment)
{
- this.specializedBean = EnterpriseBean.of(getAnnotatedItem().getSuperclass(),
manager);
- this.specializedBean.initialize();
+ if
(!environment.getClassBeanMap().containsKey(getAnnotatedItem().getSuperclass()))
+ {
+ throw new IllegalStateException(toString() + " does not specialize a
bean");
+ }
+ else if (!(environment.getClassBeanMap().get(getAnnotatedItem().getSuperclass())
instanceof EnterpriseBean))
+ {
+ throw new IllegalStateException(toString() + " doesn't have a session
bean as a superclass " +
environment.getClassBeanMap().get(getAnnotatedItem().getSuperclass()));
+ }
+ else
+ {
+ this.specializedBean = (EnterpriseBean<?>)
environment.getClassBeanMap().get(getAnnotatedItem().getSuperclass());
+ }
}
/**
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-03-23
18:26:06 UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -28,6 +28,7 @@
import javax.inject.Disposes;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.injection.ParameterInjectionPoint;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -75,16 +76,24 @@
protected T produceInstance(CreationalContext<T> creationalContext)
{
- return method.invoke(getReceiver(creationalContext), manager, creationalContext,
CreationException.class);
+ Object receiver = getReceiver(creationalContext);
+ if (receiver != null)
+ {
+ return method.invokeOnInstance(receiver, manager, creationalContext,
CreationException.class);
+ }
+ else
+ {
+ return method.invoke(receiver, manager, creationalContext,
CreationException.class);
+ }
}
/**
* Initializes the bean and its metadata
*/
@Override
- public void initialize()
+ public void initialize(BeanDeployerEnvironment environment)
{
- super.initialize();
+ super.initialize(environment);
checkProducerMethod();
//initDisposalMethod();
initInjectionPoints();
@@ -139,7 +148,7 @@
* @return The annotated item
*/
@Override
- protected AnnotatedMethod<T> getAnnotatedItem()
+ public AnnotatedMethod<T> getAnnotatedItem()
{
return method;
}
@@ -215,12 +224,14 @@
}
@Override
- protected void specialize()
+ protected void specialize(BeanDeployerEnvironment environment)
{
- SimpleBean<?> superClassBean =
SimpleBean.of(declaringBean.getAnnotatedItem().getSuperclass(), manager);
- superClassBean.initialize();
- this.specializedBean =
ProducerMethodBean.of(declaringBean.getAnnotatedItem().getSuperclass().getMethod(getAnnotatedItem().getAnnotatedMethod()),
superClassBean, manager);
- this.specializedBean.initialize();
+ AnnotatedMethod<?> superClassMethod =
declaringBean.getAnnotatedItem().getSuperclass().getMethod(getAnnotatedItem().getAnnotatedMethod());
+ if (!environment.getMethodBeanMap().containsKey(superClassMethod))
+ {
+ throw new IllegalStateException(toString() + " does not specialize a
bean");
+ }
+ this.specializedBean = environment.getMethodBeanMap().get(superClassMethod);
}
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java 2009-03-23 18:26:06
UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java 2009-03-23 18:27:55
UTC (rev 2149)
@@ -23,6 +23,7 @@
import javax.inject.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
/**
@@ -55,7 +56,7 @@
public abstract Class<T> getType();
- public abstract void initialize();
+ public abstract void initialize(BeanDeployerEnvironment environment);
public abstract boolean isSpecializing();
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-23
18:26:06 UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -28,6 +28,7 @@
import javax.inject.Initializer;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.context.DependentContext;
import org.jboss.webbeans.context.DependentStorageRequest;
import org.jboss.webbeans.ejb.EJBApiAbstraction;
@@ -283,9 +284,9 @@
* Initializes the bean and its metadata
*/
@Override
- public void initialize()
+ public void initialize(BeanDeployerEnvironment environment)
{
- super.initialize();
+ super.initialize(environment);
initConstructor();
checkType();
initInjectionPoints();
@@ -359,10 +360,20 @@
}
@Override
- protected void specialize()
+ protected void specialize(BeanDeployerEnvironment environment)
{
- this.specializedBean = SimpleBean.of(getAnnotatedItem().getSuperclass(), manager);
- this.specializedBean.initialize();
+ if
(!environment.getClassBeanMap().containsKey(getAnnotatedItem().getSuperclass()))
+ {
+ throw new IllegalStateException(toString() + " does not specialize a
bean");
+ }
+ else if (!(environment.getClassBeanMap().get(getAnnotatedItem().getSuperclass())
instanceof SimpleBean))
+ {
+ throw new IllegalStateException(toString() + " doesn't have a simple
bean as a superclass " +
environment.getClassBeanMap().get(getAnnotatedItem().getSuperclass()));
+ }
+ else
+ {
+ this.specializedBean = (SimpleBean<?>)
environment.getClassBeanMap().get(getAnnotatedItem().getSuperclass());
+ }
}
/**
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/AbstractStandardBean.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/AbstractStandardBean.java 2009-03-23
18:26:06 UTC (rev 2148)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/AbstractStandardBean.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -11,6 +11,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
import org.jboss.webbeans.injection.AnnotatedInjectionPoint;
import org.jboss.webbeans.literal.CurrentLiteral;
@@ -23,7 +24,7 @@
}
@Override
- public void initialize()
+ public void initialize(BeanDeployerEnvironment environment)
{
// No-op
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-23
18:26:06 UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -26,7 +26,6 @@
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedField;
-import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.WrappedAnnotatedField;
import org.jboss.webbeans.introspector.WrappedAnnotatedMethod;
@@ -53,15 +52,9 @@
this.classes = new HashSet<AnnotatedClass<?>>();
}
- public <T> BeanDeployer addBean(AnnotatedItem<T, ?> item, RIBean<T>
bean)
- {
- this.beanDeployerEnvironment.addBean(item, bean);
- return this;
- }
-
public <T> BeanDeployer addBean(RIBean<T> bean)
{
- this.beanDeployerEnvironment.addBean(null, bean);
+ this.beanDeployerEnvironment.addBean(bean);
return this;
}
@@ -105,7 +98,7 @@
beans.addAll(beanDeployerEnvironment.getBeans());
for (RIBean<?> bean : beans)
{
- bean.initialize();
+ bean.initialize(beanDeployerEnvironment);
log.info("Bean: " + bean);
}
manager.setBeans(beans);
@@ -135,7 +128,7 @@
protected <T> void createBean(AbstractClassBean<T> bean, final
AnnotatedClass<T> annotatedClass)
{
- addBean(annotatedClass, bean);
+ addBean(bean);
manager.getResolver().addInjectionPoints(bean.getInjectionPoints());
@@ -163,7 +156,7 @@
private <T> void createProducerMethod(AbstractClassBean<?> declaringBean,
AnnotatedMethod<T> annotatedMethod)
{
ProducerMethodBean<T> bean = ProducerMethodBean.of(annotatedMethod,
declaringBean, manager);
- addBean(annotatedMethod, bean);
+ addBean(bean);
manager.getResolver().addInjectionPoints(bean.getInjectionPoints());
}
@@ -188,7 +181,7 @@
private <T> void createProducerField(AbstractClassBean<?> declaringBean,
AnnotatedField<T> field)
{
ProducerFieldBean<T> bean = ProducerFieldBean.of(field, declaringBean,
manager);
- addBean(field, bean);
+ addBean(bean);
}
private void createProducerFields(AbstractClassBean<?> declaringBean,
AnnotatedClass<?> annotatedClass)
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-03-23
18:26:06 UTC (rev 2148)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployerEnvironment.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -1,57 +1,68 @@
package org.jboss.webbeans.bootstrap;
import java.lang.annotation.Annotation;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.Map.Entry;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.NewBean;
+import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.RIBean;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.injection.resolution.ResolvableAnnotatedClass;
+import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedItem;
+import org.jboss.webbeans.introspector.AnnotatedMethod;
public class BeanDeployerEnvironment
{
private static final AnnotatedItem<?, ?> OTHER_BEANS_ANNOTATED_ITEM =
ResolvableAnnotatedClass.of(BeanDeployerEnvironment.class, new Annotation[0]);
- private final Map<AnnotatedItem<?, ?>, Set<RIBean<?>>>
beanMap;
+ private final Map<AnnotatedClass<?>, AbstractClassBean<?>>
classBeanMap;
+ private final Map<AnnotatedMethod<?>, ProducerMethodBean<?>>
methodBeanMap;
+ private final Set<RIBean<?>> beans;
private final Set<ObserverImpl<?>> observers;
public BeanDeployerEnvironment()
{
- this.beanMap = new HashMap<AnnotatedItem<?,?>,
Set<RIBean<?>>>();
+ this.classBeanMap = new HashMap<AnnotatedClass<?>,
AbstractClassBean<?>>();
+ this.methodBeanMap = new HashMap<AnnotatedMethod<?>,
ProducerMethodBean<?>>();
+ this.beans = new HashSet<RIBean<?>>();
this.observers = new HashSet<ObserverImpl<?>>();
}
- public Map<AnnotatedItem<?, ?>, Set<RIBean<?>>> getBeanMap()
+ public Map<AnnotatedClass<?>, AbstractClassBean<?>>
getClassBeanMap()
{
- return beanMap;
+ return Collections.unmodifiableMap(classBeanMap);
}
- public void addBean(AnnotatedItem<?, ?> key, RIBean<?> value)
+ public Map<AnnotatedMethod<?>, ProducerMethodBean<?>>
getMethodBeanMap()
{
- if (key == null)
+ return Collections.unmodifiableMap(methodBeanMap);
+ }
+
+ public void addBean(RIBean<?> value)
+ {
+ if (value instanceof AbstractClassBean && !(value instanceof NewBean))
{
- key = OTHER_BEANS_ANNOTATED_ITEM;
+ AbstractClassBean<?> bean = (AbstractClassBean<?>) value;
+ classBeanMap.put(bean.getAnnotatedItem(), bean);
}
- if (!beanMap.containsKey(key))
+ else if (value instanceof ProducerMethodBean)
{
- beanMap.put(key, new HashSet<RIBean<?>>());
+ ProducerMethodBean<?> bean = (ProducerMethodBean<?>) value;
+ methodBeanMap.put(bean.getAnnotatedItem(), bean);
}
- beanMap.get(key).add(value);
+ beans.add(value);
}
public Set<RIBean<?>> getBeans()
{
- Set<RIBean<?>> beans = new HashSet<RIBean<?>>();
- for (Entry<AnnotatedItem<?, ?>, Set<RIBean<?>>> entry :
beanMap.entrySet())
- {
- beans.addAll(entry.getValue());
- }
- return beans;
+ return Collections.unmodifiableSet(beans);
}
public Set<ObserverImpl<?>> getObservers()
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java 2009-03-23
18:26:06 UTC (rev 2148)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -36,6 +36,14 @@
// Place o1 before it's subclass o2
return -1;
}
+ else if (!(o1 instanceof NewBean) && o2 instanceof NewBean)
+ {
+ return -1;
+ }
+ else if (o1 instanceof NewBean && !(o2 instanceof NewBean))
+ {
+ return 1;
+ }
}
if (o1 instanceof AbstractProducerBean && o2 instanceof
AbstractProducerBean)
@@ -65,23 +73,16 @@
return o1.getId().compareTo(o2.getId());
}
- if (o1.getType().getName().startsWith("org.jboss.webbeans") &&
!o2.getType().getName().startsWith("org.jboss.webbeans"))
- {
- return -1;
- }
- else if (!o1.getType().getName().startsWith("org.jboss.webbeans")
&& o2.getType().getName().startsWith("org.jboss.webbeans"))
- {
- return 1;
- }
+// if (o1.getType().getName().startsWith("org.jboss.webbeans") &&
!o2.getType().getName().startsWith("org.jboss.webbeans"))
+// {
+// return -1;
+// }
+// else if (!o1.getType().getName().startsWith("org.jboss.webbeans")
&& o2.getType().getName().startsWith("org.jboss.webbeans"))
+// {
+// return 1;
+// }
- if (!(o1 instanceof NewBean) && o2 instanceof NewBean)
- {
- return -1;
- }
- else if (o1 instanceof NewBean && !(o2 instanceof NewBean))
- {
- return 1;
- }
+
return o1.getId().compareTo(o2.getId());
}
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2009-03-23
18:26:06 UTC (rev 2148)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -179,8 +179,7 @@
public T invokeOnInstance(Object instance, Object...parameters) throws
IllegalArgumentException, SecurityException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException
{
- Method method = instance.getClass().getMethod(getName(),
getParameterTypesAsArray());
- method.setAccessible(true);
+ Method method = Reflections.lookupMethod(getName(), getParameterTypesAsArray(),
instance);
@SuppressWarnings("unchecked")
T result = (T) method.invoke(instance, parameters);
return result;
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java 2009-03-23
18:26:06 UTC (rev 2148)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Reflections.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -28,6 +28,7 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -391,15 +392,52 @@
*
* @param method The method to look for
* @param instance The instance to start from
- * @return The method found, or an NoSuchMethodException if it is not found
+ * @return The method found
+ * @throws IllegalArgumentException if the method is not found
*/
public static Method lookupMethod(Method method, Object instance)
{
- for (Class<? extends Object> clazz = instance.getClass(); clazz != null;
clazz = clazz.getSuperclass())
+ try
{
+ return lookupMethod(method.getName(), method.getParameterTypes(), instance);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ /**
+ * Looks up a method in the type hierarchy of an instance
+ *
+ * @param method The method to look for
+ * @param instance The instance to start from
+ * @return the method
+ * @throws NoSuchMethodException if the method is not found
+ */
+ public static Method lookupMethod(String methodName, Class<?>[] parameterTypes,
Object instance) throws NoSuchMethodException
+ {
+ return lookupMethod(methodName, parameterTypes, instance.getClass());
+ }
+
+ private static Method lookupMethod(String methodName, Class<?>[] parameterTypes,
Class<?> c) throws NoSuchMethodException
+ {
+ for (Class<? extends Object> clazz = c; clazz != null; clazz =
clazz.getSuperclass())
+ {
+ for (Class<?> intf : clazz.getInterfaces())
+ {
+ try
+ {
+ return lookupMethod(methodName, parameterTypes, intf);
+ }
+ catch (NoSuchMethodException e)
+ {
+ // Expected
+ }
+ }
try
{
- Method targetMethod = clazz.getDeclaredMethod(method.getName(),
method.getParameterTypes());
+ Method targetMethod = clazz.getDeclaredMethod(methodName, parameterTypes);
if (!targetMethod.isAccessible())
{
targetMethod.setAccessible(true);
@@ -411,8 +449,10 @@
// Expected, nothing to see here.
}
}
- throw new IllegalArgumentException("Method " + method.getName() + "
not implemented by instance");
+ throw new NoSuchMethodException("Method " + methodName +
Arrays.asList(parameterTypes).toString().replace("[",
"(").replace("]", ")") + " not implemented by instance
" + c.getName());
}
+
+
/**
* Indicates if an instance is a Javassist proxy
Modified:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23
18:26:06 UTC (rev 2148)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-23
18:27:55 UTC (rev 2149)
@@ -128,7 +128,7 @@
}
}
- @Test(groups="bootstrap")
+ //@Test(groups="bootstrap")
public void testOrgJbossWebbeansBeforeUsers()
{
BeanDeployer beanDeployer = new BeanDeployer(manager);
@@ -189,15 +189,15 @@
int i = 0;
for (RIBean<?> bean : beans)
{
- if (bean.getType().equals(Spider.class))
+ if (bean.getType().equals(Spider.class) &&
!bean.getBindings().contains(new NewLiteral()))
{
indexOfSpider = i;
}
- if (bean.getType().equals(Tarantula.class))
+ if (bean.getType().equals(Tarantula.class) &&
!bean.getBindings().contains(new NewLiteral()))
{
indexOfTarantula = i;
}
- if (bean.getType().equals(DefangedTarantula.class))
+ if (bean.getType().equals(DefangedTarantula.class) &&
!bean.getBindings().contains(new NewLiteral()))
{
indexOfDefangedTarantula = i;
}