Skip to content

Commit

Permalink
WBRI-265
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@2764 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Jun 4, 2009
1 parent e6b7e4c commit 14cc591
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
Expand Up @@ -352,7 +352,7 @@ public InternalEjbDescriptor<T> getEjbDescriptor()
return ejbDescriptor;
}

public boolean canCallRemoveMethods()
public boolean isClientCanCallRemoveMethods()
{
return getEjbDescriptor().isStateful() && isDependent();
}
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.jboss.webbeans.bean.proxy;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javassist.util.proxy.MethodHandler;
Expand Down Expand Up @@ -93,9 +94,16 @@ public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[]
bean = manager.getBeans().get(beanIndex);
}
Object proxiedInstance = getProxiedInstance(bean);
Object returnValue = Reflections.lookupMethod(proxiedMethod, proxiedInstance).invoke(proxiedInstance, args);
log.trace("Executed method " + proxiedMethod + " on " + proxiedInstance + " with parameters " + args + " and got return value " + returnValue);
return returnValue;
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);
return returnValue;
}
catch (InvocationTargetException e)
{
throw e.getCause();
}
}

private <T> T getProxiedInstance(Bean<T> bean)
Expand Down
Expand Up @@ -17,11 +17,14 @@
package org.jboss.webbeans.bean.proxy;

import java.lang.reflect.Method;
import java.util.Collection;

import javassist.util.proxy.MethodHandler;

import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.ejb.api.SessionObjectReference;
import org.jboss.webbeans.introspector.MethodSignature;
import org.jboss.webbeans.introspector.jlr.MethodSignatureImpl;
import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.util.Reflections;
Expand Down Expand Up @@ -56,9 +59,12 @@ private static void setEnterpriseBean(EnterpriseBean<?> bean)
enterpriseBean.set(bean);
}

final SessionObjectReference reference;
final Class<?> objectInterface;
boolean destroyed;
private final SessionObjectReference reference;
private final Class<?> objectInterface;
private final Collection<MethodSignature> removeMethodSignatures;
private final boolean clientCanCallRemoveMethods;

private boolean destroyed;

/**
* Constructor
Expand All @@ -71,6 +77,8 @@ public EnterpriseBeanProxyMethodHandler(EnterpriseBean<?> bean)
{
this.destroyed = false;
this.objectInterface = bean.getEjbDescriptor().getObjectInterface();
this.removeMethodSignatures = bean.getEjbDescriptor().getRemoveMethodSignatures();
this.clientCanCallRemoveMethods = bean.isClientCanCallRemoveMethods();
try
{
setEnterpriseBean(bean);
Expand Down Expand Up @@ -131,6 +139,16 @@ else if ("setDestroyed".equals(method.getName()))
return null;
}

if (!clientCanCallRemoveMethods)
{
// TODO we can certainly optimize this search algorithm!
MethodSignature methodSignature = new MethodSignatureImpl(method);
if (removeMethodSignatures.contains(methodSignature))
{
throw new UnsupportedOperationException("Cannot call EJB remove method directly on non-dependent scoped bean " + method );
}
}

Class<?> businessInterface = method.getDeclaringClass();
if (businessInterface.equals(Object.class))
{
Expand Down
Expand Up @@ -16,10 +16,15 @@
*/
package org.jboss.webbeans.ejb;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.jboss.webbeans.ejb.spi.BusinessInterfaceDescriptor;
import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.introspector.MethodSignature;
import org.jboss.webbeans.introspector.jlr.MethodSignatureImpl;

/**
* More powerful version of {@link EjbDescriptor} that exposes Maps for some
Expand All @@ -34,6 +39,7 @@ public class InternalEjbDescriptor<T> extends ForwardingEjbDescriptor<T> impleme

private final Class<?> objectInterface;
private final EjbDescriptor<T> delegate;
private final Collection<MethodSignature> removeMethodSignatures;

public InternalEjbDescriptor(EjbDescriptor<T> ejbDescriptor)
{
Expand All @@ -47,6 +53,11 @@ public InternalEjbDescriptor(EjbDescriptor<T> ejbDescriptor)
{
this.objectInterface = null;
}
removeMethodSignatures = new ArrayList<MethodSignature>();
for (Method method : delegate.getRemoveMethods())
{
removeMethodSignatures.add(new MethodSignatureImpl(method));
}
}

@Override
Expand All @@ -60,4 +71,9 @@ public Class<?> getObjectInterface()
return objectInterface;
}

public Collection<MethodSignature> getRemoveMethodSignatures()
{
return removeMethodSignatures;
}

}
Expand Up @@ -16,7 +16,9 @@
*/
package org.jboss.webbeans.introspector;

public interface ConstructorSignature
import java.io.Serializable;

public interface ConstructorSignature extends Serializable
{

public String[] getParameterTypes();
Expand Down
Expand Up @@ -16,7 +16,9 @@
*/
package org.jboss.webbeans.introspector;

public interface MethodSignature
import java.io.Serializable;

public interface MethodSignature extends Serializable
{

public String getMethodName();
Expand Down
Expand Up @@ -16,6 +16,7 @@
*/
package org.jboss.webbeans.introspector.jlr;

import java.lang.reflect.Method;
import java.util.Arrays;

import org.jboss.webbeans.introspector.AnnotatedMethod;
Expand All @@ -24,6 +25,8 @@
public class MethodSignatureImpl implements MethodSignature
{

private static final long serialVersionUID = 870948075030895317L;

private final String methodName;
private final String[] parameterTypes;

Expand All @@ -35,6 +38,16 @@ public MethodSignatureImpl(AnnotatedMethod<?> method)
{
parameterTypes[i] = method.getParameters().get(i).getRawType().getName();
}
}

public MethodSignatureImpl(Method method)
{
this.methodName = method.getName();
this.parameterTypes = new String[method.getParameterTypes().length];
for (int i = 0; i < method.getParameterTypes().length; i++)
{
parameterTypes[i] = method.getParameterTypes()[i].getName();
}

}

Expand Down

0 comments on commit 14cc591

Please sign in to comment.