[jboss-cvs] JBossAS SVN: r59556 - in projects/aop/trunk/aop/src: main/org/jboss/aop/proxy/container and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 11 18:41:54 EST 2007


Author: kabir.khan at jboss.com
Date: 2007-01-11 18:41:48 -0500 (Thu, 11 Jan 2007)
New Revision: 59556

Added:
   projects/aop/trunk/aop/src/resources/test/container/
   projects/aop/trunk/aop/src/resources/test/container/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Child.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Parent.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestInterceptor.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java
Log:
[JBAOP-340] Enable chain overriding for container proxies

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java	2007-01-11 23:41:48 UTC (rev 59556)
@@ -38,7 +38,6 @@
 import org.jboss.aop.util.ConstructorComparator;
 import org.jboss.aop.util.FieldComparator;
 import org.jboss.aop.util.MethodHashing;
-import gnu.trove.TLongObjectHashMap;
 
 /**
  * Comment
@@ -48,6 +47,8 @@
  */
 public class ClassContainer extends Advisor
 {
+   private boolean chainOverridingForInheritedMethods;
+   
    public ClassContainer(String name, AspectManager manager)
    {
       super(name, manager);
@@ -262,4 +263,23 @@
 
       doesHaveAspects = adviceBindings.size() > 0;
    }
+
+   /**
+    * @return the value of chainOverridingForInheritedMethods
+    * @see Advisor#chainOverridingForInheritedMethods()
+    */
+   @Override
+   public boolean chainOverridingForInheritedMethods()
+   {
+      return chainOverridingForInheritedMethods;
+   }
+
+   /**
+    * @param overriding the new value of chainOverridingForInheritedMethods
+    * @see Advisor#chainOverridingForInheritedMethods()
+    */
+   public void setChainOverridingForInheritedMethods(boolean overriding)
+   {
+      this.chainOverridingForInheritedMethods = overriding;
+   }
 }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java	2007-01-11 23:41:48 UTC (rev 59556)
@@ -207,6 +207,11 @@
       return super.getPerClassAspect(def);
    }
 
+   /**
+    * @return true always
+    * @see Advisor#chainOverridingForInheritedMethods()
+    */
+   @Override
    public boolean chainOverridingForInheritedMethods()
    {
       return true;

Added: projects/aop/trunk/aop/src/resources/test/container/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/container/jboss-aop.xml	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/resources/test/container/jboss-aop.xml	2007-01-11 23:41:48 UTC (rev 59556)
@@ -0,0 +1,6 @@
+<aop>
+   <interceptor class="org.jboss.test.aop.container.TestInterceptor"/>
+   <bind pointcut="execution(* @org.jboss.test.aop.container.Annotation->*(..))">
+   	<interceptor-ref name="org.jboss.test.aop.container.TestInterceptor"/>
+   </bind>
+</aop>
\ No newline at end of file

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Annotation.java	2007-01-11 23:41:48 UTC (rev 59556)
@@ -0,0 +1,31 @@
+/*
+* 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.container;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public @interface Annotation {
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Child.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Child.java	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Child.java	2007-01-11 23:41:48 UTC (rev 59556)
@@ -0,0 +1,36 @@
+/*
+* 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.container;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Annotation
+public class Child extends Parent
+{
+
+   public void childMethod()
+   {
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/ContainerTestCase.java	2007-01-11 23:41:48 UTC (rev 59556)
@@ -0,0 +1,104 @@
+/*
+  * 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.container;
+
+import java.lang.reflect.Method;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.ClassContainer;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.test.aop.AOPTestWithSetup;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+*
+* @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+* @version $Revision: 45977 $
+*/
+public class ContainerTestCase extends AOPTestWithSetup
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("ContainerTestCase");
+      suite.addTestSuite(ContainerTestCase.class);
+      return suite;
+   }
+
+   public ContainerTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testContainerWithNoChainOverriding() throws Throwable
+   {
+      invokeContainer(false);
+   }
+
+   public void testContainerWithChainOverriding() throws Throwable
+   {
+      invokeContainer(true);
+   }
+
+   public void invokeContainer(boolean overriding) throws Throwable
+   {
+         AspectManager manager = AspectManager.instance();
+         ClassContainer container = new ClassContainer("X", manager);
+         container.setChainOverridingForInheritedMethods(overriding);
+         container.setClass(Child.class);
+         container.initializeClassContainer();
+         Child child = new Child();
+         
+         MethodInvocation invocation = getMethodInvocation(container, "childMethod", child);
+         TestInterceptor.invoked = false;
+         container.dynamicInvoke(child, invocation);
+         assertTrue(TestInterceptor.invoked);
+         
+         invocation = getMethodInvocation(container, "parentMethod", child);
+         TestInterceptor.invoked = false;
+         container.dynamicInvoke(child, invocation);
+         assertEquals(overriding, TestInterceptor.invoked);
+   }
+   
+   private MethodInvocation getMethodInvocation(ClassContainer advisor, String methodName, Object target) throws Exception
+   {
+      Method method = target.getClass().getMethod(methodName, new Class[0]);
+      long hash = MethodHashing.calculateHash(method);
+      MethodInfo info = advisor.getMethodInfo(hash);
+      Interceptor[] interceptors = info.getInterceptors();
+      MethodInvocation invocation = new MethodInvocation(interceptors, hash, method, method, advisor);
+      invocation.setTargetObject(target);
+      invocation.setArguments(new Object[0]);
+      return invocation;
+   }
+}
+

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Parent.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Parent.java	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/Parent.java	2007-01-11 23:41:48 UTC (rev 59556)
@@ -0,0 +1,34 @@
+/*
+* 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.container;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Parent
+{
+   public void parentMethod() 
+   {
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestInterceptor.java	2007-01-11 22:16:29 UTC (rev 59555)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/container/TestInterceptor.java	2007-01-11 23:41:48 UTC (rev 59556)
@@ -0,0 +1,47 @@
+/*
+* 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.container;
+
+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 TestInterceptor implements Interceptor
+{
+   public static boolean invoked = true;
+   
+   public String getName()
+   {
+      return TestInterceptor.class.getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      invoked = true;
+      return invocation.invokeNext();
+   }
+
+}




More information about the jboss-cvs-commits mailing list