/**
   * Create the channel instance and sets its name.
   *
   * <p>If the channel class matches to constructor parameters of the default channel (ChannelImpl)
   * that constructor is used, else the empty constructor is invoked.
   *
   * @param channelClass Channel implementation class to instanciate.
   * @param name Name of the channel.
   * @return a new Channel instance.
   * @throws IllegalStateException if a channel with name already created or channelClass could not
   *     be instancieated.
   */
  protected Channel getNewChannel(Class<? extends Channel> channelClass, String name)
      throws IllegalStateException {
    try {
      channelRegister.getChannel(name);
      throw new IllegalStateException("Channel with name " + name + " has already been created.");
    } catch (NoSuchChannelException nsce) {
      try {
        if (ChannelImpl.class.isAssignableFrom(channelClass)) {

          Constructor<? extends Channel> cons =
              channelClass.getConstructor(
                  String.class,
                  ChannelRegister.class,
                  EventRegister.class,
                  EventMethodInvoker.class,
                  BeanResolver.class);
          return cons.newInstance(
              name, channelRegister, eventRegister, eventMethodInvoker, beanResolver);
        } else {
          Channel channel = channelClass.newInstance();
          channel.setName(name);
          return channel;
        }
      } catch (Exception e) {
        throw new IllegalStateException(
            "Could not find or instanciate channel class " + channelClass, e);
      }
    }
  }
Beispiel #2
0
  /**
   * Register a new Event type to the register.
   *
   * @param eventClass New event type to handle
   * @throws NoSuchEventException if no event can be found of type eventClass.
   */
  @Override
  public void registerEvent(Class<? extends EventObject> eventClass) throws NoSuchEventException {
    EventConfig eventConfig = eventRegister.getEventByClass(eventClass);

    if (!eventMap.containsKey(eventClass)) {
      if (eventConfig.getListener() != null) {
        eventMap.put(eventClass, eventConfig.getListener());
      }
      channelRegister.registerEventHandler(this, eventClass);
    }
  }
  /**
   * Creates and registers a new channel of the supplied channel class, registers all events.
   *
   * @param channelClass The channel implementation to use (default is ChannelImpl).
   * @param channelName Name of the new channel.
   * @param events Set of events to register at the channel.
   * @return The newly created channel.
   */
  public Channel createChannel(
      Class<? extends Channel> channelClass,
      String channelName,
      Set<Class<? extends EventObject>> events) {
    Channel channel = getNewChannel(channelClass, channelName);
    channelRegister.registerChannel(channel);
    for (Class<? extends EventObject> eventClass : events) {
      channel.registerEvent(eventClass);
    }

    return channel;
  }
 /**
  * Creates and registers a new channel of the supplied channel class, registers all events.
  *
  * @param channelClass The channel implementation to use (default is ChannelImpl).
  * @param channelName Name of the new channel.
  * @param events Set of events to register at the channel.
  * @param listeners Listeners to register at the channel.
  * @return The newly created channel.
  */
 public ListenerChannel createChannel(
     Class<? extends ListenerChannel> channelClass,
     String channelName,
     Set<Class<? extends EventObject>> events,
     Set<EventListener> listeners) {
   ListenerChannel channel = (ListenerChannel) getNewChannel(channelClass, channelName);
   for (Class<? extends EventObject> eventClass : events) {
     channel.registerEvent(eventClass);
   }
   for (EventListener listener : listeners) {
     channel.registerListener(listener);
   }
   channelRegister.registerChannel(channel);
   return channel;
 }
Beispiel #5
0
 /**
  * Unregister the event from this channel.
  *
  * @param eventClass Class of the event to unregister.
  */
 @Override
 public void unregisterEvent(Class<? extends EventObject> eventClass) {
   eventMap.remove(eventClass);
   channelRegister.unregisterEventHandler(this, eventClass);
 }
 /**
  * Creates and registers a new channel of the default implementation ChannelImpl.
  *
  * @param channelClass The channel implementation to use (default is ChannelImpl).
  * @param channelName Name of the new channel
  * @return The newly created channel.
  */
 public Channel createChannel(Class<? extends Channel> channelClass, String channelName) {
   Channel channel = getNewChannel(channelClass, channelName);
   channelRegister.registerChannel(channel);
   return channel;
 }