public CallbackHelper(Class superclass, Class[] interfaces) { List methods = new ArrayList(); Enhancer.getMethods(superclass, interfaces, methods); Map indexes = new HashMap(); for (int i = 0, size = methods.size(); i < size; i++) { Method method = (Method)methods.get(i); Object callback = getCallback(method); if (callback == null) throw new IllegalStateException("getCallback cannot return null"); boolean isCallback = callback instanceof Callback; if (!(isCallback || (callback instanceof Class))) throw new IllegalStateException("getCallback must return a Callback or a Class"); if (i > 0 && ((callbacks.get(i - 1) instanceof Callback) ^ isCallback)) throw new IllegalStateException("getCallback must return a Callback or a Class consistently for every Method"); Integer index = (Integer)indexes.get(callback); if (index == null) { index = new Integer(callbacks.size()); indexes.put(callback, index); } methodMap.put(method, index); callbacks.add(callback); } }
public Class[] getCallbackTypes() { if (callbacks.size() == 0) return new Class[0]; if (callbacks.get(0) instanceof Callback) { return ReflectUtils.getClasses(getCallbacks()); } else { return (Class[])callbacks.toArray(new Class[callbacks.size()]); } }
public Class[] getCallbackTypes() { if (callbacks.size() == 0) return new Class[0]; if (callbacks.get(0) instanceof Callback) { return ReflectUtils.getClasses(getCallbacks()); } else { return (Class[])callbacks.toArray(new Class[callbacks.size()]); } }
public CallbackHelper(Class superclass, Class[] interfaces) { List methods = new ArrayList(); Enhancer.getMethods(superclass, interfaces, methods); Map indexes = new HashMap(); for (int i = 0, size = methods.size(); i < size; i++) { Method method = (Method)methods.get(i); Object callback = getCallback(method); if (callback == null) throw new IllegalStateException("getCallback cannot return null"); boolean isCallback = callback instanceof Callback; if (!(isCallback || (callback instanceof Class))) throw new IllegalStateException("getCallback must return a Callback or a Class"); if (i > 0 && ((callbacks.get(i - 1) instanceof Callback) ^ isCallback)) throw new IllegalStateException("getCallback must return a Callback or a Class consistently for every Method"); Integer index = (Integer)indexes.get(callback); if (index == null) { index = new Integer(callbacks.size()); indexes.put(callback, index); } methodMap.put(method, index); callbacks.add(callback); } }