Skip to content

Commit

Permalink
Minor. Proxied type detection attempt
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@209 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Oct 30, 2008
1 parent b9d9a32 commit 9b9fc31
Showing 1 changed file with 13 additions and 2 deletions.
@@ -1,7 +1,7 @@
package org.jboss.webbeans.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Set;

import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
Expand Down Expand Up @@ -45,11 +45,22 @@ public Object invoke(Object self, Method method, Method proceed, Object[] args)
public <T> T createClientProxy(Bean<T> bean) throws InstantiationException, IllegalAccessException {
ProxyFactory proxyFactory = new ProxyFactory();
// TODO How to get the type T from a bean?
proxyFactory.setSuperclass(bean.getTypes().toArray()[0].getClass());
Class<?>[] beanTypes = bean.getTypes().toArray(new Class<?>[0]);
proxyFactory.setSuperclass(beanTypes[0]);
T clientProxy = (T) proxyFactory.createClass().newInstance();
ProxyMethodHandler proxyMethodHandler = new ProxyMethodHandler(bean, manager);
((ProxyObject)clientProxy).setHandler(proxyMethodHandler);
return clientProxy;
}

private void run() throws InstantiationException, IllegalAccessException {
Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
Tuna proxy = createClientProxy(tunaBean);
}

public static void main(String[] params) throws InstantiationException, IllegalAccessException {
ClientProxyFactory f = new ClientProxyFactory(new ManagerImpl());
f.run();
}

}

0 comments on commit 9b9fc31

Please sign in to comment.