[jboss-cvs] JBossAS SVN: r57784 - in projects/aop/trunk/aop/src: main/org/jboss/aop/proxy/container resources/test resources/test/serialization resources/test/serialization/simple test/org/jboss/test/aop test/org/jboss/test/aop/serialization test/org/jboss/test/aop/serialization/simple
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 23 19:17:49 EDT 2006
Author: kabir.khan at jboss.com
Date: 2006-10-23 19:17:41 -0400 (Mon, 23 Oct 2006)
New Revision: 57784
Added:
projects/aop/trunk/aop/src/resources/test/serialization/
projects/aop/trunk/aop/src/resources/test/serialization/simple/
projects/aop/trunk/aop/src/resources/test/serialization/simple/jboss-aop.xml
projects/aop/trunk/aop/src/resources/test/serialization/simple/manual-aop.xml
projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/
projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/
projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/POJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/Proxied.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleInterceptor.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleSerialiizationTestCase.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java
projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ProxyTemplate.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/AOPTestWithSetup.java
Log:
[JBAOP-233] Add the AOP side of things to make the MC serialization test for proxies work
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java 2006-10-23 23:17:41 UTC (rev 57784)
@@ -21,6 +21,7 @@
*/
package org.jboss.aop.proxy.container;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
@@ -49,6 +50,7 @@
import org.jboss.aop.MethodInfo;
import org.jboss.aop.instrument.TransformerCommon;
import org.jboss.aop.introduction.InterfaceIntroduction;
+import org.jboss.aop.metadata.SimpleMetaData;
import org.jboss.aop.util.JavassistMethodHashing;
@@ -232,6 +234,8 @@
addMethodFromTemplate(template, "setInstanceAdvisor", instanceAdvisorSetterBody());
addMethodFromTemplate(template, "getInstanceAdvisor", instanceAdvisorGetterBody());
+ addMethodFromTemplate(template, "writeObject", writeObjectBody());
+ addMethodFromTemplate(template, "readObject", readObjectBody(superclass));
return proxy;
}
@@ -271,6 +275,33 @@
"}";
}
+ private String writeObjectBody()
+ {
+ return
+ "{" +
+ " $1.writeObject(delegate);" +
+ " $1.writeObject(mixins);" +
+ " $1.writeObject(metadata);"+
+ " $1.writeObject(classAdvisor.getClazz());" +
+ "}";
+// TODO add support for the instance advisors
+ }
+
+ private String readObjectBody(CtClass superclass)
+ {
+ return
+ "{" +
+ " delegate = (" + superclass.getName() + ")$1.readObject();" +
+ " mixins = (Object[])$1.readObject();" +
+ " metadata = (org.jboss.aop.metadata.SimpleMetaData)$1.readObject();" +
+ " java.lang.Class clazz = (java.lang.Class)$1.readObject();" +
+ " org.jboss.aop.AspectManager manager = org.jboss.aop.AspectManager.getTopLevelAspectManager();" +
+ " classAdvisor = manager.findAdvisor(clazz);" +
+ " currentAdvisor = classAdvisor;" +
+ "}";
+ //TODO add support for instance advisors
+ }
+
private CtField addFieldFromTemplate(CtClass template, String name) throws Exception
{
return addFieldFromTemplate(template, name, null);
@@ -281,7 +312,7 @@
CtField templateField = template.getField(name);
CtClass fieldType = (type == null) ? templateField.getType() : type;
CtField field = new CtField(fieldType, name, proxy);
- field.setModifiers(Modifier.PRIVATE);
+ field.setModifiers(templateField.getModifiers());
proxy.addField(field);
return field;
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ProxyTemplate.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ProxyTemplate.java 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ProxyTemplate.java 2006-10-23 23:17:41 UTC (rev 57784)
@@ -21,7 +21,10 @@
*/
package org.jboss.aop.proxy.container;
+import java.io.IOException;
+
import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
import org.jboss.aop.InstanceAdvisor;
import org.jboss.aop.metadata.SimpleMetaData;
@@ -36,9 +39,9 @@
{
}
- private Advisor classAdvisor;
- private InstanceAdvisor instanceAdvisor;
- protected volatile Advisor currentAdvisor;
+ private transient Advisor classAdvisor;
+ private transient InstanceAdvisor instanceAdvisor;
+ protected volatile transient Advisor currentAdvisor;
private Object delegate;
private Object[] mixins; // Do not remove this
@@ -103,4 +106,26 @@
return instanceAdvisor;
}
+ private void writeObject(java.io.ObjectOutputStream out) throws IOException
+ {
+ out.writeObject(delegate);
+ out.writeObject(mixins);
+ out.writeObject(metadata);
+ out.writeObject(classAdvisor.getClazz());
+ //TODO add support for the instance advisors
+ }
+
+ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ delegate = in.readObject();
+ mixins = (Object[])in.readObject();
+ metadata = (SimpleMetaData)in.readObject();
+
+ Class clazz = (Class)in.readObject();
+ AspectManager manager = AspectManager.getTopLevelAspectManager();
+ classAdvisor = manager.findAdvisor(clazz);
+ currentAdvisor = classAdvisor;
+ //TODO add support for instance advisors
+
+ }
}
Added: projects/aop/trunk/aop/src/resources/test/serialization/simple/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/serialization/simple/jboss-aop.xml 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/resources/test/serialization/simple/jboss-aop.xml 2006-10-23 23:17:41 UTC (rev 57784)
@@ -0,0 +1,6 @@
+<aop>
+ <interceptor class="org.jboss.test.aop.serialization.simple.SimpleInterceptor"/>
+ <bind pointcut="execution(* org.jboss.test.aop.serialization.simple.POJO->someMethod())">
+ <interceptor-ref name="org.jboss.test.aop.serialization.simple.SimpleInterceptor"/>
+ </bind>
+</aop>
Added: projects/aop/trunk/aop/src/resources/test/serialization/simple/manual-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/serialization/simple/manual-aop.xml 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/resources/test/serialization/simple/manual-aop.xml 2006-10-23 23:17:41 UTC (rev 57784)
@@ -0,0 +1,5 @@
+<aop>
+ <bind pointcut="execution(* org.jboss.test.aop.serialization.simple.Proxied->someMethod())">
+ <interceptor-ref name="org.jboss.test.aop.serialization.simple.SimpleInterceptor"/>
+ </bind>
+</aop>
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/AOPTestWithSetup.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/AOPTestWithSetup.java 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/AOPTestWithSetup.java 2006-10-23 23:17:41 UTC (rev 57784)
@@ -56,7 +56,6 @@
protected URL getURLRelativeToProjectRoot(String relativePath) throws IOException
{
URL url = this.getClass().getProtectionDomain().getCodeSource().getLocation();
- System.out.println("class url: " + url);
String location = url.toString();
int index = location.indexOf("/output/");
location = location.substring(0, index);
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/POJO.java 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/POJO.java 2006-10-23 23:17:41 UTC (rev 57784)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.serialization.simple;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJO implements Serializable
+{
+ public void someMethod() throws Exception
+ {
+
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/Proxied.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/Proxied.java 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/Proxied.java 2006-10-23 23:17:41 UTC (rev 57784)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.serialization.simple;
+
+import java.io.Serializable;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Proxied implements Serializable
+{
+ public void someMethod()
+ {
+
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleInterceptor.java 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleInterceptor.java 2006-10-23 23:17:41 UTC (rev 57784)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.serialization.simple;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleInterceptor implements Interceptor
+{
+ public static boolean invoked;
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ invoked = true;
+ return invocation.invokeNext();
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleSerialiizationTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleSerialiizationTestCase.java 2006-10-23 23:15:54 UTC (rev 57783)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/serialization/simple/SimpleSerialiizationTestCase.java 2006-10-23 23:17:41 UTC (rev 57784)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.serialization.simple;
+
+import java.net.URL;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.aop.Advised;
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.aop.proxy.container.AOPProxyFactoryParameters;
+import org.jboss.aop.proxy.container.AspectManaged;
+import org.jboss.aop.proxy.container.GeneratedAOPProxyFactory;
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ * A test case to test that woven objects can be serialized. This does not take into
+ * account anything deployed "below" the main aspect manager or per instance aspects.
+ * The main idea is to test reattachment within the same vm
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleSerialiizationTestCase extends AOPTestWithSetup
+{
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("SimpleSerialiizationTestCase");
+ suite.addTestSuite(SimpleSerialiizationTestCase.class);
+ return suite;
+ }
+
+ public SimpleSerialiizationTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testWoven() throws Exception
+ {
+ SimpleInterceptor.invoked = false;
+ POJO pojo = new POJO();
+ pojo.someMethod();
+ assertTrue(SimpleInterceptor.invoked);
+
+ byte[] bytes = serialize(pojo);
+ POJO newPojo = (POJO)deserialize(bytes);
+
+ assertNotNull(newPojo);
+ SimpleInterceptor.invoked = false;
+ newPojo.someMethod();
+ assertTrue(SimpleInterceptor.invoked);
+
+ Proxied proxied = new Proxied();
+ SimpleInterceptor.invoked = false;
+ proxied.someMethod();
+ assertFalse(SimpleInterceptor.invoked);
+
+ Advisor advisor = ((Advised)pojo)._getAdvisor();
+ Advisor newAdvisor = ((Advised)newPojo)._getAdvisor();
+ assertSame(advisor, newAdvisor);
+ }
+
+ public void testProxy() throws Exception
+ {
+ Proxied tgt = new Proxied();
+ URL url = getURLRelativeToProjectRoot("/src/resources/test/serialization/simple/manual-aop.xml");
+ AspectXmlLoader.deployXML(url);
+
+ AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+ params.setTarget(tgt);
+ GeneratedAOPProxyFactory factory = new GeneratedAOPProxyFactory();
+ Proxied proxied = (Proxied)factory.createAdvisedProxy(params);
+
+ proxied.someMethod();
+ assertTrue(SimpleInterceptor.invoked);
+
+ byte[] bytes = serialize(proxied);
+ Proxied newProxied = (Proxied)deserialize(bytes);
+
+ assertNotNull(newProxied);
+ SimpleInterceptor.invoked = false;
+ newProxied.someMethod();
+ assertTrue(SimpleInterceptor.invoked);
+
+ Advisor advisor = ((AspectManaged)proxied).getAdvisor();
+ Advisor newAdvisor = ((AspectManaged)newProxied).getAdvisor();
+ assertSame(advisor, newAdvisor);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list