Esempio n. 1
0
  @Override
  public void addViewListener(ApplicationEventListener<? extends ApplicationEvent> listener) {
    if (map == null) {
      map = new HashMap<Class<? extends ApplicationEvent>, Set<ApplicationEventListener<?>>>();
    }

    Set<ApplicationEventListener<?>> listenerSet = map.get(listener.getEventType());
    if (listenerSet == null) {
      listenerSet = new LinkedHashSet<ApplicationEventListener<?>>();
      map.put(listener.getEventType(), listenerSet);
    }

    listenerSet.add(listener);
  }
Esempio n. 2
0
  protected void fireEvent(ApplicationEvent event) {

    log.debug("Fire event: {}", event);

    Class<? extends ApplicationEvent> eventType = event.getClass();

    Set<ApplicationEventListener<?>> eventSet = map.get(eventType);
    if (eventSet != null) {
      Iterator<ApplicationEventListener<?>> listenerSet = map.get(eventType).iterator();

      while (listenerSet.hasNext()) {
        ApplicationEventListener<?> listener = listenerSet.next();
        @SuppressWarnings("unchecked")
        ApplicationEventListener<ApplicationEvent> l =
            (ApplicationEventListener<ApplicationEvent>) listener;
        l.handle(event);
      }
    } else {
      log.error("No listener is registered for event type " + eventType);
    }
  }