1 17 package org.apache.bcel; 18 19 import java.io.IOException ; 20 import org.apache.bcel.classfile.JavaClass; 21 import org.apache.bcel.util.ClassPath; 22 import org.apache.bcel.util.SyntheticRepository; 23 24 35 public abstract class Repository { 36 37 private static org.apache.bcel.util.Repository _repository = SyntheticRepository.getInstance(); 38 39 40 42 public static org.apache.bcel.util.Repository getRepository() { 43 return _repository; 44 } 45 46 47 49 public static void setRepository( org.apache.bcel.util.Repository rep ) { 50 _repository = rep; 51 } 52 53 54 61 public static JavaClass lookupClass( String class_name ) throws ClassNotFoundException { 62 return _repository.loadClass(class_name); 63 } 64 65 66 73 public static JavaClass lookupClass( Class clazz ) throws ClassNotFoundException { 74 return _repository.loadClass(clazz); 75 } 76 77 78 83 public static ClassPath.ClassFile lookupClassFile( String class_name ) { 84 try { 85 ClassPath path = _repository.getClassPath(); 86 if (path == null) { 87 return null; 88 } 89 return path.getClassFile(class_name); 90 } catch (IOException e) { 91 return null; 92 } 93 } 94 95 96 98 public static void clearCache() { 99 _repository.clear(); 100 } 101 102 103 108 public static JavaClass addClass( JavaClass clazz ) { 109 JavaClass old = _repository.findClass(clazz.getClassName()); 110 _repository.storeClass(clazz); 111 return old; 112 } 113 114 115 118 public static void removeClass( String clazz ) { 119 _repository.removeClass(_repository.findClass(clazz)); 120 } 121 122 123 126 public static void removeClass( JavaClass clazz ) { 127 _repository.removeClass(clazz); 128 } 129 130 131 136 public static JavaClass[] getSuperClasses( JavaClass clazz ) throws ClassNotFoundException { 137 return clazz.getSuperClasses(); 138 } 139 140 141 147 public static JavaClass[] getSuperClasses( String class_name ) throws ClassNotFoundException { 148 JavaClass jc = lookupClass(class_name); 149 return getSuperClasses(jc); 150 } 151 152 153 160 public static JavaClass[] getInterfaces( JavaClass clazz ) throws ClassNotFoundException { 161 return clazz.getAllInterfaces(); 162 } 163 164 165 171 public static JavaClass[] getInterfaces( String class_name ) throws ClassNotFoundException { 172 return getInterfaces(lookupClass(class_name)); 173 } 174 175 176 182 public static boolean instanceOf( JavaClass clazz, JavaClass super_class ) 183 throws ClassNotFoundException { 184 return clazz.instanceOf(super_class); 185 } 186 187 188 193 public static boolean instanceOf( String clazz, String super_class ) 194 throws ClassNotFoundException { 195 return instanceOf(lookupClass(clazz), lookupClass(super_class)); 196 } 197 198 199 203 public static boolean instanceOf( JavaClass clazz, String super_class ) 204 throws ClassNotFoundException { 205 return instanceOf(clazz, lookupClass(super_class)); 206 } 207 208 209 213 public static boolean instanceOf( String clazz, JavaClass super_class ) 214 throws ClassNotFoundException { 215 return instanceOf(lookupClass(clazz), super_class); 216 } 217 218 219 224 public static boolean implementationOf( JavaClass clazz, JavaClass inter ) 225 throws ClassNotFoundException { 226 return clazz.implementationOf(inter); 227 } 228 229 230 235 public static boolean implementationOf( String clazz, String inter ) 236 throws ClassNotFoundException { 237 return implementationOf(lookupClass(clazz), lookupClass(inter)); 238 } 239 240 241 246 public static boolean implementationOf( JavaClass clazz, String inter ) 247 throws ClassNotFoundException { 248 return implementationOf(clazz, lookupClass(inter)); 249 } 250 251 252 257 public static boolean implementationOf( String clazz, JavaClass inter ) 258 throws ClassNotFoundException { 259 return implementationOf(lookupClass(clazz), inter); 260 } 261 } 262 | Popular Tags |