Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@3822 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Sep 30, 2009
1 parent d53c0c2 commit d30ec9c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +89,6 @@ protected void initTypes()
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;
Expand Down Expand Up @@ -119,29 +117,11 @@ protected void initType()
}
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
*/
Expand Down
Expand Up @@ -164,7 +164,10 @@ else if (decoratedType instanceof ParameterizedType)
{
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()))
{
Expand Down
Expand Up @@ -92,7 +92,6 @@ protected void initBindings()
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;
Expand Down
4 changes: 1 addition & 3 deletions impl/src/main/java/org/jboss/webbeans/bean/SessionBean.java
Expand Up @@ -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;

Expand Down Expand Up @@ -122,8 +121,7 @@ public void initialize(BeanDeployerEnvironment environment)
@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())
{
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -108,7 +109,7 @@ public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[]
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)
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -115,7 +116,7 @@ public Object invoke(Object self, Method method, Method proceed, Object[] args)
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;
}

Expand Down
20 changes: 20 additions & 0 deletions impl/src/main/java/org/jboss/webbeans/util/Beans.java
Expand Up @@ -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;
Expand Down Expand Up @@ -523,6 +524,25 @@ public static <T> void injectEEFields(T beanInstance, BeanManagerImpl manager, I
}


/**
* 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
*
Expand Down

0 comments on commit d30ec9c

Please sign in to comment.