[webbeans-commits] Webbeans SVN: r213 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-10-31 15:00:18 -0400 (Fri, 31 Oct 2008)
New Revision: 213
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java
Log:
Fixed Java 6 compiler error and replaced the reflection on T to find the constructor.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java 2008-10-31 14:46:37 UTC (rev 212)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java 2008-10-31 19:00:18 UTC (rev 213)
@@ -2,6 +2,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
+import java.util.logging.Level;
import java.util.logging.Logger;
import javax.webbeans.Dependent;
@@ -14,6 +15,8 @@
import org.jboss.webbeans.introspector.SimpleAnnotatedField;
import org.jboss.webbeans.util.LoggerUtil;
+import com.sun.org.apache.xerces.internal.dom.events.EventImpl;
+
/**
* Web Beans bean meta model for the container instantiated, injectable,
* observable events (Section 7.4).
@@ -28,33 +31,32 @@
private String location;
private SimpleAnnotatedField<T> annotatedItem;
private SimpleAnnotatedField<T> xmlAnnotatedItem;
- private BeanConstructor<T> constructor;
+ private BeanConstructor<T> constructor;
public EventBeanModel(SimpleAnnotatedField<T> annotatedItem, SimpleAnnotatedField<T> xmlAnnotatedItem, ManagerImpl manager)
{
this.annotatedItem = annotatedItem;
this.xmlAnnotatedItem = xmlAnnotatedItem;
+ initConstructor();
this.init(manager);
}
- @Override
- protected void init(ManagerImpl container)
- {
- super.init(container);
- this.initConstructor();
- }
-
/**
- * Initializes the constructor field of this class.
+ * Caches the constructor for this type of bean to avoid future reflections during use.
*/
- protected void initConstructor()
+ @SuppressWarnings("unchecked")
+ private void initConstructor()
{
- // There should only be one constructor for the event implementation used here
- // TODO Probably don't need to use reflection as this is a container supplied class
- Constructor<T> classConstructor = this.annotatedItem.getType().getConstructors()[0];
- constructor = new SimpleConstructor<T>(classConstructor);
+ try
+ {
+ constructor = new SimpleConstructor<T>((Constructor<T>) EventImpl.class.getConstructor((Class[])null));
+ } catch (Exception e)
+ {
+ log.log(Level.SEVERE, "Unable to get constructor for build-in Event implementation", e);
+ }
}
+
public BeanConstructor<T> getConstructor()
{
return constructor;
16 years
[webbeans-commits] Webbeans SVN: r212 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-31 10:46:37 -0400 (Fri, 31 Oct 2008)
New Revision: 212
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
Log:
fix compilation errors
Modified: 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-10-30 19:40:01 UTC (rev 211)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-10-31 14:46:37 UTC (rev 212)
@@ -3,7 +3,6 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Set;
@@ -15,8 +14,6 @@
import javax.webbeans.manager.Context;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.test.beans.Tuna;
-import org.jboss.webbeans.test.util.Util;
public class ClientProxyFactory
{
@@ -37,7 +34,6 @@
this.manager = manager;
}
- @Override
public Object invoke(Object self, Method method, Method proceed, Object[] args) throws Throwable
{
Context context = manager.getContext(bean.getScopeType());
@@ -49,9 +45,10 @@
}
private Class<?>[] addSerializableInterface(Class<?> clazz) {
- Class<?>[] interfaces = Arrays.copyOf(clazz.getInterfaces(), clazz.getInterfaces().length + 1);
+ // TODO Doesn't compile Class<?>[] interfaces = Arrays.copyOf(clazz.getInterfaces(), clazz.getInterfaces().length + 1);
+ Class[] interfaces = new Class[0];
interfaces[interfaces.length] = Serializable.class;
- return interfaces;
+ return interfaces;
}
private class TypeInfo {
16 years
[webbeans-commits] Webbeans SVN: r211 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-30 15:40:01 -0400 (Thu, 30 Oct 2008)
New Revision: 211
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
Log:
Superclass/interface detection in proxy generation
Modified: 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-10-30 08:02:51 UTC (rev 210)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-10-30 19:40:01 UTC (rev 211)
@@ -1,6 +1,10 @@
package org.jboss.webbeans.util;
+import java.io.Serializable;
import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.Set;
import javassist.util.proxy.MethodHandler;
@@ -22,7 +26,9 @@
this.manager = manager;
}
- public class ProxyMethodHandler implements MethodHandler {
+ public class ProxyMethodHandler implements MethodHandler, Serializable {
+ private static final long serialVersionUID = -5391564935097267888L;
+
private ManagerImpl manager;
private Bean<?> bean;
@@ -41,26 +47,44 @@
}
}
+
+ private Class<?>[] addSerializableInterface(Class<?> clazz) {
+ Class<?>[] interfaces = Arrays.copyOf(clazz.getInterfaces(), clazz.getInterfaces().length + 1);
+ interfaces[interfaces.length] = Serializable.class;
+ return interfaces;
+ }
+ 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) throws InstantiationException, IllegalAccessException {
ProxyFactory proxyFactory = new ProxyFactory();
- // TODO How to get the type T from a bean?
- Class<?>[] beanTypes = bean.getTypes().toArray(new Class<?>[0]);
- proxyFactory.setSuperclass(beanTypes[0]);
+ TypeInfo typeInfo = getTypeInfo(bean.getTypes());
+ proxyFactory.setInterfaces(typeInfo.interfaces);
+ proxyFactory.setSuperclass(typeInfo.superclass);
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();
- }
-
+
}
16 years
[webbeans-commits] Webbeans SVN: r210 - in ri/trunk/webbeans-ri: src/test/java/org/jboss/webbeans/test and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-30 04:02:51 -0400 (Thu, 30 Oct 2008)
New Revision: 210
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java
Modified:
ri/trunk/webbeans-ri/testng.xml
Log:
Stubs for passivation tests
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java 2008-10-30 08:02:51 UTC (rev 210)
@@ -0,0 +1,156 @@
+package org.jboss.webbeans.test;
+
+import javax.webbeans.manager.Context;
+
+import org.jboss.webbeans.contexts.RequestContext;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Nicklas Karlsson (nickarls(a)gmail.com)
+ *
+ */
+@SpecVersion("20081029-PDR")
+public class PassivatingContextTest extends AbstractTest
+{
+ Context context;
+
+ @BeforeMethod
+ public void initContext()
+ {
+ context = new RequestContext();
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testIsSessionScopePassivating()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testIsConversationScopePassivating()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testIsApplicationScopeNonPassivating()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testIsRequestScopePassivating()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testEJBWebBeanCanDefinePassivatingScope()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testSimpleWebBeanWithNonSerializableImplementationClassFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testProducerMethodDeclaringPassivatingScopeButReturningNonSerializableImplementationClassFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testSimpleWebBeanDeclaringPassivatingScopeIsSerializedWhenContextIsPassivated()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testStatefulEJBIsSerializedWhenPassivatedByEJBContainer()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testReferencesToWebBeansAreSerializable()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testDependentEJBsAreSerializable()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoStatefulSessionBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoNonTransientFieldOfWebBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoConstructorParameterOfWebBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoInitializerParameterOfWebBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testSimpleDependentWebBeanWithNonSerializableImplementationInjectedIntoProducerMethodParameterWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testDependentScopedProducerMethodReturnsNonSerializableObjectForInjectionIntoStatefulSessionBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testDependentScopedProducerMethodReturnsNonSerializableObjectForInjectionIntoNonTransientFieldOfWebBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testDependentScopedProducerMethodReturnsNonSerializableObjectForInjectionIntoConstructorParameterOfWebBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testDependentScopedProducerMethodReturnsNonSerializableObjectForInjectionIntoInitializerParameterOfWebBeanWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testDependentScopedProducerMethodReturnsNonSerializableObjectForInjectionIntoProducerMethodParameterWithPassivatingScopeFails()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "contexts", "passivation" }) @SpecAssertion(section = "8.4")
+ public void testJMSEndpointProxyIsSerializable()
+ {
+ assert false;
+ }
+}
Modified: ri/trunk/webbeans-ri/testng.xml
===================================================================
--- ri/trunk/webbeans-ri/testng.xml 2008-10-30 07:13:46 UTC (rev 209)
+++ ri/trunk/webbeans-ri/testng.xml 2008-10-30 08:02:51 UTC (rev 210)
@@ -23,6 +23,7 @@
<exclude name="innerClass" />
<exclude name="servlet" />
<exclude name="clientProxy" />
+ <exclude name="passivation" />
</run>
</groups>
<packages>
16 years
[webbeans-commits] Webbeans SVN: r209 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-30 03:13:46 -0400 (Thu, 30 Oct 2008)
New Revision: 209
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
Log:
Minor. Proxied type detection attempt
Modified: 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-10-30 05:32:02 UTC (rev 208)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-10-30 07:13:46 UTC (rev 209)
@@ -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;
@@ -45,11 +45,22 @@
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();
+ }
}
16 years
[webbeans-commits] Webbeans SVN: r208 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: util and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-30 01:32:02 -0400 (Thu, 30 Oct 2008)
New Revision: 208
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
Log:
Client proxy changes
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 14:03:54 UTC (rev 207)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-30 05:32:02 UTC (rev 208)
@@ -60,16 +60,16 @@
}
}
- private class ProxyPool extends MapWrapper<Bean<?>, Bean<?>>
+ private class ClientProxyCache extends MapWrapper<Bean<?>, Object>
{
- public ProxyPool()
+ public ClientProxyCache()
{
- super(new HashMap<Bean<?>, Bean<?>>());
+ super(new HashMap<Bean<?>, Object>());
}
- public Bean<?> get(Bean<?> key)
+ public <T> T get(Bean<T> key)
{
- return (Bean<?>) super.get(key);
+ return (T) super.get(key);
}
}
@@ -79,7 +79,7 @@
private EventBus eventBus;
private ResolutionManager resolutionManager;
private ContextMap contextMap;
- private ProxyPool proxyPool;
+ private ClientProxyCache clientProxyCache;
// TODO This could be a static method?
private ClientProxyFactory clientProxyFactory;
@@ -94,7 +94,7 @@
this.beans = new HashSet<Bean<?>>();
this.eventBus = new EventBus();
this.resolutionManager = new ResolutionManager(this);
- this.proxyPool = new ProxyPool();
+ this.clientProxyCache = new ClientProxyCache();
clientProxyFactory = new ClientProxyFactory(this);
}
@@ -295,7 +295,7 @@
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal())
{
// TODO What *really* to proxy? The bean? The instance?
- return (T) getClientProxy(bean).create();
+ return (T) getClientProxy(bean);
}
else
{
@@ -391,19 +391,19 @@
return null;
}
- private Bean<?> getClientProxy(Bean<?> bean)
+ private Object getClientProxy(Bean<?> bean)
{
- Bean<?> clientProxy = proxyPool.get(bean);
+ Object clientProxy = clientProxyCache.get(bean);
if (clientProxy == null)
{
try
{
- clientProxy = clientProxyFactory.createProxyClient(bean);
+ clientProxy = clientProxyFactory.createClientProxy(bean);
} catch (Exception e) {
// TODO: What to *really* do here?
- throw new UnproxyableDependencyException("Could not create proxy", e);
+ throw new UnproxyableDependencyException("Could not create client proxy for " + bean.getName(), e);
}
- proxyPool.put(bean, clientProxy);
+ clientProxyCache.put(bean, clientProxy);
}
return clientProxy;
}
Modified: 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-10-29 14:03:54 UTC (rev 207)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-10-30 05:32:02 UTC (rev 208)
@@ -12,7 +12,6 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.test.beans.Tuna;
-import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.jboss.webbeans.test.util.Util;
public class ClientProxyFactory
@@ -25,33 +24,32 @@
public class ProxyMethodHandler implements MethodHandler {
private ManagerImpl manager;
+ private Bean<?> bean;
- public ProxyMethodHandler(ManagerImpl manager) {
+ public ProxyMethodHandler(Bean<?> bean, ManagerImpl manager) {
+ this.bean = bean;
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);
-// Oneliner ;-)
-// return proceed.invoke(manager.getContext(((Bean<?>)self).getScopeType()).get(bean, true), args);
+ Context context = manager.getContext(bean.getScopeType());
+ Object proxiedInstance = context.get(bean, true);
+ Method proxiedMethod = proxiedInstance.getClass().getMethod(method.getName(), method.getParameterTypes());
+ return proxiedMethod.invoke(proxiedInstance, 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;
+ 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());
+ T clientProxy = (T) proxyFactory.createClass().newInstance();
+ ProxyMethodHandler proxyMethodHandler = new ProxyMethodHandler(bean, manager);
+ ((ProxyObject)clientProxy).setHandler(proxyMethodHandler);
+ return clientProxy;
}
-
+
}
16 years
[webbeans-commits] Webbeans SVN: r207 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: contexts and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-29 10:03:54 -0400 (Wed, 29 Oct 2008)
New Revision: 207
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ProxyData.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
Log:
Minor. WS and comments.
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java 2008-10-29 10:58:20 UTC (rev 206)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ClientProxy.java 2008-10-29 14:03:54 UTC (rev 207)
@@ -1,26 +0,0 @@
-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-29 10:58:20 UTC (rev 206)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-29 14:03:54 UTC (rev 207)
@@ -294,7 +294,8 @@
contextMap.getDependentContext().setActive(true);
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal())
{
- return (T) getClientProxy(bean);
+ // TODO What *really* to proxy? The bean? The instance?
+ return (T) getClientProxy(bean).create();
}
else
{
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ProxyData.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ProxyData.java 2008-10-29 10:58:20 UTC (rev 206)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ProxyData.java 2008-10-29 14:03:54 UTC (rev 207)
@@ -1,27 +0,0 @@
-package org.jboss.webbeans;
-
-import javax.webbeans.manager.Bean;
-import javax.webbeans.manager.Manager;
-
-public class ProxyData
-{
- private Bean<?> bean;
- private Manager manager;
-
- public ProxyData(Bean<?> bean, Manager manager)
- {
- this.bean = bean;
- this.manager = manager;
- }
-
- public Bean<?> getBean()
- {
- return bean;
- }
-
- public Manager getManager()
- {
- return manager;
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-29 10:58:20 UTC (rev 206)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-29 14:03:54 UTC (rev 207)
@@ -8,13 +8,13 @@
public abstract class NormalContext extends AbstractContext
{
-
private BeanMap beans;
public NormalContext(Class<? extends Annotation> scopeType)
{
super(scopeType);
beans = new BeanMap();
+ //TODO Are they active at creation?
active = true;
}
@@ -25,6 +25,7 @@
throw new ContextNotActiveException();
}
+ //TODO violation of specs. Why not just set active to false in destroy()?
if (beans == null)
{
// Context has been destroyed
Modified: 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-10-29 10:58:20 UTC (rev 206)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-10-29 14:03:54 UTC (rev 207)
@@ -11,6 +11,9 @@
import javax.webbeans.manager.Context;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.test.beans.Tuna;
+import org.jboss.webbeans.test.mock.MockManagerImpl;
+import org.jboss.webbeans.test.util.Util;
public class ClientProxyFactory
{
16 years
[webbeans-commits] Webbeans SVN: r206 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: util and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-29 06:58:20 -0400 (Wed, 29 Oct 2008)
New Revision: 206
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
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java
Log:
Minor: WS & import cleanup
ManagerImpl: Moved dependent context into context map and made helper method in ContextMap. Up for debate, though.
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 10:30:21 UTC (rev 205)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-29 10:58:20 UTC (rev 206)
@@ -10,6 +10,7 @@
import javax.webbeans.AmbiguousDependencyException;
import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.Dependent;
import javax.webbeans.DeploymentException;
import javax.webbeans.Observer;
import javax.webbeans.Production;
@@ -52,6 +53,11 @@
{
return (List<Context>) super.get(key);
}
+
+ public DependentContext getDependentContext()
+ {
+ return (DependentContext) get(Dependent.class).get(0);
+ }
}
private class ProxyPool extends MapWrapper<Bean<?>, Bean<?>>
@@ -73,8 +79,8 @@
private EventBus eventBus;
private ResolutionManager resolutionManager;
private ContextMap contextMap;
- private DependentContext dependentContext;
private ProxyPool proxyPool;
+ // TODO This could be a static method?
private ClientProxyFactory clientProxyFactory;
private Set<Bean<?>> beans;
@@ -115,9 +121,7 @@
this.contextMap = new ContextMap();
if (contexts == null)
{
-
- this.dependentContext = new DependentContext();
- addContext(dependentContext);
+ addContext(new DependentContext());
addContext(new RequestContext());
addContext(new SessionContext());
addContext(new ApplicationContext());
@@ -287,7 +291,7 @@
{
try
{
- dependentContext.setActive(true);
+ contextMap.getDependentContext().setActive(true);
if (getModelManager().getScopeModel(bean.getScopeType()).isNormal())
{
return (T) getClientProxy(bean);
@@ -299,7 +303,7 @@
}
finally
{
- dependentContext.setActive(false);
+ contextMap.getDependentContext().setActive(false);
}
}
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 10:30:21 UTC (rev 205)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java 2008-10-29 10:58:20 UTC (rev 206)
@@ -1,10 +1,7 @@
package org.jboss.webbeans.util;
-import java.lang.reflect.Method;
-import javassist.util.proxy.MethodHandler;
-
public class ClientProxy
{
Modified: 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-10-29 10:30:21 UTC (rev 205)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyFactory.java 2008-10-29 10:58:20 UTC (rev 206)
@@ -35,6 +35,8 @@
Context context = manager.getContext(beanScope);
Object instance = context.get(bean, true);
return proceed.invoke(instance, args);
+// Oneliner ;-)
+// return proceed.invoke(manager.getContext(((Bean<?>)self).getScopeType()).get(bean, true), args);
}
}
16 years
[webbeans-commits] Webbeans SVN: r205 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: util and 1 other directory.
by webbeans-commits@lists.jboss.org
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;
+ }
+
+}
16 years
[webbeans-commits] Webbeans SVN: r204 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: util and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-29 03:34:07 -0400 (Wed, 29 Oct 2008)
New Revision: 204
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Log:
Minor. renames
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:24:34 UTC (rev 203)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-29 07:34:07 UTC (rev 204)
@@ -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.ClientProxyUtil;
+import org.jboss.webbeans.util.ClientProxy;
import org.jboss.webbeans.util.MapWrapper;
import org.jboss.webbeans.util.Reflections;
@@ -341,7 +341,7 @@
else
{
Bean<T> bean = beans.iterator().next();
- if (getModelManager().getScopeModel(bean.getScopeType()).isNormal() && !ClientProxyUtil.isProxyable(injectable.getType()))
+ if (getModelManager().getScopeModel(bean.getScopeType()).isNormal() && !ClientProxy.isProxyable(injectable.getType()))
{
throw new UnproxyableDependencyException(new TypesafeResolutionLocation(injectable) + "Unable to proxy");
}
@@ -390,7 +390,7 @@
{
try
{
- clientProxy = ClientProxyUtil.createProxy(new ProxyData(bean, this));
+ clientProxy = ClientProxy.createProxy(new ProxyData(bean, this));
} catch (Exception e) {
throw new UnproxyableDependencyException("Could not create proxy", e);
}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java (from rev 203, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxy.java 2008-10-29 07:34:07 UTC (rev 204)
@@ -0,0 +1,69 @@
+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
+{
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+
+}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java 2008-10-29 07:24:34 UTC (rev 203)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/ClientProxyUtil.java 2008-10-29 07:34:07 UTC (rev 204)
@@ -1,69 +0,0 @@
-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 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;
- }
- }
-
- 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 clientProxy) throws InstantiationException, IllegalAccessException
- {
- ProxyFactory proxyFactory = new ProxyFactory();
- proxyFactory.setSuperclass(clientProxy.getClass());
- Class<?> proxyClass = proxyFactory.createClass();
- Bean<?> proxy = (Bean<?>) proxyClass.newInstance();
- ((ProxyObject)proxy).setHandler(methodHandler);
- return proxy;
- }
-
-}
16 years, 1 month