@Test public void testFindAllHandlers() { Sub listener = new Sub(); Map<Class<? >, Set<EventHandler>> map = new ListenerHandlerFinder().findAllHandlers(listener); assertTrue(map.containsKey(SimpleEvent.class)); Collection<EventHandler> handlers = map.get(SimpleEvent.class); assertTrue(handlers.size() == 1); Iterator<EventHandler> iterator = handlers.iterator(); assertTrue(iterator.hasNext()); EventHandler handler = iterator.next(); try { assertTrue(handler.equals(new EventHandler(listener,listener.getClass().getMethod(ISubscribe.methodName,SimpleEvent.class)))); } catch (NoSuchMethodException e) { fail(); } }
@Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInListener = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); Type[] types = clazz.getGenericInterfaces(); for(Type type : types) { if(type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(!parameterizedType.getRawType().equals(ISubscribe.class)) { continue; } Type[] typeArguments = parameterizedType.getActualTypeArguments(); if(typeArguments.length == 1) { try { Class<?> eventType = ((Class)typeArguments[0]); Method method = clazz.getMethod(ISubscribe.methodName,eventType); EventHandler handler = makeHandler(listener, method); put(methodsInListener,eventType, handler); } catch (Exception e) { throw new IllegalArgumentException( "Method has not implements ISubscribe "); } } } } return methodsInListener; }
ListenerHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInListener = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); Type[] types = clazz.getGenericInterfaces(); for(Type type : types) { if(type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(!parameterizedType.getRawType().equals(ISubscribe.class)) { continue; } Type[] typeArguments = parameterizedType.getActualTypeArguments(); if(typeArguments.length == 1) { try { Class<?> eventType = ((Class)typeArguments[0]); Method method = clazz.getMethod(ISubscribe.methodName,eventType); EventHandler handler = makeHandler(listener, method); put(methodsInListener,eventType, handler); } catch (Exception e) { throw new IllegalArgumentException( "Method has not implements ISubscribe "); } } } } return methodsInListener; } }
ListenerHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInListener = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); Type[] types = clazz.getGenericInterfaces(); for(Type type : types) { if(type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(!parameterizedType.getRawType().equals(ISubscribe.class)) { continue; } Type[] typeArguments = parameterizedType.getActualTypeArguments(); if(typeArguments.length == 1) { try { Class<?> eventType = ((Class)typeArguments[0]); Method method = clazz.getMethod(ISubscribe.methodName,eventType); EventHandler handler = makeHandler(listener, method); put(methodsInListener,eventType, handler); } catch (Exception e) { throw new IllegalArgumentException( "Method has not implements ISubscribe "); } } } } return methodsInListener; }  }
ListenerHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInListener = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); Type[] types = clazz.getGenericInterfaces(); for(Type type : types) { if(type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(!parameterizedType.getRawType().equals(ISubscribe.class)) { continue; } Type[] typeArguments = parameterizedType.getActualTypeArguments(); if(typeArguments.length == 1) { try { Class<?> eventType = ((Class)typeArguments[0]); Method method = clazz.getMethod(ISubscribe.methodName,eventType); EventHandler handler = makeHandler(listener, method); put(methodsInListener,eventType, handler); } catch (Exception e) { throw new IllegalArgumentException( "Method has not implements ISubscribe "); } } } } return methodsInListener; }  @Override Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener); }
ListenerHandlerFinder extends AbstractHandlerFinder { @Override public Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener) { Map<Class<?>, Set<EventHandler>> methodsInListener = new HashMap<Class<?>, Set<EventHandler>>(); Class clazz = listener.getClass(); Type[] types = clazz.getGenericInterfaces(); for(Type type : types) { if(type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; if(!parameterizedType.getRawType().equals(ISubscribe.class)) { continue; } Type[] typeArguments = parameterizedType.getActualTypeArguments(); if(typeArguments.length == 1) { try { Class<?> eventType = ((Class)typeArguments[0]); Method method = clazz.getMethod(ISubscribe.methodName,eventType); EventHandler handler = makeHandler(listener, method); put(methodsInListener,eventType, handler); } catch (Exception e) { throw new IllegalArgumentException( "Method has not implements ISubscribe "); } } } } return methodsInListener; }  @Override Map<Class<?>, Set<EventHandler>> findAllHandlers(Object listener);  }