[webbeans-commits] Webbeans SVN: r201 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: util and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Oct 28 18:04:15 EDT 2008


Author: nickarls
Date: 2008-10-28 18:04:15 -0400 (Tue, 28 Oct 2008)
New Revision: 201

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java
Removed:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Log:
Initial proxy support

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java	2008-10-28 22:04:15 UTC (rev 201)
@@ -0,0 +1,26 @@
+package org.jboss.webbeans;
+
+import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Context;
+import javax.webbeans.manager.Manager;
+
+public class ClientProxy<T>
+{
+   private Bean<T> bean;
+   private Manager manager;
+   
+   public ClientProxy(Bean<T> bean, Manager manager)
+   {
+      this.bean = bean;
+      this.manager = manager;
+   }
+   
+   public T getInstance() 
+   {
+      Context context = manager.getContext(bean.getScopeType());
+      T instance = context.get(bean, true);
+      // wrap in proxy here
+      return instance;
+   }
+
+}

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-28 20:27:32 UTC (rev 200)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java	2008-10-28 22:04:15 UTC (rev 201)
@@ -34,7 +34,7 @@
 import org.jboss.webbeans.exceptions.TypesafeResolutionLocation;
 import org.jboss.webbeans.injectable.Injectable;
 import org.jboss.webbeans.injectable.ResolverInjectable;
-import org.jboss.webbeans.util.ClientProxy;
+import org.jboss.webbeans.util.ClientProxyUtil;
 import org.jboss.webbeans.util.MapWrapper;
 import org.jboss.webbeans.util.Reflections;
 
@@ -55,6 +55,22 @@
 
    }
 
+   private class ProxyPool extends MapWrapper<Bean<?>, ClientProxy<?>>
+   {
+
+      public ProxyPool()
+      {
+         super(new HashMap<Bean<?>, ClientProxy<?>>());
+      }
+
+      public ClientProxy<?> get(Bean<?> key)
+      {
+         return (ClientProxy<?>) super.get(key);
+      }
+
+   }
+   
+   
    private List<Class<? extends Annotation>> enabledDeploymentTypes;
    private ModelManager modelManager;
    private EjbManager ejbLookupManager;
@@ -62,6 +78,7 @@
    private ResolutionManager resolutionManager;
    private ContextMap contextMap;
    private DependentContext dependentContext;
+   private ProxyPool proxyPool;
 
    private Set<Bean<?>> beans;
 
@@ -74,6 +91,7 @@
       this.beans = new HashSet<Bean<?>>();
       this.eventBus = new EventBus();
       this.resolutionManager = new ResolutionManager(this);
+      this.proxyPool = new ProxyPool();
    }
 
    protected void initEnabledDeploymentTypes(List<Class<? extends Annotation>> enabledDeploymentTypes)
@@ -272,8 +290,7 @@
          dependentContext.setActive(true);
          if (getModelManager().getScopeModel(bean.getScopeType()).isNormal())
          {
-            // TODO return a client proxy
-            return getContext(bean.getScopeType()).get(bean, true);
+            return (T) getClientProxy(bean).getInstance();
          }
          else
          {
@@ -327,7 +344,7 @@
       else
       {
          Bean<T> bean = beans.iterator().next();
-         if (getModelManager().getScopeModel(bean.getScopeType()).isNormal() && !ClientProxy.isProxyable(injectable.getType()))
+         if (getModelManager().getScopeModel(bean.getScopeType()).isNormal() && !ClientProxyUtil.isProxyable(injectable.getType()))
          {
             throw new UnproxyableDependencyException(new TypesafeResolutionLocation(injectable) + "Unable to proxy");
          }
@@ -367,5 +384,17 @@
       // TODO Auto-generated method stub
       return null;
    }
+   
+   private ClientProxy<?> getClientProxy(Bean<?> bean) 
+   {
+      ClientProxy<?> clientProxy = proxyPool.get(bean);
+      if (clientProxy == null)
+      {
+         clientProxy = new ClientProxy(bean, this);
+         proxyPool.put(bean, clientProxy);
+      }
+      return clientProxy;
+   }
+   
 
 }

Deleted: 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-28 20:27:32 UTC (rev 200)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java	2008-10-28 22:04:15 UTC (rev 201)
@@ -1,33 +0,0 @@
-package org.jboss.webbeans.util;
-
-
-public class ClientProxy
-{
-   
-   public static boolean isProxyable(Class<?> rawType)
-   {
-      // TODO Add logging
-      
-      if (Reflections.getConstructor(rawType) == null)
-      {
-         return false;
-      }
-      else if (Reflections.isTypeOrAnyMethodFinal(rawType))
-      {
-         return false;
-      }
-      else if (Reflections.isPrimitive(rawType))
-      {
-         return false;
-      }
-      else if (Reflections.isArrayType(rawType))
-      {
-         return false;
-      }
-      else
-      {
-         return true;
-      }
-   }
-   
-}

Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java (from rev 199, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java	2008-10-28 22:04:15 UTC (rev 201)
@@ -0,0 +1,33 @@
+package org.jboss.webbeans.util;
+
+
+public class ClientProxyUtil
+{
+   
+   public static boolean isProxyable(Class<?> rawType)
+   {
+      // TODO Add logging
+      
+      if (Reflections.getConstructor(rawType) == null)
+      {
+         return false;
+      }
+      else if (Reflections.isTypeOrAnyMethodFinal(rawType))
+      {
+         return false;
+      }
+      else if (Reflections.isPrimitive(rawType))
+      {
+         return false;
+      }
+      else if (Reflections.isArrayType(rawType))
+      {
+         return false;
+      }
+      else
+      {
+         return true;
+      }
+   }
+   
+}


Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:mergeinfo
   + 




More information about the weld-commits mailing list