1 22 package org.jboss.test.aop.dynamicgenadvisor; 23 24 import java.lang.reflect.Constructor ; 25 import java.lang.reflect.Field ; 26 import java.lang.reflect.Method ; 27 import java.util.ArrayList ; 28 29 public class Interceptions 30 { 31 private static ArrayList interceptions = new ArrayList (); 32 33 public static void clear() 34 { 35 interceptions.clear(); 36 } 37 38 public static boolean isEmpty() 39 { 40 return interceptions.isEmpty(); 41 } 42 43 public static int size() 44 { 45 return interceptions.size(); 46 } 47 48 public static String get(int index) 49 { 50 return (String )interceptions.get(index); 51 } 52 53 public static void addConstructorInterception(Class aspect, Constructor c) 54 { 55 interceptions.add(getConstructorName(getClassName(aspect), c)); 56 } 57 58 public static void addConstructionInterception(Class aspect, Constructor c) 59 { 60 interceptions.add(getConstructionName(getClassName(aspect), c)); 61 } 62 63 public static void addMethodInterception(Class aspect, Method m) 64 { 65 interceptions.add(getMethodName(getClassName(aspect), m)); 66 } 67 68 public static void addFieldReadInterception(Class aspect, Field f) 69 { 70 interceptions.add(getFieldReadName(getClassName(aspect), f)); 71 } 72 73 public static void addFieldWriteInterception(Class aspect, Field f) 74 { 75 interceptions.add(getFieldWriteName(getClassName(aspect), f)); 76 } 77 78 public static String getConstructorName(String aspect, String clazz) 79 { 80 return aspect + " : " + clazz + ".new"; 81 } 82 83 public static String getConstructionName(String aspect, String clazz) 84 { 85 return aspect + " : " + clazz + ".new..."; 86 } 87 88 public static String getMethodName(String aspect, String clazz, String m) 89 { 90 return aspect + " : " + clazz + "." + m; 91 } 92 93 public static String getFieldReadName(String aspect, String clazz, String f) 94 { 95 return aspect + " : " + clazz + ".r_" + f; 96 } 97 98 public static String getFieldWriteName(String aspect, String clazz, String f) 99 { 100 return aspect + " : " + clazz + ".w_" + f; 101 } 102 103 private static String getConstructorName(String aspect, Constructor con) 104 { 105 return getConstructorName(aspect, getClassName(con)); 106 } 107 108 private static String getConstructionName(String aspect, Constructor con) 109 { 110 return getConstructionName(aspect, getClassName(con)); 111 } 112 113 private static String getMethodName(String aspect, Method m) 114 { 115 return getMethodName(aspect, getClassName(m), m.getName()); 116 } 117 118 private static String getFieldReadName(String aspect, Field f) 119 { 120 return getFieldReadName(aspect, getClassName(f), f.getName()); 121 } 122 123 private static String getFieldWriteName(String aspect, Field f) 124 { 125 return getFieldWriteName(aspect, getClassName(f), f.getName()); 126 } 127 128 private static String getClassName(Constructor c) 129 { 130 return getClassName(c.getDeclaringClass().getName()); 131 } 132 133 private static String getClassName(Method m) 134 { 135 return getClassName(m.getDeclaringClass().getName()); 136 } 137 138 private static String getClassName(Field f) 139 { 140 return getClassName(f.getDeclaringClass().getName()); 141 } 142 143 private static String getClassName(Class clazz) 144 { 145 return getClassName(clazz.getName()); 146 } 147 148 private static String getClassName(String s) 149 { 150 return s.substring(s.lastIndexOf('.') + 1); 151 } 152 } 153 | Popular Tags |