]> source.dussan.org Git - aspectj.git/commitdiff
AOPAlliance adapter sample
authoracolyer <acolyer>
Mon, 17 May 2004 09:00:54 +0000 (09:00 +0000)
committeracolyer <acolyer>
Mon, 17 May 2004 09:00:54 +0000 (09:00 +0000)
24 files changed:
docs/developer/ajdt/ajdt.core.workitems.txt
docs/sandbox/aopalliance/.cvsignore [new file with mode: 0644]
docs/sandbox/aopalliance/aopalliance.jar [new file with mode: 0644]
docs/sandbox/aopalliance/lib/aj-aopalliance.jar [new file with mode: 0644]
docs/sandbox/aopalliance/readme.txt [new file with mode: 0644]
docs/sandbox/aopalliance/src/org/aspectj/aopalliance/AOPAllianceAdapter.aj [new file with mode: 0644]
docs/sandbox/aopalliance/src/org/aspectj/aopalliance/ConstructorInvocationClosure.java [new file with mode: 0644]
docs/sandbox/aopalliance/src/org/aspectj/aopalliance/InvocationJoinPointClosure.java [new file with mode: 0644]
docs/sandbox/aopalliance/src/org/aspectj/aopalliance/JoinPointClosure.java [new file with mode: 0644]
docs/sandbox/aopalliance/src/org/aspectj/aopalliance/MethodInvocationClosure.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/AOPAllianceAdapterTest.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/AllTests.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/ConstructorInvocationClosureTest.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/Hello.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloAOPAllianceAdapter.aj [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloConstructionInterceptor.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloMethodInterceptor.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/InvocationJoinPointClosureTest.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/JoinPointClosureTest.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MethodInvocationClosureTest.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockConstructorSignature.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockJoinPoint.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockMethodSignature.java [new file with mode: 0644]
docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockSignature.java [new file with mode: 0644]

index 92ae2f8e6a00467dabb8b700a22af1b14bdfc7f1..866931ff85f572a32e605f6a7d2c1ebfd47ef744 100644 (file)
@@ -248,7 +248,7 @@ I'm not sure what user interface features need this...
 17) Version upgrade
 =============================================================================
 17.1) port to Eclipse 3.0 M9
-17.2) port to Eclipse 2.0 final
+17.2) port to Eclipse 3.0 final
 
 18) JDT DEBUG
 =============================================================================
