1 54 package org.logicalcobwebs.cglib.proxy; 55 56 import org.logicalcobwebs.asm.Type; 57 58 class CallbackUtils { 59 private CallbackUtils() { } 60 61 static Class determineType(Callback callback) { 62 Class test = typeHelper(callback, null, NoOp.class); 63 test = typeHelper(callback, test, MethodInterceptor.class); 64 test = typeHelper(callback, test, InvocationHandler.class); 65 test = typeHelper(callback, test, LazyLoader.class); 66 test = typeHelper(callback, test, Dispatcher.class); 67 test = typeHelper(callback, test, FixedValue.class); 68 if (test == null) { 69 throw new IllegalStateException ("Unknown callback " + callback.getClass()); 70 } 71 return test; 72 } 73 74 private static Class typeHelper(Callback callback, Class cur, Class callbackType) { 75 if (callback == null) { 76 throw new IllegalStateException ("Callback is null"); 77 } 78 if (callbackType.isAssignableFrom(callback.getClass())) { 79 if (cur != null) { 80 throw new IllegalStateException ("Callback implements both " + cur + " and " + callbackType + "; use setCallbackTypes to distinguish"); 81 } 82 return callbackType; 83 } else { 84 return cur; 85 } 86 } 87 88 static CallbackGenerator getGenerator(Class type) { 89 if (type.equals(NoOp.class)) { 90 return NoOpGenerator.INSTANCE; 91 } else if (type.equals(MethodInterceptor.class)) { 92 return MethodInterceptorGenerator.INSTANCE; 93 } else if (type.equals(InvocationHandler.class)) { 94 return InvocationHandlerGenerator.INSTANCE; 95 } else if (type.equals(LazyLoader.class)) { 96 return LazyLoaderGenerator.INSTANCE; 97 } else if (type.equals(Dispatcher.class)) { 98 return DispatcherGenerator.INSTANCE; 99 } else if (type.equals(FixedValue.class)) { 100 return FixedValueGenerator.INSTANCE; 101 } else { 102 throw new IllegalStateException ("Unknown callback " + type); 103 } 104 } 105 } 106 | Popular Tags |