Author: pete.muir(a)jboss.org
Date: 2009-09-30 09:38:57 -0400 (Wed, 30 Sep 2009)
New Revision: 3822
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
Log:
tidy up
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-09-30
13:21:36 UTC (rev 3821)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java 2009-09-30
13:38:57 UTC (rev 3822)
@@ -21,7 +21,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
@@ -90,7 +89,6 @@
if (getType().isArray() || getType().isPrimitive())
{
Set<Type> types = new HashSet<Type>();
- types = new HashSet<Type>();
types.add(getType());
types.add(Object.class);
super.types = types;
@@ -119,30 +117,12 @@
}
catch (ClassCastException e)
{
- throw new RuntimeException(" Cannot cast producer type " +
getAnnotatedItem().getJavaClass() + " to bean type " + (getDeclaredBeanType() ==
null ? " unknown " : getDeclaredBeanType()), e);
+ Type type = Beans.getDeclaredBeanType(getClass());
+ throw new RuntimeException(" Cannot cast producer type " +
getAnnotatedItem().getJavaClass() + " to bean type " + (type == null ? "
unknown " : type), e);
}
}
/**
- * Gets the declared bean type
- *
- * @return The bean type
- */
- protected Type getDeclaredBeanType()
- {
- Type type = getClass();
- if (type instanceof ParameterizedType)
- {
- ParameterizedType parameterizedType = (ParameterizedType) type;
- if (parameterizedType.getActualTypeArguments().length == 1)
- {
- return parameterizedType.getActualTypeArguments()[0];
- }
- }
- return null;
- }
-
- /**
* Validates the producer method
*/
protected void checkProducerReturnType()
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java 2009-09-30
13:21:36 UTC (rev 3821)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DecoratorImpl.java 2009-09-30
13:38:57 UTC (rev 3822)
@@ -164,7 +164,10 @@
{
throw new DefinitionException("The decorated type is parameterized,
but the delegate type isn't. Delegate type " + delegateType + "." +
this);
}
- if (!Arrays.equals(delegateInjectionPoint.getActualTypeArguments(),
parameterizedType.getActualTypeArguments()));
+ if (!Arrays.equals(delegateInjectionPoint.getActualTypeArguments(),
parameterizedType.getActualTypeArguments()))
+ {
+ throw new DefinitionException("The delegate type must have exactly
the same type parameters as the decorated type. Decorated type " + decoratedType +
"." + this );
+ }
Type rawType = ((ParameterizedType) decoratedType).getRawType();
if (rawType instanceof Class && !((Class<?>)
rawType).isAssignableFrom(delegateInjectionPoint.getJavaClass()))
{
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java 2009-09-30
13:21:36 UTC (rev 3821)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/DisposalMethod.java 2009-09-30
13:38:57 UTC (rev 3822)
@@ -92,7 +92,6 @@
protected void initTypes()
{
Set<Type> types = new HashSet<Type>();
- types = new HashSet<Type>();
types.addAll(disposalMethodInjectionPoint.getAnnotatedParameters(Disposes.class).get(0).getTypeClosure());
types.add(Object.class);
super.types = types;
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java 2009-09-30
13:21:36 UTC (rev 3821)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java 2009-09-30
13:38:57 UTC (rev 3822)
@@ -22,7 +22,6 @@
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -122,8 +121,7 @@
@Override
protected void initTypes()
{
- Set<Type> types = new HashSet<Type>();
- types = new LinkedHashSet<Type>();
+ Set<Type> types = new LinkedHashSet<Type>();
types.add(Object.class);
for (BusinessInterfaceDescriptor<?> businessInterfaceDescriptor :
ejbDescriptor.getLocalBusinessInterfaces())
{
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java 2009-09-30
13:21:36 UTC (rev 3821)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/ClientProxyMethodHandler.java 2009-09-30
13:38:57 UTC (rev 3822)
@@ -19,6 +19,7 @@
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
import javassist.util.proxy.MethodHandler;
@@ -108,7 +109,7 @@
try
{
Object returnValue = Reflections.lookupMethod(proxiedMethod,
proxiedInstance).invoke(proxiedInstance, args);
- log.trace("Executed method " + proxiedMethod + " on " +
proxiedInstance + " with parameters " + args + " and got return value
" + returnValue);
+ log.trace("Executed method " + proxiedMethod + " on " +
proxiedInstance + " with parameters " + Arrays.toString(args) + " and got
return value " + returnValue);
return returnValue;
}
catch (InvocationTargetException e)
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-09-30
13:21:36 UTC (rev 3821)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/proxy/EnterpriseBeanProxyMethodHandler.java 2009-09-30
13:38:57 UTC (rev 3822)
@@ -18,6 +18,7 @@
import java.io.Serializable;
import java.lang.reflect.Method;
+import java.util.Arrays;
import java.util.Collection;
import javassist.util.proxy.MethodHandler;
@@ -115,7 +116,7 @@
Object proxiedInstance = reference.getBusinessObject(businessInterface);
Method proxiedMethod = Reflections.lookupMethod(method, proxiedInstance);
Object returnValue = Reflections.invokeAndWrap(proxiedMethod, proxiedInstance,
args);
- log.trace("Executed " + method + " on " + proxiedInstance +
" with parameters " + args + " and got return value " + returnValue);
+ log.trace("Executed " + method + " on " + proxiedInstance +
" with parameters " + Arrays.toString(args) + " and got return value "
+ returnValue);
return returnValue;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java 2009-09-30 13:21:36 UTC
(rev 3821)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/Beans.java 2009-09-30 13:38:57 UTC
(rev 3822)
@@ -17,6 +17,7 @@
package org.jboss.webbeans.util;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -524,6 +525,25 @@
/**
+ * Gets the declared bean type
+ *
+ * @return The bean type
+ */
+ public static Type getDeclaredBeanType(Class<? extends Bean> clazz)
+ {
+ Type[] actualTypeArguments = Reflections.getActualTypeArguments(clazz);
+ if (actualTypeArguments.length == 1)
+ {
+ return actualTypeArguments[0];
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+
+ /**
* Injects bound fields
*
* @param instance The instance to inject into
Show replies by date