diff --git a/docs/sandbox/aopalliance/.cvsignore b/docs/sandbox/aopalliance/.cvsignore
new file mode 100644 (file)
index 0000000..ba077a4
--- /dev/null
@@ -0,0 +1 @@
+bin
diff --git a/docs/sandbox/aopalliance/aopalliance.jar b/docs/sandbox/aopalliance/aopalliance.jar
new file mode 100644 (file)
index 0000000..578b1a0
Binary files /dev/null and b/docs/sandbox/aopalliance/aopalliance.jar differ
diff --git a/docs/sandbox/aopalliance/lib/aj-aopalliance.jar b/docs/sandbox/aopalliance/lib/aj-aopalliance.jar
new file mode 100644 (file)
index 0000000..b41ecaa
Binary files /dev/null and b/docs/sandbox/aopalliance/lib/aj-aopalliance.jar differ
diff --git a/docs/sandbox/aopalliance/readme.txt b/docs/sandbox/aopalliance/readme.txt
new file mode 100644 (file)
index 0000000..2c6083f
--- /dev/null
@@ -0,0 +1,21 @@
+This example shows how to call an AOP Alliance aspect (interceptor) from
+within AspectJ. 
+
+The contents of the src directory comprise some library classes plus an
+abstract aspect that can be extended to create AOP Alliance invoking concrete
+aspects (provide an implementation of getMethodInterceptor() and the 
+targetJP() pointcut in your concrete subaspect). 
+
+The contents of the testsrc directory supply test cases, and in so doing a
+sample of using the AOPAllianceAdapter aspect (HelloAOPAllianceAdapter aspect).
+
+With the docs module checked out of the AspectJ CVS tree, I build and test 
+these AOPAlliance samples as follows:
+
+Create an AJDT project, "AOPAlliance" (you can call it whatever you like).
+Add the file lib/aopalliance.jar to the build path. Remove the default source
+directory that will have been set up for the project, and add a "src" directory.
+When doing this click "advanced" and set it up as a link to the src folder in
+this directory. Do the same for "testsrc". Now you have an AJDT project that
+should build and take its source from this directory. To run the tests, select
+the "AllTests.java" file in the AJDT project and choose "run as junit."
diff --git a/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/AOPAllianceAdapter.aj b/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/AOPAllianceAdapter.aj
new file mode 100644 (file)
index 0000000..789e18f
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************\r
+ * Copyright (c) 2004 IBM Corporation and others.\r
+ * All rights reserved. This program and the accompanying materials \r
+ * are made available under the terms of the Common Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/cpl-v10.html\r
+ * \r
+ * Contributors:\r
+ *     IBM Corporation - initial API and implementation\r
+ *******************************************************************************/\r
+package org.aspectj.aopalliance;\r
+\r
+import org.aspectj.lang.SoftException;\r
+import org.aopalliance.intercept.MethodInterceptor;\r
+import org.aopalliance.intercept.ConstructorInterceptor;\r
+\r
+public abstract aspect AOPAllianceAdapter {\r
+       \r
+       /**\r
+        * Return the interceptor to use at method execution join points.\r
+        * Must be overriden by subclasses.\r
+        * @return MethodInterceptor, or null if no method advice required\r
+        */\r
+       protected abstract MethodInterceptor getMethodInterceptor();\r
+       \r
+       /**\r
+        * Return the interceptor to use at constructor execution join points.\r
+        * May be overriden by subclasses.\r
+        * @return ConstructorInterceptor, or null if no constructor advice required\r
+        */\r
+       protected ConstructorInterceptor getConstructorInterceptor() {\r
+         return null;\r
+       }\r
+       \r
+       protected abstract pointcut targetJoinPoint();\r
+       \r
+       pointcut methodExecution() : execution(* *(..));\r
+       pointcut constructorExecution() : execution(new(..));\r
+       \r
+       Object around() : targetJoinPoint() && methodExecution() {\r
+               MethodInvocationClosure mic = new MethodInvocationClosure(thisJoinPoint) {\r
+                       public Object execute() { return proceed();}\r
+               };\r
+               MethodInterceptor mInt = getMethodInterceptor();\r
+               if (mInt != null) {\r
+                       try {\r
+                               return mInt.invoke(mic);\r
+                       } catch (Throwable t) {\r
+                               throw new SoftException(t);\r
+                       }\r
+               } else {\r
+                       return proceed();\r
+               }\r
+       }\r
+       \r
+       Object around() : targetJoinPoint() && constructorExecution() {\r
+               ConstructorInvocationClosure cic = new ConstructorInvocationClosure(thisJoinPoint) {\r
+                       public Object execute() { proceed(); return thisJoinPoint.getThis();}\r
+               };\r
+               ConstructorInterceptor cInt = getConstructorInterceptor();\r
+               if (cInt != null) {\r
+                       try {\r
+                               return cInt.construct(cic);\r
+                       } catch (Throwable t) {\r
+                               throw new SoftException(t);\r
+                       }\r
+               } else {\r
+                       return proceed();\r
+               }\r
+       }\r
+       \r
+}\r
diff --git a/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/ConstructorInvocationClosure.java b/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/ConstructorInvocationClosure.java
new file mode 100644 (file)
index 0000000..0d1541e
--- /dev/null
@@ -0,0 +1,32 @@
+/*******************************************************************************\r
+ * Copyright (c) 2004 IBM Corporation and others.\r
+ * All rights reserved. This program and the accompanying materials \r
+ * are made available under the terms of the Common Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/cpl-v10.html\r
+ * \r
+ * Contributors:\r
+ *     IBM Corporation - initial API and implementation\r
+ *******************************************************************************/\r
+package org.aspectj.aopalliance;\r
+\r
+import java.lang.reflect.Constructor;\r
+\r
+import org.aopalliance.intercept.ConstructorInvocation;\r
+import org.aspectj.lang.JoinPoint;\r
+\r
+public abstract class ConstructorInvocationClosure extends InvocationJoinPointClosure\r
+               implements ConstructorInvocation {\r
+\r
+       public ConstructorInvocationClosure(JoinPoint jp) {\r
+               super(jp);\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.MethodInvocation#getMethod()\r
+        */\r
+       public Constructor getConstructor() {\r
+               return (Constructor) getStaticPart();\r
+       }\r
+\r
+}\r
diff --git a/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/InvocationJoinPointClosure.java b/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/InvocationJoinPointClosure.java
new file mode 100644 (file)
index 0000000..efbea5b
--- /dev/null
@@ -0,0 +1,54 @@
+/*******************************************************************************\r
+ * Copyright (c) 2004 IBM Corporation and others.\r
+ * All rights reserved. This program and the accompanying materials \r
+ * are made available under the terms of the Common Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/cpl-v10.html\r
+ * \r
+ * Contributors:\r
+ *     IBM Corporation - initial API and implementation\r
+ *******************************************************************************/\r
+package org.aspectj.aopalliance;\r
+\r
+import java.lang.reflect.AccessibleObject;\r
+\r
+import org.aopalliance.intercept.Invocation;\r
+import org.aspectj.lang.JoinPoint;\r
+import org.aspectj.lang.reflect.CodeSignature;\r
+import org.aspectj.lang.reflect.ConstructorSignature;\r
+import org.aspectj.lang.reflect.MethodSignature;\r
+\r
+public abstract class InvocationJoinPointClosure extends JoinPointClosure implements Invocation {\r
+\r
+       public InvocationJoinPointClosure(JoinPoint jp) {\r
+               super(jp);\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.Joinpoint#getStaticPart()\r
+        */\r
+       public AccessibleObject getStaticPart() {\r
+               CodeSignature cSig = (CodeSignature)jp.getSignature();\r
+               Class clazz = cSig.getDeclaringType();\r
+               AccessibleObject ret = null;\r
+               try {\r
+                       if (cSig instanceof MethodSignature) {\r
+                               ret = clazz.getMethod(cSig.getName(),cSig.getParameterTypes());                         \r
+                       } else if (cSig instanceof ConstructorSignature) {\r
+                               ret = clazz.getConstructor(cSig.getParameterTypes());\r
+                       }\r
+               } catch (NoSuchMethodException mEx) {\r
+                       throw new UnsupportedOperationException(\r
+                                       "Can't find member " + cSig.toLongString());\r
+               }\r
+               return ret;\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.Invocation#getArguments()\r
+        */\r
+       public Object[] getArguments() {\r
+               return jp.getArgs();\r
+       }       \r
+\r
+}\r
diff --git a/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/JoinPointClosure.java b/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/JoinPointClosure.java
new file mode 100644 (file)
index 0000000..a995ff1
--- /dev/null
@@ -0,0 +1,50 @@
+/*******************************************************************************\r
+ * Copyright (c) 2004 IBM Corporation and others.\r
+ * All rights reserved. This program and the accompanying materials \r
+ * are made available under the terms of the Common Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/cpl-v10.html\r
+ * \r
+ * Contributors:\r
+ *     IBM Corporation - initial API and implementation\r
+ *******************************************************************************/\r
+package org.aspectj.aopalliance;\r
+\r
+import java.lang.reflect.AccessibleObject;\r
+\r
+import org.aopalliance.intercept.Joinpoint;\r
+import org.aspectj.lang.JoinPoint;\r
+\r
+public abstract class JoinPointClosure implements Joinpoint {\r
+       \r
+       protected JoinPoint jp;\r
+       \r
+       public JoinPointClosure(JoinPoint joinPoint) {\r
+               this.jp = joinPoint;\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.Joinpoint#proceed()\r
+        */\r
+       public Object proceed() throws Throwable {\r
+               return execute();\r
+       }\r
+       \r
+       // for subclasses, renamed from proceed to avoid confusion in \r
+       // AspectJ around advice.\r
+       public abstract Object execute();\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.Joinpoint#getThis()\r
+        */\r
+       public Object getThis() {\r
+               return jp.getThis();  \r
+       }\r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.Joinpoint#getStaticPart()\r
+        * Must return either a Field, Method or Constructor representing the entity\r
+        * at the joinpoint.\r
+        */\r
+       public abstract AccessibleObject getStaticPart();\r
+\r
+}\r
diff --git a/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/MethodInvocationClosure.java b/docs/sandbox/aopalliance/src/org/aspectj/aopalliance/MethodInvocationClosure.java
new file mode 100644 (file)
index 0000000..468a369
--- /dev/null
@@ -0,0 +1,33 @@
+/*******************************************************************************\r
+ * Copyright (c) 2004 IBM Corporation and others.\r
+ * All rights reserved. This program and the accompanying materials \r
+ * are made available under the terms of the Common Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/cpl-v10.html\r
+ * \r
+ * Contributors:\r
+ *     IBM Corporation - initial API and implementation\r
+ *******************************************************************************/\r
+package org.aspectj.aopalliance;\r
+\r
+import java.lang.reflect.Method;\r
+\r
+import org.aopalliance.intercept.MethodInvocation;\r
+import org.aspectj.lang.JoinPoint;\r
+\r
+public abstract class MethodInvocationClosure extends InvocationJoinPointClosure\r
+               implements\r
+                       MethodInvocation {\r
+\r
+       public MethodInvocationClosure(JoinPoint jp) {\r
+               super(jp);\r
+       }\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.MethodInvocation#getMethod()\r
+        */\r
+       public Method getMethod() {\r
+               return (Method) getStaticPart();\r
+       }\r
+\r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/AOPAllianceAdapterTest.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/AOPAllianceAdapterTest.java
new file mode 100644 (file)
index 0000000..a172c22
--- /dev/null
@@ -0,0 +1,19 @@
+\r
+package org.aspectj.aopalliance.tests;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public class AOPAllianceAdapterTest extends TestCase {\r
+       \r
+       public void testHello() {\r
+               Hello h = new Hello();\r
+               h.sayHello();\r
+               Hello h2 = new Hello("Hello AOP Alliance");\r
+               h2.sayHello();\r
+               assertTrue("Constructor executed", Hello.defaultConsExecuted);\r
+               assertTrue("2nd Constructor executed", Hello.paramConsExecuted);\r
+               assertEquals("sayHello invoked twice",2,Hello.sayHelloCount);\r
+               assertEquals("Constructor interceptor ran twice",2,HelloConstructionInterceptor.runCount);\r
+               assertEquals("Method interceptor ran twice",2,HelloMethodInterceptor.runCount);\r
+       }\r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/AllTests.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/AllTests.java
new file mode 100644 (file)
index 0000000..ea4d96c
--- /dev/null
@@ -0,0 +1,19 @@
+package org.aspectj.aopalliance.tests;\r
+\r
+import junit.framework.Test;\r
+import junit.framework.TestSuite;\r
+\r
+public class AllTests {\r
+       public static Test suite() {\r
+               TestSuite suite = new TestSuite(\r
+                               "Test for org.aspectj.aopalliance.tests");\r
+               //$JUnit-BEGIN$\r
+               suite.addTestSuite(JoinPointClosureTest.class);\r
+               suite.addTestSuite(InvocationJoinPointClosureTest.class);\r
+               suite.addTestSuite(MethodInvocationClosureTest.class);\r
+               suite.addTestSuite(ConstructorInvocationClosureTest.class);\r
+               suite.addTestSuite(AOPAllianceAdapterTest.class);\r
+               //$JUnit-END$\r
+               return suite;\r
+       }\r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/ConstructorInvocationClosureTest.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/ConstructorInvocationClosureTest.java
new file mode 100644 (file)
index 0000000..8071193
--- /dev/null
@@ -0,0 +1,39 @@
+package org.aspectj.aopalliance.tests;\r
+\r
+import java.lang.reflect.Constructor;\r
+\r
+import org.aspectj.aopalliance.ConstructorInvocationClosure;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public class ConstructorInvocationClosureTest extends TestCase {\r
+       \r
+\r
+       public void testGetArguments() {\r
+               MockMethodSignature sig = new MockMethodSignature("toString",Object.class,\r
+                               new Class[] {});\r
+               Object[] args = new Object[] {this};\r
+               MockJoinPoint jp = new MockJoinPoint(this,sig,args);\r
+               ConstructorInvocationClosure cic = new ConstructorInvocationClosure(jp) {\r
+                         public Object execute() {return null;}\r
+                 };\r
+               assertEquals(args,cic.getArguments());\r
+       }\r
+       \r
+       public void testGetConstructor() {\r
+               MockConstructorSignature sig = new MockConstructorSignature("new",StringBuffer.class,\r
+                               new Class[] {String.class});\r
+               MockJoinPoint jp = new MockJoinPoint(this,sig,null);\r
+               ConstructorInvocationClosure cic = new ConstructorInvocationClosure(jp) {\r
+                         public Object execute() {return null;}\r
+                 };\r
+               Constructor c = cic.getConstructor();\r
+               try {\r
+                       assertEquals("Should find StringBuffer constructor",StringBuffer.class.getConstructor(new Class[]{String.class}),\r
+                                       c);\r
+               } catch (NoSuchMethodException e) {\r
+                       fail("Duff test:" + e);\r
+               }\r
+\r
+       }\r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/Hello.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/Hello.java
new file mode 100644 (file)
index 0000000..6aea070
--- /dev/null
@@ -0,0 +1,24 @@
+\r
+package org.aspectj.aopalliance.tests;\r
+\r
+public class Hello {\r
+       \r
+       public static boolean defaultConsExecuted = false;\r
+       public static boolean paramConsExecuted = false;\r
+       public static int sayHelloCount = 0;\r
+       \r
+       private String msg = "Hello";\r
+       \r
+       public Hello() { defaultConsExecuted = true;}\r
+       \r
+       public Hello(String s) {\r
+               msg = s;\r
+               paramConsExecuted = true;\r
+       }\r
+       \r
+       public String sayHello() {\r
+               sayHelloCount++;\r
+               return msg;\r
+       }\r
+       \r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloAOPAllianceAdapter.aj b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloAOPAllianceAdapter.aj
new file mode 100644 (file)
index 0000000..804cf1c
--- /dev/null
@@ -0,0 +1,28 @@
+package org.aspectj.aopalliance.tests;\r
+\r
+import org.aspectj.aopalliance.AOPAllianceAdapter;\r
+import org.aopalliance.intercept.MethodInterceptor;\r
+import org.aopalliance.intercept.ConstructorInterceptor;\r
+\r
+\r
+public aspect HelloAOPAllianceAdapter extends AOPAllianceAdapter {\r
+\r
+       private MethodInterceptor mInt;\r
+       private ConstructorInterceptor cInt;\r
+       \r
+       public pointcut targetJoinPoint() : within(Hello);\r
+       \r
+       protected MethodInterceptor getMethodInterceptor() {\r
+               return mInt;\r
+       }\r
+       \r
+       protected ConstructorInterceptor getConstructorInterceptor() {\r
+               return cInt;\r
+       }\r
+       \r
+       public HelloAOPAllianceAdapter() {\r
+               mInt = new HelloMethodInterceptor();\r
+               cInt = new HelloConstructionInterceptor();\r
+       }\r
+       \r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloConstructionInterceptor.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloConstructionInterceptor.java
new file mode 100644 (file)
index 0000000..65d18ad
--- /dev/null
@@ -0,0 +1,21 @@
+package org.aspectj.aopalliance.tests;\r
+\r
+import org.aopalliance.intercept.ConstructorInterceptor;\r
+import org.aopalliance.intercept.ConstructorInvocation;\r
+\r
+public class HelloConstructionInterceptor implements ConstructorInterceptor {\r
+\r
+       public static int runCount = 0;\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.ConstructorInterceptor#construct(org.aopalliance.intercept.ConstructorInvocation)\r
+        */\r
+       public Object construct(ConstructorInvocation jp) throws Throwable {\r
+               System.out.println("About to invoke AOP Alliance constructor interceptor");\r
+               Object ret = jp.proceed();\r
+               System.out.println("Invoked AOP Alliance constructor interceptor, return = " + \r
+                               (ret != null ? ret.toString() : "null"));\r
+               runCount++;\r
+               return ret;\r
+       }\r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloMethodInterceptor.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/HelloMethodInterceptor.java
new file mode 100644 (file)
index 0000000..70162fd
--- /dev/null
@@ -0,0 +1,20 @@
+package org.aspectj.aopalliance.tests;\r
+\r
+import org.aopalliance.intercept.MethodInterceptor;\r
+import org.aopalliance.intercept.MethodInvocation;\r
+\r
+public class HelloMethodInterceptor implements MethodInterceptor {\r
+\r
+       public static int runCount = 0;\r
+       \r
+       /* (non-Javadoc)\r
+        * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)\r
+        */\r
+       public Object invoke(MethodInvocation jp) throws Throwable {\r
+               System.out.println("About to invoke AOP Alliance method interceptor");\r
+               Object ret = jp.proceed();\r
+               System.out.println("Invoked AOP Alliance method interceptor, return = " + ret.toString());\r
+               runCount++;\r
+               return ret;\r
+       }\r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/InvocationJoinPointClosureTest.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/InvocationJoinPointClosureTest.java
new file mode 100644 (file)
index 0000000..bfa710b
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * Created on 07-May-2004\r
+ *\r
+ * TODO To change the template for this generated file go to\r
+ * Window - Preferences - Java - Code Generation - Code and Comments\r
+ */\r
+package org.aspectj.aopalliance.tests;\r
+\r
+import java.lang.reflect.AccessibleObject;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.aspectj.aopalliance.InvocationJoinPointClosure;\r
+\r
+\r
+public class InvocationJoinPointClosureTest extends TestCase {\r
+\r
+       public void testGetStaticPartMethod() {\r
+               MockMethodSignature sig = new MockMethodSignature("toString",Object.class,\r
+                               new Class[] {});\r
+               MockJoinPoint jp = new MockJoinPoint(this,sig,null);\r
+               InvocationJoinPointClosure mejpc = new InvocationJoinPointClosure(jp) {\r
+                         public Object execute() {return null;}\r
+                 };\r
+               AccessibleObject ao = mejpc.getStaticPart();\r
+               try {\r
+                       assertEquals("Should find toString method",Object.class.getMethod("toString",new Class[]{}),\r
+                                       ao);\r
+               } catch (NoSuchMethodException e) {\r
+                       fail("Duff test:" + e);\r
+               }\r
+       }\r
+\r
+       public void testGetStaticPartConstructor() {\r
+               MockConstructorSignature sig = new MockConstructorSignature("new",StringBuffer.class,\r
+                               new Class[] {String.class});\r
+               MockJoinPoint jp = new MockJoinPoint(this,sig,null);\r
+               InvocationJoinPointClosure mejpc = new InvocationJoinPointClosure(jp) {\r
+                         public Object execute() {return null;}\r
+                 };\r
+               AccessibleObject ao = mejpc.getStaticPart();\r
+               try {\r
+                       assertEquals("Should find StringBuffer constructor",StringBuffer.class.getConstructor(new Class[]{String.class}),\r
+                                       ao);\r
+               } catch (NoSuchMethodException e) {\r
+                       fail("Duff test:" + e);\r
+               }\r
+       }\r
+       \r
+       public void testGetStaticPartException() {\r
+               try {\r
+                       MockMethodSignature sig = new MockMethodSignature("toKettle",Object.class,\r
+                                       new Class[] {});\r
+                       MockJoinPoint jp = new MockJoinPoint(this,sig,null);\r
+                       InvocationJoinPointClosure mejpc = new InvocationJoinPointClosure(jp) {\r
+                                 public Object execute() {return null;}\r
+                         };\r
+                       AccessibleObject ao = mejpc.getStaticPart();                    \r
+                       fail("UnsupportedOperationException expected");\r
+               } catch (UnsupportedOperationException unEx) {\r
+                       assertEquals("Can't find member long string",unEx.getMessage());\r
+               }\r
+       }\r
+\r
+       public void testGetArguments() {\r
+               MockMethodSignature sig = new MockMethodSignature("toString",Object.class,\r
+                               new Class[] {});\r
+               Object[] args = new Object[] {this};\r
+               MockJoinPoint jp = new MockJoinPoint(this,sig,args);\r
+               InvocationJoinPointClosure mic = new InvocationJoinPointClosure(jp) {\r
+                         public Object execute() {return null;}\r
+                 };\r
+               assertEquals(args,mic.getArguments());\r
+       }\r
+       \r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/JoinPointClosureTest.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/JoinPointClosureTest.java
new file mode 100644 (file)
index 0000000..7bc996a
--- /dev/null
@@ -0,0 +1,45 @@
+/*\r
+ * Created on 07-May-2004\r
+ *\r
+ * TODO To change the template for this generated file go to\r
+ * Window - Preferences - Java - Code Generation - Code and Comments\r
+ */\r
+package org.aspectj.aopalliance.tests;\r
+\r
+import java.lang.reflect.AccessibleObject;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.aspectj.aopalliance.JoinPointClosure;\r
+import org.aspectj.lang.JoinPoint;\r
+\r
+/**\r
+ * @author colyer\r
+ *\r
+ * TODO To change the template for this generated type comment go to\r
+ * Window - Preferences - Java - Code Generation - Code and Comments\r
+ */\r
+public class JoinPointClosureTest extends TestCase {\r
+       \r
+       public void testGetThis() {\r
+               JoinPoint jp = new MockJoinPoint(this,null,null);\r
+               JoinPointClosure jpc = new JoinPointClosure(jp) {\r
+                       public Object execute() {return null;}\r
+                       public AccessibleObject getStaticPart() {return null;}};\r
+               assertEquals("getThis returns join point 'this'",this,jpc.getThis());\r
+       }\r
+       \r
+       public void testProceed() {\r
+               JoinPoint jp = new MockJoinPoint(this,null,null);\r
+               JoinPointClosure jpc = new JoinPointClosure(jp) {\r
+                       public Object execute() {return this;}\r
+                       public AccessibleObject getStaticPart() {return null;}};\r
+               try {\r
+                       Object ret = jpc.proceed();\r
+                   assertTrue("should return value from execute",ret instanceof JoinPointClosure);\r
+               } catch (Throwable e) {\r
+                   fail("Exception proceeding on join point : " + e);\r
+               }\r
+       }\r
+       \r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MethodInvocationClosureTest.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MethodInvocationClosureTest.java
new file mode 100644 (file)
index 0000000..a25755f
--- /dev/null
@@ -0,0 +1,27 @@
+package org.aspectj.aopalliance.tests;\r
+\r
+import java.lang.reflect.Method;\r
+\r
+import org.aspectj.aopalliance.MethodInvocationClosure;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public class MethodInvocationClosureTest extends TestCase {\r
+       \r
+\r
+       public void testGetMethod() {\r
+               MockMethodSignature sig = new MockMethodSignature("toString",Object.class,\r
+                               new Class[] {});\r
+               MockJoinPoint jp = new MockJoinPoint(this,sig,null);\r
+               MethodInvocationClosure mic = new MethodInvocationClosure(jp) {\r
+                         public Object execute() {return null;}\r
+                 };\r
+               Method m = mic.getMethod();\r
+               try {\r
+                       assertEquals("Should find toString method",Object.class.getMethod("toString",new Class[]{}),\r
+                                       m);\r
+               } catch (NoSuchMethodException e) {\r
+                       fail("Duff test:" + e);\r
+               }               \r
+       }\r
+}\r
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockConstructorSignature.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockConstructorSignature.java
new file mode 100644 (file)
index 0000000..4a691c8
--- /dev/null
@@ -0,0 +1,16 @@
+/*\r
+ * Created on 07-May-2004\r
+ *\r
+ * TODO To change the template for this generated file go to\r
+ * Window - Preferences - Java - Code Generation - Code and Comments\r
+ */\r
+package org.aspectj.aopalliance.tests;\r
+\r
+import org.aspectj.lang.reflect.ConstructorSignature;\r
+\r
+\r
+class MockConstructorSignature extends MockSignature implements ConstructorSignature {\r
+       public MockConstructorSignature(String name,Class decClass, Class[] paramTypes) {\r
+               super(name,decClass,paramTypes);\r
+       }               \r
+}
\ No newline at end of file
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockJoinPoint.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockJoinPoint.java
new file mode 100644 (file)
index 0000000..821ed50
--- /dev/null
@@ -0,0 +1,53 @@
+/*\r
+ * Created on 07-May-2004\r
+ *\r
+ * TODO To change the template for this generated file go to\r
+ * Window - Preferences - Java - Code Generation - Code and Comments\r
+ */\r
+package org.aspectj.aopalliance.tests;\r
+\r
+import org.aspectj.lang.JoinPoint;\r
+import org.aspectj.lang.Signature;\r
+import org.aspectj.lang.reflect.SourceLocation;\r
+\r
+\r
+class MockJoinPoint implements JoinPoint {\r
+               \r
+               private Object me;\r
+               private Signature sig;\r
+               private Object[] args;\r
+               \r
+               public MockJoinPoint(Object me, Signature sig, Object[] args) {\r
+                       this.me = me;\r
+                       this.sig = sig;\r
+                       this.args = args;\r
+               }\r
+               \r
+               public Object[] getArgs() {\r
+                       return args;\r
+               }\r
+               public String getKind() {\r
+                       return null;\r
+               }\r
+               public Signature getSignature() {\r
+                       return sig;\r
+               }\r
+               public SourceLocation getSourceLocation() {\r
+                       return null;\r
+               }\r
+               public StaticPart getStaticPart() {\r
+                       return null;\r
+               }\r
+               public Object getTarget() {\r
+                       return null;\r
+               }\r
+               public Object getThis() {\r
+                       return me;\r
+               }\r
+               public String toLongString() {\r
+                       return null;\r
+               }\r
+               public String toShortString() {\r
+                       return null;\r
+               }\r
+}
\ No newline at end of file
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockMethodSignature.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockMethodSignature.java
new file mode 100644 (file)
index 0000000..9a70a22
--- /dev/null
@@ -0,0 +1,18 @@
+/*\r
+ * Created on 07-May-2004\r
+ *\r
+ * TODO To change the template for this generated file go to\r
+ * Window - Preferences - Java - Code Generation - Code and Comments\r
+ */\r
+package org.aspectj.aopalliance.tests;\r
+\r
+import org.aspectj.lang.reflect.MethodSignature;\r
+\r
+\r
+class MockMethodSignature extends MockSignature implements MethodSignature {\r
+       public MockMethodSignature(String name,Class decClass, Class[] paramTypes) {\r
+               super(name,decClass,paramTypes);\r
+       }\r
+\r
+       public Class getReturnType() {return null;}\r
+}
\ No newline at end of file
diff --git a/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockSignature.java b/docs/sandbox/aopalliance/testsrc/org/aspectj/aopalliance/tests/MockSignature.java
new file mode 100644 (file)
index 0000000..9f81281
--- /dev/null
@@ -0,0 +1,51 @@
+/*\r
+ * Created on 07-May-2004\r
+ *\r
+ * TODO To change the template for this generated file go to\r
+ * Window - Preferences - Java - Code Generation - Code and Comments\r
+ */\r
+package org.aspectj.aopalliance.tests;\r
+\r
+import org.aspectj.lang.reflect.CodeSignature;\r
+\r
+\r
+class MockSignature implements CodeSignature {\r
+       \r
+       private String name;\r
+       private Class decClass;\r
+       private Class[] paramTypes;\r
+       \r
+       public MockSignature(String name,Class decClass, Class[] paramTypes) {\r
+               this.name = name;\r
+               this.decClass = decClass;\r
+               this.paramTypes = paramTypes;\r
+       }\r
+       \r
+       public Class[] getExceptionTypes() {\r
+               return null;\r
+       }\r
+       public String[] getParameterNames() {\r
+               return null;\r
+       }\r
+       public Class[] getParameterTypes() {\r
+               return paramTypes;\r
+       }\r
+       public Class getDeclaringType() {\r
+               return decClass;\r
+       }\r
+       public String getDeclaringTypeName() {\r
+               return null;\r
+       }\r
+       public int getModifiers() {\r
+               return 0;\r
+       }\r
+       public String getName() {\r
+               return name;\r
+       }\r
+       public String toLongString() {\r
+               return "long string";\r
+       }\r
+       public String toShortString() {\r
+               return null;\r
+       }\r
+}
\ No newline at end of file