[jboss-cvs] jboss-seam/src/main/org/jboss/seam/intercept ...
Gavin King
gavin.king at jboss.com
Fri Oct 13 00:04:48 EDT 2006
User: gavin
Date: 06/10/13 00:04:48
Modified: src/main/org/jboss/seam/intercept
ClientSideInterceptor.java JavaBeanInterceptor.java
RootInterceptor.java RootInvocationContext.java
Added: src/main/org/jboss/seam/intercept Proxy.java
Log:
make cglib interceptors properly serializable JBSEAM-332
Revision Changes Path
1.3 +37 -20 jboss-seam/src/main/org/jboss/seam/intercept/ClientSideInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ClientSideInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/intercept/ClientSideInterceptor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ClientSideInterceptor.java 10 Oct 2006 18:12:31 -0000 1.2
+++ ClientSideInterceptor.java 13 Oct 2006 04:04:48 -0000 1.3
@@ -1,10 +1,8 @@
-//$Id: ClientSideInterceptor.java,v 1.2 2006/10/10 18:12:31 gavin Exp $
+//$Id: ClientSideInterceptor.java,v 1.3 2006/10/13 04:04:48 gavin Exp $
package org.jboss.seam.intercept;
-import java.io.Serializable;
import java.lang.reflect.Method;
-
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@@ -19,7 +17,7 @@
* @author Gavin King
*/
public class ClientSideInterceptor extends RootInterceptor
- implements MethodInterceptor, Serializable
+ implements MethodInterceptor
{
private final Object bean;
@@ -34,36 +32,55 @@
public Object intercept(final Object proxy, final Method method, final Object[] params,
final MethodProxy methodProxy) throws Throwable
{
- //TODO: handle the finalize method
- return aroundInvoke( new RootInvocationContext(bean, method, params)
+ String methodName = method.getName();
+ if ( "finalize".equals(methodName) )
+ {
+ return methodProxy.invokeSuper(proxy, params);
+ }
+ else if ( "writeReplace".equals(methodName) )
+ {
+ return this;
+ }
+ return interceptInvocation(method, params, methodProxy);
+ }
+
+ private Object interceptInvocation(final Method method, final Object[] params, final MethodProxy methodProxy) throws Exception
+ {
+ return aroundInvoke( new RootInvocationContext(bean, method, params, methodProxy)
{
public Object proceed() throws Exception
{
SeamInterceptor.COMPONENT.set( getComponent() );
try
{
- return methodProxy.invoke(bean, params);
+ return super.proceed();
}
- catch (Error e)
+ finally
{
- throw e;
+ SeamInterceptor.COMPONENT.set(null);
}
- catch (Exception e)
- {
- throw e;
}
- catch (Throwable t)
+
+ });
+ }
+
+ //TODO: copy/paste from JavaBean interceptor
+ Object readResolve()
{
- //only extremely wierd stuff!
- throw new Exception(t);
+ Component comp = getComponent();
+ if (comp==null)
+ {
+ throw new IllegalStateException("No component found: " + getComponentName());
}
- finally
+
+ try
{
- SeamInterceptor.COMPONENT.set(null);
+ return comp.wrap(bean, this);
}
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
}
-
- });
}
}
1.3 +51 -63 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- JavaBeanInterceptor.java 10 Oct 2006 18:12:31 -0000 1.2
+++ JavaBeanInterceptor.java 13 Oct 2006 04:04:48 -0000 1.3
@@ -1,7 +1,6 @@
-//$Id: JavaBeanInterceptor.java,v 1.2 2006/10/10 18:12:31 gavin Exp $
+//$Id: JavaBeanInterceptor.java,v 1.3 2006/10/13 04:04:48 gavin Exp $
package org.jboss.seam.intercept;
-import java.io.Serializable;
import java.lang.reflect.Method;
import net.sf.cglib.proxy.MethodInterceptor;
@@ -16,108 +15,97 @@
* @author Gavin King
*/
public class JavaBeanInterceptor extends RootInterceptor
- implements MethodInterceptor, Serializable
+ implements MethodInterceptor
{
- private boolean recursive = false;
+ private final Object bean;
- public JavaBeanInterceptor(Component component)
+ public JavaBeanInterceptor(Object bean, Component component)
{
super(InterceptorType.ANY);
+ this.bean = bean;
init(component);
}
- public Object intercept(final Object target, final Method method, final Object[] params,
+ public Object intercept(final Object proxy, final Method method, final Object[] params,
final MethodProxy methodProxy) throws Throwable
{
- if (recursive)
- {
- return methodProxy.invokeSuper(target, params);
- }
- recursive = true;
- try
- {
String methodName = method.getName();
if ( "finalize".equals(methodName) )
{
- return methodProxy.invokeSuper(target, params);
+ return methodProxy.invokeSuper(proxy, params);
+ }
+ else if ( "writeReplace".equals(methodName) )
+ {
+ return this;
}
else if ( "sessionDidActivate".equals(methodName) )
{
- callPostActivate(target);
+ callPostActivate();
return null;
}
else if ( "sessionWillPassivate".equals(methodName) )
{
- callPrePassivate(target);
+ callPrePassivate();
return null;
}
else
{
- return interceptInvocation(target, method, params, methodProxy);
- }
- }
- finally
- {
- recursive = false;
+ return interceptInvocation(method, params, methodProxy);
}
+
}
- private void callPrePassivate(final Object target)
+ private void callPrePassivate()
{
- prePassivate( new RootInvocationContext(target, getComponent().getPrePassivateMethod(), new Object[0])
+ prePassivate( new RootInvocationContext(bean, getComponent().getPrePassivateMethod(), new Object[0])
{
public Object proceed() throws Exception
{
- getComponent().callPrePassivateMethod(target);
+ getComponent().callPrePassivateMethod(bean);
return null;
}
} );
}
- private void callPostActivate( final Object target)
+ private void callPostActivate()
{
- postActivate( new RootInvocationContext(target, getComponent().getPostActivateMethod(), new Object[0])
+ postActivate( new RootInvocationContext(bean, getComponent().getPostActivateMethod(), new Object[0])
{
public Object proceed() throws Exception
{
- getComponent().callPostActivateMethod(target);
+ getComponent().callPostActivateMethod(bean);
return null;
}
} );
}
- private Object interceptInvocation(final Object target, final Method method, final Object[] params,
+ private Object interceptInvocation(final Method method, final Object[] params,
final MethodProxy methodProxy) throws Exception
{
- return aroundInvoke( new RootInvocationContext(target, method, params)
- {
+ return aroundInvoke( new RootInvocationContext(bean, method, params, methodProxy) );
+ }
- public Object proceed() throws Exception
+ // TODO: copy/paste from ClientSide interceptor
+ Object readResolve()
{
- try
+ Component comp = getComponent();
+ if (comp==null)
{
- return methodProxy.invokeSuper(target, params);
+ throw new IllegalStateException("No component found: " + getComponentName());
}
- catch (Error e)
+
+ try
{
- throw e;
+ return comp.wrap(bean, this);
}
catch (Exception e)
{
- throw e;
+ throw new RuntimeException(e);
}
- catch (Throwable t)
- {
- //only extremely wierd stuff!
- throw new Exception(t);
- }
- }
-
- } );
}
}
1.3 +5 -0 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.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- RootInterceptor.java 11 Oct 2006 01:22:15 -0000 1.2
+++ RootInterceptor.java 13 Oct 2006 04:04:48 -0000 1.3
@@ -190,4 +190,9 @@
return component;
}
+ protected String getComponentName()
+ {
+ return componentName;
+ }
+
}
1.2 +36 -3 jboss-seam/src/main/org/jboss/seam/intercept/RootInvocationContext.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RootInvocationContext.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/intercept/RootInvocationContext.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- RootInvocationContext.java 10 Oct 2006 18:12:31 -0000 1.1
+++ RootInvocationContext.java 13 Oct 2006 04:04:48 -0000 1.2
@@ -6,27 +6,60 @@
import javax.interceptor.InvocationContext;
+import net.sf.cglib.proxy.MethodProxy;
+
/**
* InvocationContext for use with CGLIB-based interceptors.
*
* @author Gavin King
*
*/
-public abstract class RootInvocationContext implements InvocationContext
+public class RootInvocationContext implements InvocationContext
{
private final Object bean;
private final Method method;
private Object[] params;
private final Map contextData = new HashMap();
+ private final MethodProxy methodProxy;
- public RootInvocationContext(Object bean, Method method, Object[] params)
+ public RootInvocationContext(Object bean, Method method, Object[] params, MethodProxy methodProxy)
{
this.bean = bean;
this.method = method;
this.params = params;
+ this.methodProxy = methodProxy;
+ }
+
+ public RootInvocationContext(Object bean, Method method, Object[] params)
+ {
+ this(bean, method, params, null);
+ }
+
+ public Object proceed() throws Exception
+ {
+ if (methodProxy==null)
+ {
+ throw new UnsupportedOperationException();
}
- public abstract Object proceed() throws Exception;
+ try
+ {
+ return methodProxy.invoke(bean, params);
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ //only extremely wierd stuff!
+ throw new Exception(t);
+ }
+ }
public Object getTarget()
{
1.1 date: 2006/10/13 04:04:48; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/intercept/Proxy.java
Index: Proxy.java
===================================================================
package org.jboss.seam.intercept;
import java.io.Serializable;
public interface Proxy extends Serializable
{
public Object writeReplace();
}
More information about the jboss-cvs-commits
mailing list