Author: nickarls
Date: 2008-10-29 06:30:21 -0400 (Wed, 29 Oct 2008)
New Revision: 205
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java
Log:
ProxyFactory
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-29
07:34:07 UTC (rev 204)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-29
10:30:21 UTC (rev 205)
@@ -35,6 +35,7 @@
import org.jboss.webbeans.injectable.Injectable;
import org.jboss.webbeans.injectable.ResolverInjectable;
import org.jboss.webbeans.util.ClientProxy;
+import org.jboss.webbeans.util.ClientProxyFactory;
import org.jboss.webbeans.util.MapWrapper;
import org.jboss.webbeans.util.Reflections;
@@ -74,6 +75,7 @@
private ContextMap contextMap;
private DependentContext dependentContext;
private ProxyPool proxyPool;
+ private ClientProxyFactory clientProxyFactory;
private Set<Bean<?>> beans;
@@ -87,6 +89,7 @@
this.eventBus = new EventBus();
this.resolutionManager = new ResolutionManager(this);
this.proxyPool = new ProxyPool();
+ clientProxyFactory = new ClientProxyFactory(this);
}
protected void initEnabledDeploymentTypes(List<Class<? extends
Annotation>> enabledDeploymentTypes)
@@ -390,8 +393,9 @@
{
try
{
- clientProxy = ClientProxy.createProxy(new ProxyData(bean, this));
+ clientProxy = clientProxyFactory.createProxyClient(bean);
} catch (Exception e) {
+ // TODO: What to *really* do here?
throw new UnproxyableDependencyException("Could not create proxy",
e);
}
proxyPool.put(bean, clientProxy);
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java 2008-10-29
07:34:07 UTC (rev 204)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java 2008-10-29
10:30:21 UTC (rev 205)
@@ -1,19 +1,10 @@
package org.jboss.webbeans.util;
-import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import javassist.util.proxy.MethodHandler;
-import javassist.util.proxy.ProxyFactory;
-import javassist.util.proxy.ProxyObject;
-import javax.webbeans.manager.Bean;
-import javax.webbeans.manager.Context;
-import javax.webbeans.manager.Manager;
-import org.jboss.webbeans.ProxyData;
-
-
public class ClientProxy
{
@@ -43,27 +34,4 @@
}
}
- private static MethodHandler methodHandler = new MethodHandler()
- {
- public Object invoke(Object self, Method m, Method proceed, Object[] args) throws
Throwable
- {
- ProxyData proxyData = (ProxyData)self;
- Manager manager = proxyData.getManager();
- Class<? extends Annotation> beanScope =
proxyData.getBean().getScopeType();
- Context context = manager.getContext(beanScope);
- Object instance = context.get(proxyData.getBean(), true);
- return proceed.invoke(instance, args);
- }
- };
-
- public static Bean<?> createProxy(ProxyData proxyData) throws
InstantiationException, IllegalAccessException
- {
- ProxyFactory proxyFactory = new ProxyFactory();
- proxyFactory.setSuperclass(proxyData.getClass());
- Class<?> proxyClass = proxyFactory.createClass();
- Bean<?> proxy = (Bean<?>) proxyClass.newInstance();
- ((ProxyObject)proxy).setHandler(methodHandler);
- return proxy;
- }
-
}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-10-29
10:30:21 UTC (rev 205)
@@ -0,0 +1,52 @@
+package org.jboss.webbeans.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+
+import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Context;
+
+import org.jboss.webbeans.ManagerImpl;
+
+public class ClientProxyFactory
+{
+ private ManagerImpl manager;
+
+ public ClientProxyFactory(ManagerImpl manager) {
+ this.manager = manager;
+ }
+
+ public class ProxyMethodHandler implements MethodHandler {
+ private ManagerImpl manager;
+
+ public ProxyMethodHandler(ManagerImpl manager) {
+ this.manager = manager;
+ }
+
+ @Override
+ public Object invoke(Object self, Method method, Method proceed, Object[] args)
throws Throwable
+ {
+ Bean<?> bean = (Bean<?>)self;
+ Class<? extends Annotation> beanScope = bean.getScopeType();
+ Context context = manager.getContext(beanScope);
+ Object instance = context.get(bean, true);
+ return proceed.invoke(instance, args);
+ }
+
+ }
+
+ public Bean<?> createProxyClient(Bean<?> bean) throws
InstantiationException, IllegalAccessException {
+ ProxyFactory factory = new ProxyFactory();
+ factory.setSuperclass(bean.getClass());
+ Class<?> proxyClass = factory.createClass();
+ Object proxy = proxyClass.newInstance();
+ ProxyMethodHandler proxyMethodHandler = new ProxyMethodHandler(manager);
+ ((ProxyObject)proxy).setHandler(proxyMethodHandler);
+ return (Bean<?>) proxy;
+ }
+
+}
Show replies by date