From: Kabir K. <ka...@us...> - 2004-07-17 20:32:02
|
User: kabkhan Date: 04/07/17 13:31:56 Modified: src/main/org/jboss/test/aop/basic ReflectionPOJO.java Log: Moved instumentation of caller pointcuts from Instrumentor to a new CallerTransformer class. Optimized caller pointcuts Revision Changes Path 1.6 +56 -13 jboss-aop/src/main/org/jboss/test/aop/basic/ReflectionPOJO.java Index: ReflectionPOJO.java =================================================================== RCS file: /cvsroot/jboss/jboss-aop/src/main/org/jboss/test/aop/basic/ReflectionPOJO.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ReflectionPOJO.java 17 Jul 2004 13:32:30 -0000 1.5 +++ ReflectionPOJO.java 17 Jul 2004 20:31:56 -0000 1.6 @@ -24,12 +24,55 @@ public class ReflectionPOJO { final static Package LANG_PACKAGE = Package.getPackage("java.lang"); + + public ReflectionPOJO() + { + try + { + System.out.println("*** reflection (from constructor): Class.newInstance"); + Class clazz = ReflectionAopPOJO.class; + clazz.newInstance(); + if (ReflectionAspectTester.constructor == null) + { + throw new RuntimeException("Not intercepted"); + } + + //Check Constructor.newInstance() interception + System.out.println("*** reflection (from constructor): Constructor.newInstance"); + Constructor constructor = clazz.getConstructor(new Class[] {Integer.TYPE}); + Object obj = constructor.newInstance(new Object[] {new Integer(4)}); + + //Check Field.setInt() interception + System.out.println("*** reflection (from constructor): Field.setInt"); + Field field = clazz.getField("j"); + field.setInt(obj, 10); + if (ReflectionAspectTester.field == null + || ((Integer)ReflectionAspectTester.args[0]).intValue() != 10){ + throw new RuntimeException("Not intercepted"); + } + + + //Check Field.getInt() interception + System.out.println("*** reflection (from constructor): Field.getInt"); + int j = field.getInt(obj); + if (ReflectionAspectTester.field == null + || j != 10){ + throw new RuntimeException("Not intercepted"); + } + } + catch (Exception e) + { + throw new RuntimeException(e); + } + + } + public void testCreationAndFieldAccess(){ try { //Check Class.newInstance() interception - System.out.println("*** reflection: Class.newInstance"); + System.out.println("*** reflection (from method): Class.newInstance"); Class clazz = ReflectionAopPOJO.class; clazz.newInstance(); if (ReflectionAspectTester.constructor == null){ @@ -38,13 +81,13 @@ //Check Constructor.newInstance() interception - System.out.println("*** reflection: Constructor.newInstance"); + System.out.println("*** reflection (from method): Constructor.newInstance"); Constructor constructor = clazz.getConstructor(new Class[] {Integer.TYPE}); Object obj = constructor.newInstance(new Object[] {new Integer(4)}); //Check Field.setInt() interception - System.out.println("*** reflection: Field.setInt"); + System.out.println("*** reflection (from method): Field.setInt"); Field field = clazz.getField("j"); field.setInt(obj, 10); if (ReflectionAspectTester.field == null @@ -54,7 +97,7 @@ //Check Field.getInt() interception - System.out.println("*** reflection: Field.getInt"); + System.out.println("*** reflection (from method): Field.getInt"); int j = field.getInt(obj); if (ReflectionAspectTester.field == null || j != 10){ @@ -68,7 +111,7 @@ } public void testCleanGetMethods(){ - System.out.println("*** reflection: Class.getMethods()"); + System.out.println("*** reflection (from method): Class.getMethods()"); Class pojoClass = ReflectionAopPOJO.class; Class pojoRoot = ReflectionAopRootPOJO.class; try { @@ -114,7 +157,7 @@ public void testCleanGetDeclaredMethods(){ - System.out.println("*** reflection: Class.getDeclaredMethods()"); + System.out.println("*** reflection (from method): Class.getDeclaredMethods()"); Class clazz = ReflectionAopPOJO.class; try { //helloWorld() is introduced @@ -157,7 +200,7 @@ public void testCleanGetDeclaredFields(){ - System.out.println("*** reflection: Class.getDeclaredFields()"); + System.out.println("*** reflection (from method): Class.getDeclaredFields()"); Class clazz = ReflectionAopPOJO.class; try { Field[] check = new Field[]{ @@ -197,7 +240,7 @@ public void testCleanGetInterfaces(){ - System.out.println("*** reflection: Class.getInterfaces()"); + System.out.println("*** reflection (from method): Class.getInterfaces()"); ReflectionAopPOJO pojo = new ReflectionAopPOJO(); Class clazz = ReflectionAopPOJO.class; Class[] interfaces = clazz.getInterfaces(); @@ -213,7 +256,7 @@ public void testCleanGetDeclaredMethod(){ - System.out.println("*** reflection: Class.getDeclaredMethod()"); + System.out.println("*** reflection (from method): Class.getDeclaredMethod()"); Class pojoClass = ReflectionAopPOJO.class; Class pojoRoot = ReflectionAopRootPOJO.class; @@ -308,7 +351,7 @@ public void testCleanGetMethod(){ - System.out.println("*** reflection: Class.getMethod()"); + System.out.println("*** reflection (from method): Class.getMethod()"); Class clazz = ReflectionAopPOJO.class; try { @@ -378,7 +421,7 @@ public void testCleanGetDeclaredField(){ - System.out.println("*** reflection: Class.getDeclaredField()"); + System.out.println("*** reflection (from method): Class.getDeclaredField()"); Class clazz = ReflectionAopPOJO.class; try { Field f = clazz.getDeclaredField("i"); @@ -407,7 +450,7 @@ public void testCleanGetClasses(){ //No extra public classes are added by AOP, but include this test in case stuff changes in future - System.out.println("*** reflection: Class.getClasses()"); + System.out.println("*** reflection (from method): Class.getClasses()"); HashSet classSet = new HashSet(); classSet.add("org.jboss.test.aop.basic.ReflectionAopPOJO$AopPOJOInner"); classSet.add("org.jboss.test.aop.basic.ReflectionAopRootPOJO$AopRootPOJOInner"); @@ -428,7 +471,7 @@ } public void testCleanGetDeclaredClasses(){ - System.out.println("*** reflection: Class.getDeclaredClasses()"); + System.out.println("*** reflection (from method): Class.getDeclaredClasses()"); HashSet declaredClasses = new HashSet(); declaredClasses.add("org.jboss.test.aop.basic.ReflectionAopPOJO$AopPOJOInner"); |