1 3 package jodd.introspector; 4 5 import java.lang.reflect.Constructor ; 6 7 10 class Ctors { 11 12 Constructor [] allCtors; 13 Class [][] allArgs; 14 boolean locked = false; 15 Constructor defaultCtor; 16 17 void addCtors(Constructor [] ctors) { 18 if (locked == true) { 19 throw new IllegalStateException ("Constructor introspection is already finished."); 20 } 21 allCtors = ctors; 22 allArgs = new Class [allCtors.length][]; 23 for (int i = 0; i < ctors.length; i++) { 24 Constructor ctor = ctors[i]; 25 allArgs[i] = ctor.getParameterTypes(); 26 if (allArgs[i].length == 0) { 27 defaultCtor = ctor; 28 } 29 } 30 } 31 32 void lock() { 33 locked = true; 34 } 35 36 37 39 Constructor getDefaultCtor() { 40 return defaultCtor; 41 } 42 43 Constructor getCtor(Class [] args) { 44 ctors: 45 for (int i = 0; i < allArgs.length; i++) { 46 Class [] arg = allArgs[i]; 47 if (arg.length != args.length) { 48 continue; 49 } 50 for (int j = 0; j < arg.length; j++) { 51 if (arg[j] != args[j]) { 52 continue ctors; 53 } 54 } 55 return allCtors[i]; 56 } 57 return null; 58 } 59 60 int getCount() { 61 return allCtors.length; 62 } 63 64 Constructor [] getAllCtors() { 65 return allCtors; 66 } 67 68 } 69 | Popular Tags |