[jboss-cvs] JBossAS SVN: r67173 - in projects/aop/trunk/aop/src: main/org/jboss/aop/instrument and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 16 09:59:22 EST 2007
Author: kabir.khan at jboss.com
Date: 2007-11-16 09:59:22 -0500 (Fri, 16 Nov 2007)
New Revision: 67173
Added:
projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/
projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Base.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Child.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/ChildInterface.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/SuperClassIsAdvisedByProxyTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/TestInterceptor.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java
projects/aop/trunk/aop/src/resources/test/regression/jboss-aop.xml
Log:
[JBAOP-484] Take into account that the super class might not have a ClassAdvisor associated with it, but a ClassContainer or something like that
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java 2007-11-16 13:49:01 UTC (rev 67172)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -44,6 +44,9 @@
protected ConcurrentHashMap<String, String> generatedClasses = new ConcurrentHashMap<String, String>();
protected ConcurrentHashMap<String, Boolean> localResources = new ConcurrentHashMap<String, Boolean>();
+
+ /** Classnames of classes that have been loaded, but were not woven */
+ protected ConcurrentHashMap<String, Boolean> loadedButNotWovenClasses = new ConcurrentHashMap<String, Boolean>();
static
{
@@ -180,6 +183,15 @@
return clazz;
}
+ public void setClassLoadedButNotWoven(String classname)
+ {
+ loadedButNotWovenClasses.put(classname, Boolean.TRUE);
+ }
+
+ public boolean isClassLoadedButNotWoven(String classname)
+ {
+ return loadedButNotWovenClasses.get(classname) == Boolean.TRUE;
+ }
public static AOPClassPool createAOPClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
{
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-11-16 13:49:01 UTC (rev 67172)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -44,8 +44,10 @@
import javassist.Modifier;
import javassist.NotFoundException;
+import org.jboss.aop.Advisor;
import org.jboss.aop.AspectManager;
import org.jboss.aop.CallerConstructorInfo;
+import org.jboss.aop.ClassAdvisor;
import org.jboss.aop.GeneratedClassAdvisor;
import org.jboss.aop.InstanceAdvisor;
import org.jboss.aop.JoinPointInfo;
@@ -517,7 +519,19 @@
else
{
AspectManager manager = info.getAdvisor().getManager();
- advisorClass = manager.getAdvisor(info.getClazz()).getClass();
+ try
+ {
+ advisorClass = manager.getAdvisor(info.getClazz()).getClass();
+ }
+ catch(ClassCastException e)
+ {
+ Advisor advisor = manager.findAdvisor(info.getClazz());
+ if (advisor != null && !( advisor instanceof ClassAdvisor))
+ {
+ //The advisor is a ClassContainer or something like that, so ignore this joinpoint
+ return;
+ }
+ }
}
try
@@ -2204,4 +2218,9 @@
}
}
}
+
+ protected Field getJoinpointField()
+ {
+ return joinpointField;
+ }
}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java 2007-11-16 13:49:01 UTC (rev 67172)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -73,11 +73,15 @@
{
super(advisor, info, getParameters(info),
info.getMethod().getParameterTypes().length, false);
- if (!info.getUnadvisedMethod().getReturnType().equals(Void.TYPE))
+ if (super.getJoinpointField() != null)
{
- returnType = new WeakReference<Class<?>>(info.getUnadvisedMethod().getReturnType());
+ if (!info.getUnadvisedMethod().getReturnType().equals(Void.TYPE))
+ {
+ returnType = new WeakReference<Class<?>>(info.getUnadvisedMethod().getReturnType());
+ }
+ hasTargetObject = !Modifier.isStatic(info.getMethod().getModifiers());
}
- hasTargetObject = !Modifier.isStatic(info.getMethod().getModifiers());
+
}
private static JoinPointParameters getParameters(MethodInfo info)
Modified: projects/aop/trunk/aop/src/resources/test/regression/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/regression/jboss-aop.xml 2007-11-16 13:49:01 UTC (rev 67172)
+++ projects/aop/trunk/aop/src/resources/test/regression/jboss-aop.xml 2007-11-16 14:59:22 UTC (rev 67173)
@@ -171,4 +171,12 @@
</bind>
<prepare expr="all(org.jboss.test.aop.regression.jbaop442instancedomain.POJO)"/>
+
+ <bind pointcut="execution(* org.jboss.test.aop.regression.jbaop484superproxyadvised.Child->*(..))">
+ <interceptor class="org.jboss.test.aop.regression.jbaop484superproxyadvised.TestInterceptor"/>
+ </bind>
+ <bind pointcut="execution(* $instanceof{org.jboss.test.aop.regression.jbaop484superproxyadvised.ChildInterface}->$implements{org.jboss.test.aop.regression.jbaop484superproxyadvised.ChildInterface}(..))">
+ <interceptor class="org.jboss.test.aop.regression.jbaop484superproxyadvised.TestInterceptor"/>
+ </bind>
+
</aop>
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Base.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Base.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Base.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -0,0 +1,46 @@
+/*
+* 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.regression.jbaop484superproxyadvised;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Base
+{
+ public static boolean baseInvoked;
+ public void baseOnly()
+ {
+ baseInvoked = true;
+ }
+
+ public void baseOverridden()
+ {
+ baseInvoked = true;
+ }
+
+ public void setProperty(int i)
+ {
+ baseInvoked = true;
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Child.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Child.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/Child.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -0,0 +1,41 @@
+/*
+* 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.regression.jbaop484superproxyadvised;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Child extends Base
+{
+ public static boolean childInvoked;
+ public void childOnly()
+ {
+ childInvoked = true;
+ }
+
+ public void baseOverridden()
+ {
+ childInvoked = true;
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/ChildInterface.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/ChildInterface.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/ChildInterface.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.regression.jbaop484superproxyadvised;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 44932 $
+ */
+public interface ChildInterface
+{
+ void childOnly();
+
+ void baseOverridden();
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/SuperClassIsAdvisedByProxyTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/SuperClassIsAdvisedByProxyTestCase.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/SuperClassIsAdvisedByProxyTestCase.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -0,0 +1,201 @@
+/*
+* 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.regression.jbaop484superproxyadvised;
+
+import org.jboss.aop.Advised;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AdviceBinding;
+import org.jboss.aop.pointcut.ast.ParseException;
+import org.jboss.aop.proxy.container.AOPProxyFactory;
+import org.jboss.aop.proxy.container.AOPProxyFactoryParameters;
+import org.jboss.aop.proxy.container.AspectManaged;
+import org.jboss.aop.proxy.container.GeneratedAOPProxyFactory;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SuperClassIsAdvisedByProxyTestCase extends TestCase
+{
+ AOPProxyFactory proxyFactory = new GeneratedAOPProxyFactory();
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("SuperClassIsAdvisedByProxyTestCase");
+ suite.addTestSuite(SuperClassIsAdvisedByProxyTestCase.class);
+ return suite;
+ }
+
+ public SuperClassIsAdvisedByProxyTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testClassAdvisorAndNotInstanceAdvisor() throws Exception
+ {
+ System.out.println("== Testing proxy");
+ Base base = new Base();
+ assertFalse(base instanceof Advised);
+
+ String name = addBinding("execution(* org.jboss.test.aop.regression.jbaop484superproxyadvised.Base->*(..))", TestInterceptor.class);
+ try
+ {
+ Object proxy = createProxy(base);
+ assertTrue(proxy instanceof AspectManaged);
+ assertFalse(proxy instanceof Advised);
+
+ TestInterceptor.reset();
+ base.baseOnly();
+ assertEquals(0, TestInterceptor.interceptions);
+
+ TestInterceptor.reset();
+ base.baseOverridden();
+ assertEquals(0, TestInterceptor.interceptions);
+
+ TestInterceptor.reset();
+ ((Base)proxy).baseOnly();
+ assertEquals(1, TestInterceptor.interceptions);
+ assertNotNull(TestInterceptor.invoked);
+ assertEquals("baseOnly", TestInterceptor.invoked.getName());
+
+ TestInterceptor.reset();
+ ((Base)proxy).baseOverridden();
+ assertEquals(1, TestInterceptor.interceptions);
+ assertNotNull(TestInterceptor.invoked);
+ assertEquals("baseOverridden", TestInterceptor.invoked.getName());
+ }
+ finally
+ {
+ removeBinding(name);
+ }
+
+ System.out.println("== Testing advised child");
+ name = addBinding("execution(* org.jboss.test.aop.regression.jbaop484superproxyadvised.Base->*(..))", TestInterceptor.class);
+ try
+ {
+ Child plainChild = new Child();
+ assertTrue(plainChild instanceof Advised);
+ assertFalse(plainChild instanceof AspectManaged);
+
+ TestInterceptor.reset();
+ plainChild.baseOnly();
+ assertEquals(0, TestInterceptor.interceptions);
+
+ TestInterceptor.reset();
+ plainChild.childOnly();
+ assertEquals(1, TestInterceptor.interceptions);
+
+ TestInterceptor.reset();
+ plainChild.baseOverridden();
+ assertEquals(1, TestInterceptor.interceptions);
+ }
+ finally
+ {
+ removeBinding(name);
+ }
+
+ System.out.println("== Testing proxied child");
+ name = addBinding("execution(* org.jboss.test.aop.regression.jbaop484superproxyadvised.Base->*(..))", TestInterceptor.class);
+ Object proxy = null;
+ try
+ {
+
+ Child proxiedChild = new Child();
+ assertTrue(proxiedChild instanceof Advised);
+ assertFalse(proxiedChild instanceof AspectManaged);
+
+ proxy = createProxy(proxiedChild, new Class[] {ChildInterface.class});
+
+ TestInterceptor.reset();
+ ((Child)proxy).baseOnly();
+ assertEquals(1, TestInterceptor.interceptions);
+ assertNotNull(TestInterceptor.invoked);
+ assertEquals("baseOnly", TestInterceptor.invoked.getName());
+
+ TestInterceptor.reset();
+ ((Child)proxy).childOnly();
+ assertEquals(2, TestInterceptor.interceptions);
+ assertNotNull(TestInterceptor.invoked);
+ assertEquals("childOnly", TestInterceptor.invoked.getName());
+
+ TestInterceptor.reset();
+ ((Child)proxy).baseOverridden();
+ assertEquals(2, TestInterceptor.interceptions);
+ assertNotNull(TestInterceptor.invoked);
+ assertEquals("baseOverridden", TestInterceptor.invoked.getName());
+ }
+ finally
+ {
+ removeBinding(name);
+ }
+
+ TestInterceptor.reset();
+ ((Child)proxy).baseOnly();
+ assertEquals(1, TestInterceptor.interceptions);
+
+ }
+
+ private String addBinding(String pointcut, Class interceptor) throws ParseException
+ {
+ AdviceBinding binding = new AdviceBinding(pointcut, null);
+ String name = binding.getName();
+ binding.addInterceptor(interceptor);
+ AspectManager.instance().addBinding(binding);
+ return name;
+ }
+
+ private void removeBinding(String name)
+ {
+ AspectManager.instance().removeBinding(name);
+ }
+
+ private Object createProxy(Object target)
+ {
+ AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+ params.setProxiedClass(target.getClass());
+ params.setTarget(target);
+ return proxyFactory.createAdvisedProxy(params);
+ }
+
+ protected Object createProxy(Object target, Class[] interfaces) throws Exception
+ {
+ AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+ params.setProxiedClass(target.getClass());
+ params.setInterfaces(interfaces);
+ params.setTarget(target);
+ return proxyFactory.createAdvisedProxy(params);
+ }
+
+}
+
+
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/TestInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/TestInterceptor.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/regression/jbaop484superproxyadvised/TestInterceptor.java 2007-11-16 14:59:22 UTC (rev 67173)
@@ -0,0 +1,60 @@
+/*
+* 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.regression.jbaop484superproxyadvised;
+
+import java.lang.reflect.Method;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestInterceptor implements Interceptor
+{
+ public static int interceptions;
+ public static Method invoked;
+
+ public String getName()
+ {
+ return null;
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ interceptions++;
+ if (invocation instanceof MethodInvocation)
+ {
+ invoked = ((MethodInvocation)invocation).getMethod();
+ }
+ return invocation.invokeNext();
+ }
+
+ public static void reset()
+ {
+ interceptions = 0;
+ invoked = null;
+ }
+}
More information about the jboss-cvs-commits
mailing list