Author: nickarls
Date: 2008-11-02 17:41:01 -0500 (Sun, 02 Nov 2008)
New Revision: 218
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyPool.java
Removed:
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/test/java/org/jboss/webbeans/test/ClientProxyTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tuna.java
Log:
Moved ClientProxyCache and ClientProxyFactory to single ProxyPool class
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-11-02
20:33:56 UTC (rev 217)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-02
22:41:01 UTC (rev 218)
@@ -36,12 +36,13 @@
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.ProxyPool;
import org.jboss.webbeans.util.Reflections;
public class ManagerImpl implements Manager
{
+
private class ContextMap extends MapWrapper<Class<? extends Annotation>,
List<Context>>
{
public ContextMap()
@@ -60,28 +61,16 @@
}
}
- private class ClientProxyCache extends MapWrapper<Bean<?>, Object>
- {
- public ClientProxyCache()
- {
- super(new HashMap<Bean<?>, Object>());
- }
-
- public <T> T get(Bean<T> key)
- {
- return (T) super.get(key);
- }
- }
-
private List<Class<? extends Annotation>> enabledDeploymentTypes;
private ModelManager modelManager;
private EjbManager ejbLookupManager;
private EventBus eventBus;
private ResolutionManager resolutionManager;
private ContextMap contextMap;
- private ClientProxyCache clientProxyCache;
- private ClientProxyFactory clientProxyFactory;
+ private ProxyPool proxyPool;
private List<Bean<?>> beans;
+ private Set<Decorator> decorators;
+ private Set<Interceptor> interceptors;
public ManagerImpl()
{
@@ -92,8 +81,9 @@
this.beans = new ArrayList<Bean<?>>();
this.eventBus = new EventBus();
this.resolutionManager = new ResolutionManager(this);
- this.clientProxyCache = new ClientProxyCache();
- clientProxyFactory = new ClientProxyFactory(this);
+ this.proxyPool = new ProxyPool(this);
+ this.decorators = new HashSet<Decorator>();
+ this.interceptors = new HashSet<Interceptor>();
}
protected void initEnabledDeploymentTypes(List<Class<? extends
Annotation>> enabledDeploymentTypes)
@@ -187,6 +177,7 @@
private <T> Set<Bean<T>> resolveByType(Injectable<T, ?>
injectable)
{
Set<Bean<T>> beans = getResolutionManager().get(injectable);
+
if (beans == null)
{
return new HashSet<Bean<T>>();
@@ -218,26 +209,26 @@
public Manager addContext(Context context)
{
- List<Context> sameScopeTypeContexts =
contextMap.get(context.getScopeType());
- if (sameScopeTypeContexts == null)
+ List<Context> contexts = contextMap.get(context.getScopeType());
+ if (contexts == null)
{
- sameScopeTypeContexts = new ArrayList<Context>();
- contextMap.put(context.getScopeType(), sameScopeTypeContexts);
+ contexts = new ArrayList<Context>();
+ contextMap.put(context.getScopeType(), contexts);
}
- sameScopeTypeContexts.add(context);
+ contexts.add(context);
return this;
}
public Manager addDecorator(Decorator decorator)
{
- // TODO Auto-generated method stub
- return null;
+ decorators.add(decorator);
+ return this;
}
public Manager addInterceptor(Interceptor interceptor)
{
- // TODO Auto-generated method stub
- return null;
+ interceptors.add(interceptor);
+ return this;
}
public <T> Manager addObserver(Observer<T> observer, Class<T>
eventType, Annotation... bindings)
@@ -302,7 +293,7 @@
contextMap.getDependentContext().setActive(true);
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal())
{
- return (T) getClientProxy(bean);
+ return (T) proxyPool.getClientProxy(bean, beans.indexOf(bean));
}
else
{
@@ -398,23 +389,5 @@
return null;
}
- private Object getClientProxy(Bean<?> bean)
- {
- Object clientProxy = clientProxyCache.get(bean);
- if (clientProxy == null)
- {
- try
- {
- clientProxy = clientProxyFactory.createClientProxy(bean,
beans.indexOf(bean));
- }
- catch (Exception e)
- {
- // TODO: What to *really* do here?
- throw new UnproxyableDependencyException("Could not create client proxy
for " + bean.getName(), e);
- }
- clientProxyCache.put(bean, clientProxy);
- }
- return clientProxy;
- }
}
Deleted:
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 2008-11-02
20:33:56 UTC (rev 217)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-11-02
22:41:01 UTC (rev 218)
@@ -1,56 +0,0 @@
-package org.jboss.webbeans.util;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import javassist.util.proxy.ProxyFactory;
-import javassist.util.proxy.ProxyObject;
-
-import javax.webbeans.manager.Bean;
-
-import org.jboss.webbeans.ManagerImpl;
-
-public class ClientProxyFactory
-{
- private ManagerImpl manager;
-
- public ClientProxyFactory(ManagerImpl manager) {
- this.manager = manager;
- }
-
- private class TypeInfo {
- Class<?>[] interfaces;
- Class<?> superclass;
- }
-
- private TypeInfo getTypeInfo(Set<Class<?>> types) {
- TypeInfo typeInfo = new TypeInfo();
- List<Class<?>> interfaces = new ArrayList<Class<?>>();
- Class<?> superclass = null;
- for (Class<?> type : types) {
- if (type.isInterface()) {
- interfaces.add(type);
- } else if (superclass == null || (type != Object.class &&
superclass.isAssignableFrom(type))) {
- superclass = type;
- }
- }
- interfaces.add(Serializable.class);
- typeInfo.interfaces = interfaces.toArray(new Class<?>[0]);
- typeInfo.superclass = superclass;
- return typeInfo;
- }
-
- public <T> T createClientProxy(Bean<T> bean, int beanIndex) throws
InstantiationException, IllegalAccessException {
- ProxyFactory proxyFactory = new ProxyFactory();
- TypeInfo typeInfo = getTypeInfo(bean.getTypes());
- proxyFactory.setInterfaces(typeInfo.interfaces);
- proxyFactory.setSuperclass(typeInfo.superclass);
- T clientProxy = (T) proxyFactory.createClass().newInstance();
- ProxyMethodHandler proxyMethodHandler = new ProxyMethodHandler(bean, beanIndex,
manager);
- ((ProxyObject)clientProxy).setHandler(proxyMethodHandler);
- return clientProxy;
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyPool.java (from
rev 216,
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyPool.java
(rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyPool.java 2008-11-02
22:41:01 UTC (rev 218)
@@ -0,0 +1,93 @@
+package org.jboss.webbeans.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
+
+import javax.webbeans.UnproxyableDependencyException;
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.ManagerImpl;
+
+public class ProxyPool
+{
+ private class Pool extends MapWrapper<Bean<?>, Object>
+ {
+ public Pool()
+ {
+ super(new HashMap<Bean<?>, Object>());
+ }
+
+ public <T> T get(Bean<T> key)
+ {
+ return (T) super.get(key);
+ }
+ }
+
+ private ManagerImpl manager;
+ private Pool pool;
+
+ public ProxyPool(ManagerImpl manager) {
+ this.manager = manager;
+ this.pool = new Pool();
+ }
+
+ private class TypeInfo {
+ Class<?>[] interfaces;
+ Class<?> superclass;
+ }
+
+ private TypeInfo getTypeInfo(Set<Class<?>> types) {
+ TypeInfo typeInfo = new TypeInfo();
+ List<Class<?>> interfaces = new ArrayList<Class<?>>();
+ Class<?> superclass = null;
+ for (Class<?> type : types) {
+ if (type.isInterface()) {
+ interfaces.add(type);
+ } else if (superclass == null || (type != Object.class &&
superclass.isAssignableFrom(type))) {
+ superclass = type;
+ }
+ }
+ interfaces.add(Serializable.class);
+ typeInfo.interfaces = interfaces.toArray(new Class<?>[0]);
+ typeInfo.superclass = superclass;
+ return typeInfo;
+ }
+
+ private <T> T createClientProxy(Bean<T> bean, int beanIndex) throws
InstantiationException, IllegalAccessException {
+ ProxyFactory proxyFactory = new ProxyFactory();
+ TypeInfo typeInfo = getTypeInfo(bean.getTypes());
+ proxyFactory.setInterfaces(typeInfo.interfaces);
+ proxyFactory.setSuperclass(typeInfo.superclass);
+ T clientProxy = (T) proxyFactory.createClass().newInstance();
+ ProxyMethodHandler proxyMethodHandler = new ProxyMethodHandler(bean, beanIndex,
manager);
+ ((ProxyObject)clientProxy).setHandler(proxyMethodHandler);
+ return clientProxy;
+ }
+
+ public Object getClientProxy(Bean<?> bean, int beanIndex)
+ {
+ Object clientProxy = pool.get(bean);
+ if (clientProxy == null)
+ {
+ try
+ {
+ clientProxy = createClientProxy(bean, beanIndex);
+ }
+ catch (Exception e)
+ {
+ // TODO: What to *really* do here?
+ throw new UnproxyableDependencyException("Could not create client proxy
for " + bean.getName(), e);
+ }
+ pool.put(bean, clientProxy);
+ }
+ return clientProxy;
+ }
+
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ProxyPool.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java 2008-11-02
20:33:56 UTC (rev 217)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java 2008-11-02
22:41:01 UTC (rev 218)
@@ -38,7 +38,7 @@
@Test(groups = "clientProxy")
@SpecAssertion(section = "4.4")
- public void testClientProxyIsSerializable()
+ public void testSimpleWebBeanClientProxyIsSerializable()
{
Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
manager.addBean(tunaBean);
@@ -90,6 +90,8 @@
@SpecAssertion(section = "4.4.1")
public void testInjectionPointWithUnproxyableTypeWhichResolvesToNormalScopedWebBean()
{
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ manager.addBean(tunaBean);
assert false;
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tuna.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tuna.java 2008-11-02
20:33:56 UTC (rev 217)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Tuna.java 2008-11-02
22:41:01 UTC (rev 218)
@@ -1,5 +1,6 @@
package org.jboss.webbeans.test.beans;
+import javax.webbeans.Current;
import javax.webbeans.RequestScoped;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
@@ -8,6 +9,8 @@
@RequestScoped
public class Tuna
{
+ @Current Animal animal;
+
public String getState() {
return "tuned";
}