[weld-commits] Weld SVN: r4576 - core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Mon Nov 2 19:01:40 EST 2009
Author: pete.muir at jboss.org
Date: 2009-11-02 19:01:39 -0500 (Mon, 02 Nov 2009)
New Revision: 4576
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java
Log:
use contextual store to identify beans
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-11-02 23:59:27 UTC (rev 4575)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-11-03 00:01:39 UTC (rev 4576)
@@ -30,7 +30,9 @@
import javax.enterprise.inject.spi.Bean;
import org.jboss.weld.BeanManagerImpl;
+import org.jboss.weld.Container;
import org.jboss.weld.context.WeldCreationalContext;
+import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.util.Reflections;
import org.slf4j.cal10n.LocLogger;
@@ -52,7 +54,7 @@
// The bean
private transient Bean<?> bean;
// The bean index in the manager
- private final int beanIndex;
+ private final String id;
private final BeanManagerImpl manager;
@@ -64,12 +66,12 @@
* @param bean The bean to proxy
* @param beanIndex The index to the bean in the manager bean list
*/
- public ClientProxyMethodHandler(Bean<?> bean, BeanManagerImpl manager, int beanIndex)
+ public ClientProxyMethodHandler(Bean<?> bean, BeanManagerImpl manager, String id)
{
this.bean = bean;
- this.beanIndex = beanIndex;
+ this.id = id;
this.manager = manager;
- log.trace("Created method handler for bean " + bean + " indexed as " + beanIndex);
+ log.trace("Created method handler for bean " + bean + " identified as " + id);
}
/**
@@ -94,7 +96,7 @@
{
if (bean == null)
{
- bean = manager.getBeans().get(beanIndex);
+ bean = Container.instance().deploymentServices().get(ContextualStore.class).<Bean<Object>, Object>getContextual(id);
}
Object proxiedInstance = getProxiedInstance(bean);
if ("touch".equals(proxiedMethod.getName()) && Marker.isMarker(0, proxiedMethod, args))
@@ -164,7 +166,7 @@
{
StringBuilder buffer = new StringBuilder();
String beanInfo = bean == null ? "null bean" : bean.toString();
- buffer.append("Proxy method handler for " + beanInfo + " with index " + beanIndex);
+ buffer.append("Proxy method handler for " + beanInfo + " with id " + id);
return buffer.toString();
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java 2009-11-02 23:59:27 UTC (rev 4575)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java 2009-11-03 00:01:39 UTC (rev 4576)
@@ -27,7 +27,9 @@
import javax.enterprise.inject.spi.Bean;
import org.jboss.weld.BeanManagerImpl;
+import org.jboss.weld.Container;
import org.jboss.weld.DefinitionException;
+import org.jboss.weld.serialization.spi.ContextualStore;
import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.collections.ConcurrentCache;
@@ -70,12 +72,12 @@
* @throws InstantiationException When the proxy couldn't be created
* @throws IllegalAccessException When the proxy couldn't be created
*/
- private static <T> T createClientProxy(Bean<T> bean, BeanManagerImpl manager, int beanIndex) throws RuntimeException
+ private static <T> T createClientProxy(Bean<T> bean, BeanManagerImpl manager, String id) throws RuntimeException
{
try
{
- ClientProxyMethodHandler proxyMethodHandler = new ClientProxyMethodHandler(bean, manager, beanIndex);
+ ClientProxyMethodHandler proxyMethodHandler = new ClientProxyMethodHandler(bean, manager, id);
Set<Type> classes = new LinkedHashSet<Type>(bean.getTypes());
//classes.add(ClientProxyInstance.class);
classes.add(Serializable.class);
@@ -114,12 +116,12 @@
public T call() throws Exception
{
- int beanIndex = manager.getBeans().indexOf(bean);
- if (beanIndex < 0)
+ String id = Container.instance().deploymentServices().get(ContextualStore.class).putIfAbsent(bean);
+ if (id == null)
{
- throw new DefinitionException(bean + " is not known to the manager");
+ throw new DefinitionException("There was an error creating an id for " + bean);
}
- return createClientProxy(bean, manager, beanIndex);
+ return createClientProxy(bean, manager, id);
}
});
More information about the weld-commits
mailing list