[jboss-cvs] jboss-seam/src/main/org/jboss/seam/intercept ...
Gavin King
gavin.king at jboss.com
Tue Oct 31 20:52:09 EST 2006
User: gavin
Date: 06/10/31 20:52:09
Modified: src/main/org/jboss/seam/intercept Interceptor.java
JavaBeanInterceptor.java RootInterceptor.java
SessionBeanInterceptor.java
Log:
insulate core from EJB dependencies JBSEAM-414
Revision Changes Path
1.3 +6 -9 jboss-seam/src/main/org/jboss/seam/intercept/Interceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Interceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/intercept/Interceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Interceptor.java 25 Oct 2006 15:14:35 -0000 1.2
+++ Interceptor.java 1 Nov 2006 01:52:09 -0000 1.3
@@ -1,19 +1,16 @@
-//$Id: Interceptor.java,v 1.2 2006/10/25 15:14:35 gavin Exp $
+//$Id: Interceptor.java,v 1.3 2006/11/01 01:52:09 gavin Exp $
package org.jboss.seam.intercept;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.PostActivate;
-import javax.ejb.PrePassivate;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptors;
import javax.interceptor.InvocationContext;
import org.jboss.seam.Component;
import org.jboss.seam.InterceptorType;
+import org.jboss.seam.util.EJB;
import org.jboss.seam.util.Reflections;
/**
@@ -131,19 +128,19 @@
{
aroundInvokeMethod = method;
}
- if ( method.isAnnotationPresent(PostConstruct.class) )
+ if ( method.isAnnotationPresent(EJB.POST_CONSTRUCT) )
{
postConstructMethod = method;
}
- if ( method.isAnnotationPresent(PreDestroy.class) )
+ if ( method.isAnnotationPresent(EJB.PRE_DESTROY) )
{
preDestroyMethod = method;
}
- if ( method.isAnnotationPresent(PrePassivate.class) )
+ if ( method.isAnnotationPresent(EJB.PRE_PASSIVATE) )
{
prePassivateMethod = method;
}
- if ( method.isAnnotationPresent(PostActivate.class) )
+ if ( method.isAnnotationPresent(EJB.POST_ACTIVATE) )
{
postActivateMethod = method;
}
1.7 +30 -5 jboss-seam/src/main/org/jboss/seam/intercept/JavaBeanInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JavaBeanInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/intercept/JavaBeanInterceptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- JavaBeanInterceptor.java 25 Oct 2006 15:14:35 -0000 1.6
+++ JavaBeanInterceptor.java 1 Nov 2006 01:52:09 -0000 1.7
@@ -1,8 +1,10 @@
-//$Id: JavaBeanInterceptor.java,v 1.6 2006/10/25 15:14:35 gavin Exp $
+//$Id: JavaBeanInterceptor.java,v 1.7 2006/11/01 01:52:09 gavin Exp $
package org.jboss.seam.intercept;
import java.lang.reflect.Method;
+import javax.interceptor.InvocationContext;
+
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@@ -71,9 +73,30 @@
}
+ public void postConstruct()
+ {
+ super.postConstruct(bean);
+ callPostConstruct();
+ }
+
+ private void callPostConstruct()
+ {
+ InvocationContext context = new RootInvocationContext( bean, getComponent().getPostConstructMethod(), new Object[0] )
+ {
+ @Override
+ public Object proceed() throws Exception
+ {
+ getComponent().callPostConstructMethod(bean);
+ return null;
+ }
+
+ };
+ invokeAndHandle(context, EventType.POST_CONSTRUCT);
+ }
+
private void callPrePassivate()
{
- prePassivate( new RootInvocationContext(bean, getComponent().getPrePassivateMethod(), new Object[0])
+ InvocationContext context = new RootInvocationContext( bean, getComponent().getPrePassivateMethod(), new Object[0] )
{
@Override
public Object proceed() throws Exception
@@ -82,12 +105,13 @@
return null;
}
- } );
+ };
+ invokeAndHandle(context, EventType.PRE_PASSIVATE);
}
private void callPostActivate()
{
- postActivate( new RootInvocationContext(bean, getComponent().getPostActivateMethod(), new Object[0])
+ RootInvocationContext context = new RootInvocationContext(bean, getComponent().getPostActivateMethod(), new Object[0])
{
@Override
public Object proceed() throws Exception
@@ -96,7 +120,8 @@
return null;
}
- } );
+ };
+ invokeAndHandle(context, EventType.POST_ACTIVATE);
}
private Object interceptInvocation(final Method method, final Object[] params,
1.5 +5 -36 jboss-seam/src/main/org/jboss/seam/intercept/RootInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RootInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/intercept/RootInterceptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- RootInterceptor.java 25 Oct 2006 15:54:17 -0000 1.4
+++ RootInterceptor.java 1 Nov 2006 01:52:09 -0000 1.5
@@ -9,10 +9,6 @@
import java.io.Serializable;
import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.ejb.PostActivate;
-import javax.ejb.PrePassivate;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
@@ -41,13 +37,7 @@
private transient Component component; //a cache of the Component reference for performance
- /**
- * Called when instatiated by EJB container.
- * (In this case it might be a Seam component,
- * but we won't know until postConstruct() is
- * called.)
- */
- public RootInterceptor(InterceptorType type)
+ protected RootInterceptor(InterceptorType type)
{
this.type = type;
}
@@ -65,15 +55,14 @@
isSeamComponent = false;
}
- @PostConstruct
- public void postConstruct(InvocationContext invocation)
+ protected void postConstruct(Object bean)
{
// initialize the bean instance
if (isSeamComponent)
{
try
{
- getComponent().initialize( invocation.getTarget() );
+ getComponent().initialize(bean);
}
catch (RuntimeException e)
{
@@ -84,29 +73,9 @@
throw new RuntimeException("exception initializing EJB component", e);
}
}
-
- invokeAndHandle(invocation, EventType.POST_CONSTRUCT);
- }
-
- @PreDestroy
- public void preDestroy(InvocationContext invocation)
- {
- invokeAndHandle(invocation, EventType.PRE_DESTORY);
- }
-
- @PrePassivate
- public void prePassivate(InvocationContext invocation)
- {
- invokeAndHandle(invocation, EventType.PRE_PASSIVATE);
- }
-
- @PostActivate
- public void postActivate(InvocationContext invocation)
- {
- invokeAndHandle(invocation, EventType.POST_ACTIVATE);
}
- private void invokeAndHandle(InvocationContext invocation, EventType invocationType)
+ protected void invokeAndHandle(InvocationContext invocation, EventType invocationType)
{
try
{
1.5 +26 -4 jboss-seam/src/main/org/jboss/seam/intercept/SessionBeanInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SessionBeanInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/intercept/SessionBeanInterceptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- SessionBeanInterceptor.java 25 Oct 2006 15:14:35 -0000 1.4
+++ SessionBeanInterceptor.java 1 Nov 2006 01:52:09 -0000 1.5
@@ -7,6 +7,9 @@
package org.jboss.seam.intercept;
import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
import javax.interceptor.InvocationContext;
import org.jboss.seam.Component;
@@ -36,11 +39,29 @@
super(InterceptorType.SERVER);
}
+ @PrePassivate
+ public void prePassivate(InvocationContext invocation)
+ {
+ invokeAndHandle(invocation, EventType.PRE_PASSIVATE);
+ }
+
+ @PostActivate
+ public void postActivate(InvocationContext invocation)
+ {
+ invokeAndHandle(invocation, EventType.POST_ACTIVATE);
+ }
+
+ @PreDestroy
+ public void preDestroy(InvocationContext invocation)
+ {
+ invokeAndHandle(invocation, EventType.PRE_DESTORY);
+ }
+
@PostConstruct
- @Override
public void postConstruct(InvocationContext invocation)
{
Component invokingComponent = SessionBeanInterceptor.COMPONENT.get();
+ Object bean = invocation.getTarget();
if ( invokingComponent!=null )
{
//the session bean was obtained by the application by
@@ -48,11 +69,11 @@
//other than the default role
init(invokingComponent);
}
- else if ( invocation.getTarget().getClass().isAnnotationPresent(Name.class) )
+ else if ( bean.getClass().isAnnotationPresent(Name.class) )
{
//the session bean was obtained by the application from
//JNDI, so assume the default role
- String defaultComponentName = invocation.getTarget().getClass().getAnnotation(Name.class).value();
+ String defaultComponentName = bean.getClass().getAnnotation(Name.class).value();
init( Seam.componentForName( defaultComponentName ) );
}
else
@@ -60,7 +81,8 @@
initNonSeamComponent();
}
- super.postConstruct(invocation);
+ postConstruct(bean);
+ invokeAndHandle(invocation, EventType.POST_CONSTRUCT);
}
}
More information about the jboss-cvs-commits
mailing list