コード例 #1
0
ファイル: ProtocolManager.java プロジェクト: fomeister/sal
  /* (non-Javadoc)
   * @see jcu.sal.managers.ManagerFactory#build(org.w3c.dom.Document)
   */
  @Override
  protected AbstractProtocol build(ProtocolConfiguration config, Identifier id)
      throws ComponentInstantiationException {
    AbstractProtocol p = null;
    String type = config.getType();
    ProtocolID i = (ProtocolID) id;
    try {

      // logger.debug("building AbstractProtocol type: " + type);
      String className = PluginList.getProtocolClassName(type);

      Class<?>[] params = {ProtocolID.class, ProtocolConfiguration.class};
      Constructor<?> c = Class.forName(className).getConstructor(params);
      Object[] o = new Object[2];
      o[0] = i;
      o[1] = config;
      // logger.debug("AbstractProtocol config: " + XMLhelper.toString(config));
      p = (AbstractProtocol) c.newInstance(o);
      // logger.debug("done building protocol "+p.toString());
    } catch (Throwable e) {
      logger.error("Error in new protocol instanciation.");
      e.printStackTrace();
      logger.error("XML doc:\n");
      logger.error(config.getXMLString());
      throw new ComponentInstantiationException("Unable to instantiate component", e);
    }

    // check if there are other instances of the same type
    try {
      if (!p.supportsMultipleInstances() && getComponentsOfType(type).size() != 0) {
        logger.debug(
            "Found another instance of type '"
                + type
                + "' which doesnt support multiple instance, deleting this protocol");
        throw new ComponentInstantiationException(
            "Found another instance of type '"
                + type
                + "' which doesnt support multiple instances");
      }
    } catch (NotFoundException e) {
    } // no other instances

    // Parse the protocol's configuration
    try {
      p.parseConfig();
    } catch (ConfigurationException e1) {
      logger.error("Error in the protocol configuration:\n" + e1.getMessage());
      // e1.printStackTrace();
      throw new ComponentInstantiationException();
    }

    // save protocol config
    conf.addProtocol(config);

    ev.queueEvent(
        new ProtocolListEvent(
            ProtocolListEvent.PROTOCOL_ADDED, i.getName(), Constants.PROTOCOL_MANAGER_PRODUCER_ID));
    logger.debug("Created protocol '" + config.getID() + "' - type: " + type);
    return p;
  }
コード例 #2
0
ファイル: ProtocolManager.java プロジェクト: fomeister/sal
 /* (non-Javadoc)
  * @see jcu.sal.managers.ManagerFactory#getComponentID(org.w3c.dom.Document)
  */
 @Override
 protected Identifier getComponentID(ProtocolConfiguration n) {
   return new ProtocolID(n.getID());
 }