Author: pete.muir(a)jboss.org
Date: 2009-03-15 17:07:30 -0400 (Sun, 15 Mar 2009)
New Revision: 2017
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/ejb/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/ejb/interceptor/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/Foo.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/FooLocal.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockInvocationContext.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockSessionBeanInterceptor.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/SessionBeanInterceptorTest.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/EnterpriseBeanTest.java
Log:
WBRI-187
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-15 19:55:43
UTC (rev 2016)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-15 21:07:30
UTC (rev 2017)
@@ -68,9 +68,9 @@
import org.jboss.webbeans.ejb.EjbDescriptorCache;
import org.jboss.webbeans.event.EventManager;
import org.jboss.webbeans.event.ObserverImpl;
+import org.jboss.webbeans.injection.NonContextualInjector;
import org.jboss.webbeans.injection.ResolvableAnnotatedClass;
import org.jboss.webbeans.injection.Resolver;
-import org.jboss.webbeans.injection.NonContextualInjector;
import org.jboss.webbeans.introspector.AnnotatedClass;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -122,6 +122,9 @@
private transient List<Bean<?>> beans;
// The registered beans, mapped by implementation class
private transient final Map<Class<?>, EnterpriseBean<?>>
newEnterpriseBeanMap;
+
+ private transient final Map<String, RIBean<?>> riBeans;
+
// The registered decorators
private transient final Set<Decorator> decorators;
// The registered interceptors
@@ -146,6 +149,7 @@
this.serviceRegistry = serviceRegistry;
this.beans = new CopyOnWriteArrayList<Bean<?>>();
this.newEnterpriseBeanMap = new ConcurrentHashMap<Class<?>,
EnterpriseBean<?>>();
+ this.riBeans = new ConcurrentHashMap<String, RIBean<?>>();
this.resolver = new Resolver(this);
this.clientProxyProvider = new ClientProxyProvider();
this.decorators = new HashSet<Decorator>();
@@ -372,6 +376,7 @@
{
newEnterpriseBeanMap.put(bean.getType(), (EnterpriseBean<?>) bean);
}
+ riBeans.put(bean.getId(), bean);
}
resolver.clear();
}
@@ -396,6 +401,11 @@
{
return Collections.unmodifiableList(beans);
}
+
+ public Map<String, RIBean<?>> getRiBeans()
+ {
+ return Collections.unmodifiableMap(riBeans);
+ }
/**
* Registers a context with the manager
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java 2009-03-15
19:55:43 UTC (rev 2016)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/ForwardingBean.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -23,6 +23,7 @@
import javax.context.CreationalContext;
import javax.inject.manager.Bean;
+import javax.inject.manager.InjectionPoint;
import javax.inject.manager.Manager;
/**
@@ -141,6 +142,12 @@
{
return delegate().isSerializable();
}
+
+ @Override
+ public Set<? extends InjectionPoint> getInjectionPoints()
+ {
+ return delegate().getInjectionPoints();
+ }
/**
* Gets the hash code of the delegate
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java 2009-03-15 19:55:43
UTC (rev 2016)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/RIBean.java 2009-03-15 21:07:30
UTC (rev 2017)
@@ -16,7 +16,9 @@
*/
package org.jboss.webbeans.bean;
+import java.io.Serializable;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.context.Dependent;
import javax.inject.manager.Bean;
@@ -29,14 +31,21 @@
*
* @author Pete Muir
*/
-public abstract class RIBean<T> extends Bean<T>
+public abstract class RIBean<T> extends Bean<T> implements Serializable
{
+
+ private static final AtomicInteger idGenerator = new AtomicInteger();
+
private final ManagerImpl manager;
+
+ private final String id;
protected RIBean(ManagerImpl manager)
{
super(manager);
this.manager = manager;
+ // TODO better ID strategy (human readable)
+ this.id = getClass().getName() + "-" + idGenerator.getAndIncrement();
}
@Override
@@ -61,5 +70,10 @@
public abstract Set<AnnotatedInjectionPoint<?, ?>> getInjectionPoints();
public abstract RIBean<?> getSpecializedBean();
+
+ public String getId()
+ {
+ return id;
+ }
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java 2009-03-15
19:55:43 UTC (rev 2016)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/ejb/SessionBeanInterceptor.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -17,6 +17,10 @@
package org.jboss.webbeans.ejb;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.interceptor.InvocationContext;
@@ -33,13 +37,13 @@
*
* @author Pete Muir
*/
-public class SessionBeanInterceptor
+public class SessionBeanInterceptor implements Serializable
{
private transient Log log = Logging.getLog(SessionBeanInterceptor.class);
- // TODO make Bean serializable
private transient EnterpriseBean<Object> bean;
+ private String beanId;
private boolean contextual;
/**
@@ -98,6 +102,7 @@
this.bean = (EnterpriseBean<Object>)
CurrentManager.rootManager().getNewEnterpriseBeanMap().get(beanClass);
this.contextual = false;
}
+ this.beanId = this.bean.getId();
}
private static <T> EnterpriseBeanInstance
getEnterpriseBeanInstance(EnterpriseBean<T> bean)
@@ -112,6 +117,20 @@
throw new IllegalStateException("Contextual instance not an session bean
created by the container");
}
}
+
+ private void readObject(ObjectInputStream ois) throws IOException,
ClassNotFoundException
+ {
+ ois.defaultReadObject();
+ if (beanId != null)
+ {
+ bean = (EnterpriseBean<Object>)
CurrentManager.rootManager().getRiBeans().get(beanId);
+ }
+ }
+
+ protected EnterpriseBean<Object> getBean()
+ {
+ return bean;
+ }
}
Modified:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/EnterpriseBeanTest.java
===================================================================
---
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/EnterpriseBeanTest.java 2009-03-15
19:55:43 UTC (rev 2016)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/EnterpriseBeanTest.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -19,4 +19,6 @@
}
+
+
}
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/Foo.java
===================================================================
---
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/Foo.java
(rev 0)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/Foo.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.test.unit.implementation.enterprise.sbi;
+
+import javax.ejb.Stateful;
+
+
+@Stateful
+public class Foo implements FooLocal
+{
+
+}
Property changes on:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/Foo.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/FooLocal.java
===================================================================
---
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/FooLocal.java
(rev 0)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/FooLocal.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.unit.implementation.enterprise.sbi;
+
+import javax.ejb.Local;
+
+@Local
+public interface FooLocal
+{
+
+}
Property changes on:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/FooLocal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockInvocationContext.java
===================================================================
---
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockInvocationContext.java
(rev 0)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockInvocationContext.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -0,0 +1,48 @@
+package org.jboss.webbeans.test.unit.implementation.enterprise.sbi;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.interceptor.InvocationContext;
+
+public class MockInvocationContext implements InvocationContext
+{
+
+ private Foo foo = new Foo();
+
+ public Map<String, Object> getContextData()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Method getMethod()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object[] getParameters()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getTarget()
+ {
+ return foo;
+ }
+
+ public Object proceed() throws Exception
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setParameters(Object[] params)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Property changes on:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockInvocationContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockSessionBeanInterceptor.java
===================================================================
---
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockSessionBeanInterceptor.java
(rev 0)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockSessionBeanInterceptor.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.unit.implementation.enterprise.sbi;
+
+import org.jboss.webbeans.bean.EnterpriseBean;
+import org.jboss.webbeans.ejb.SessionBeanInterceptor;
+
+public class MockSessionBeanInterceptor extends SessionBeanInterceptor
+{
+
+ @Override
+ public EnterpriseBean<Object> getBean()
+ {
+ return super.getBean();
+ }
+
+}
Property changes on:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/MockSessionBeanInterceptor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/SessionBeanInterceptorTest.java
===================================================================
---
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/SessionBeanInterceptorTest.java
(rev 0)
+++
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/SessionBeanInterceptorTest.java 2009-03-15
21:07:30 UTC (rev 2017)
@@ -0,0 +1,47 @@
+package org.jboss.webbeans.test.unit.implementation.enterprise.sbi;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.inject.manager.Bean;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+@Artifact
+public class SessionBeanInterceptorTest extends AbstractWebBeansTest
+{
+
+ @Test
+ public void testSerializeSessionBeanInterceptor() throws Exception
+ {
+ Bean<?> foobean = manager.getNewEnterpriseBeanMap().get(Foo.class);
+ assert foobean != null;
+ MockSessionBeanInterceptor interceptor = new MockSessionBeanInterceptor();
+ interceptor.postConstruct(new MockInvocationContext());
+ assert interceptor.getBean() != null;
+ Bean<?> bean = interceptor.getBean();
+ interceptor = (MockSessionBeanInterceptor) deserialize(serialize(interceptor));
+ assert interceptor.getBean() != null;
+ assert bean.equals(interceptor.getBean());
+ }
+
+ protected byte[] serialize(Object instance) throws IOException
+ {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(bytes);
+ out.writeObject(instance);
+ return bytes.toByteArray();
+ }
+
+ protected Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException
+ {
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
+ return in.readObject();
+ }
+
+}
Property changes on:
ri/trunk/impl/src/test/java/org/jboss/webbeans/test/unit/implementation/enterprise/sbi/SessionBeanInterceptorTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain