Пример #1
0
 /**
  * Configures the module.
  *
  * <p>Takes all elements nested in component declaration and stores them as key-value pairs in
  * <code>settings</code>. Nested configuration option are not catered for. This way global
  * configuration options can be used.
  *
  * <p>For nested configurations override this function.
  */
 public void configure(Configuration conf) throws ConfigurationException {
   Configuration[] parameters = conf.getChildren();
   // Ideally here should be length * 1.333(3) but simple +1 will do for lengths up to 3
   this.settings = new HashMap(parameters.length + 1);
   for (int i = 0; i < parameters.length; i++) {
     String key = parameters[i].getName();
     String val = parameters[i].getValue("");
     this.settings.put(key, val);
   }
 }
  /**
   * Register all extension packages listed in the configuration through <code>
   * &lt;package name="fully.qualified.package"
   * prefix="prefix"/&gt;</code> in the given FunctionLibrary.
   *
   * @param conf a <code>Configuration</code> value
   */
  private void getPackages(Configuration conf) {

    Configuration[] children = conf.getChildren("package");
    int i = children.length;
    while (i-- > 0) {
      String packageName = children[i].getAttribute("name", null);
      String prefix = children[i].getAttribute("prefix", null);
      if (packageName != null && prefix != null) {
        this.library.addFunctions(new PackageFunctions(packageName, prefix));
      }
    }
  }
  /**
   * Register all namespaces listed in the configuration through <code>&lt;namespace uri="uri:foo"
   * prefix="bar"/&gt;</code> in the configuration.
   *
   * @param conf a <code>Configuration</code> value
   */
  private void getNamespaces(Configuration conf) throws ConfigurationException {

    Configuration[] children = conf.getChildren("namespace");
    int i = children.length;
    if (i > 0) {
      this.namespaces = new HashMap(i + 2);
    }
    while (i-- > 0) {
      String uri = children[i].getAttribute("uri");
      String prefix = children[i].getAttribute("prefix");
      if (uri != null && prefix != null) {
        this.namespaces.put(prefix, uri);
      }
    }
  }
Пример #4
0
 public Mapping(Configuration config) throws ConfigurationException {
   Configuration[] mappings = config.getChildren("mapping");
   if (mappings != null) {
     if (this.toMap == null) this.toMap = new HashMap();
     if (this.fromMap == null) this.fromMap = new HashMap();
     for (int i = 0; i < mappings.length; i++) {
       String in = mappings[i].getAttribute("in", null);
       String out = mappings[i].getAttribute("out", null);
       if (in != null && out != null) {
         this.toMap.put(in, out);
         this.fromMap.put(out, in);
       }
     }
   }
 }
Пример #5
0
  /** Creation of a input descriptor based on a supplied Configuration instance. */
  public InputDescriptor(Configuration conf) {
    if (conf == null) throw new RuntimeException("Null configuration.");
    try {
      tag = conf.getAttribute("tag", "");
      required = conf.getAttributeAsBoolean("required", false);
      implied = conf.getAttributeAsBoolean("implied", false);
      type = ORB.init().create_interface_tc(conf.getAttribute("type", ""), "");

      Configuration[] children = conf.getChildren();
      if (children.length > 0) {
        criteria = DPML.buildCriteriaElement(children[0]);
      }
    } catch (Exception e) {
      throw new RuntimeException("Failed to configure a input usage decriptor.", e);
    }
  }
  /** @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration) */
  public void configure(final Configuration configuration) throws ConfigurationException {

    super.configure(configuration);
    if (isEnabled()) {
      Configuration handlerConfiguration = configuration.getChild("handler");
      Configuration admin = handlerConfiguration.getChild("administrator_accounts");
      Configuration[] accounts = admin.getChildren("account");
      for (int i = 0; i < accounts.length; i++) {
        adminAccounts.put(accounts[i].getAttribute("login"), accounts[i].getAttribute("password"));
      }
      Configuration promtConfiguration = handlerConfiguration.getChild("prompt", false);
      if (promtConfiguration != null) prompt = promtConfiguration.getValue();
      if (prompt == null) prompt = "";
      else if (!prompt.equals("") && !prompt.endsWith(" ")) prompt += " ";
    }
  }
  /**
   * Register all extension functions listed in the configuration through <code>
   * &lt;function name="fully.qualified.Class"
   * prefix="prefix"/&gt;</code> in the given FunctionLibrary.
   *
   * @param conf a <code>Configuration</code> value
   */
  private void getFunctions(Configuration conf) {

    Configuration[] children = conf.getChildren("function");
    int i = children.length;
    while (i-- > 0) {
      String clazzName = children[i].getAttribute("name", null);
      String prefix = children[i].getAttribute("prefix", null);
      if (clazzName != null && prefix != null) {
        try {
          Class clazz = Class.forName(clazzName);
          this.library.addFunctions(new ClassFunctions(clazz, prefix));
        } catch (ClassNotFoundException cnf) {
          // ignore
        }
      }
    }
  }
Пример #8
0
 /**
  * Create a new parameters object from the children of the configuration. If no children are
  * available <code>null</code> is returned.
  */
 public static SourceParameters createSourceParameters(Configuration conf) {
   Configuration[] children = conf.getChildren();
   if (children != null && children.length > 0) {
     SourceParameters pars = new SourceParameters();
     String name;
     String value;
     for (int i = 0; i < children.length; i++) {
       name = children[i].getName();
       try {
         value = children[i].getValue();
       } catch (ConfigurationException local) {
         value = ""; // ignore exception
       }
       pars.setParameter(name, value);
     }
     return pars;
   }
   return null;
 }
  /**
   * Perform configuration.
   *
   * @param configuration The configuration.
   * @throws ConfigurationException If an error occurs while attempting to perform configuration.
   */
  public void configure(Configuration configuration) throws ConfigurationException {
    Configuration[] resourceConfigs = configuration.getChildren();

    for (int i = 0; i < resourceConfigs.length; ++i) {
      try {
        if (resourceConfigs[i].getName().equals("directory")) {
          addDirectoryResource(resourceConfigs[i].getValue());
        } else if (resourceConfigs[i].getName().equals("jar")) {
          addJarResource(resourceConfigs[i].getValue());
        } else if (resourceConfigs[i].getName().equals("jar-repository")) {
          addJarRepository(resourceConfigs[i].getValue());
        } else if (resourceConfigs[i].getName().equals("url")) {
          addUrlResource(resourceConfigs[i].getValue());
        } else if (resourceConfigs[i].getName().equals("component")) {
          addComponentResourceJar(resourceConfigs[i].getValue());
        } else {
          getLogger().warn("unknown resource type: " + resourceConfigs[i].getName());
        }
      } catch (Exception e) {
        throw new ConfigurationException(
            "error configuring resource: " + resourceConfigs[i].getValue(), e);
      }
    }
  }
  /** @see org.apache.avalon.framework.activity.Initializable#initialize() */
  public void initialize() throws Exception {

    getLogger().info("JamesSpoolManager init...");
    spool = (SpoolRepository) compMgr.lookup(SpoolRepository.ROLE);

    MailetLoader mailetLoader = (MailetLoader) compMgr.lookup(MailetLoader.ROLE);
    MatcherLoader matchLoader = (MatcherLoader) compMgr.lookup(MatcherLoader.ROLE);

    // A processor is a Collection of
    processors = new HashMap();

    final Configuration[] processorConfs = conf.getChildren("processor");
    for (int i = 0; i < processorConfs.length; i++) {
      Configuration processorConf = processorConfs[i];
      String processorName = processorConf.getAttribute("name");
      try {
        LinearProcessor processor = new LinearProcessor();
        setupLogger(processor, processorName);
        processor.setSpool(spool);
        processor.initialize();
        processors.put(processorName, processor);

        final Configuration[] mailetConfs = processorConf.getChildren("mailet");
        // Loop through the mailet configuration, load
        // all of the matcher and mailets, and add
        // them to the processor.
        for (int j = 0; j < mailetConfs.length; j++) {
          Configuration c = mailetConfs[j];
          String mailetClassName = c.getAttribute("class");
          String matcherName = c.getAttribute("match");
          Mailet mailet = null;
          Matcher matcher = null;
          try {
            matcher = matchLoader.getMatcher(matcherName);
            // The matcher itself should log that it's been inited.
            if (getLogger().isInfoEnabled()) {
              StringBuffer infoBuffer =
                  new StringBuffer(64)
                      .append("Matcher ")
                      .append(matcherName)
                      .append(" instantiated.");
              getLogger().info(infoBuffer.toString());
            }
          } catch (MessagingException ex) {
            // **** Do better job printing out exception
            if (getLogger().isErrorEnabled()) {
              StringBuffer errorBuffer =
                  new StringBuffer(256)
                      .append("Unable to init matcher ")
                      .append(matcherName)
                      .append(": ")
                      .append(ex.toString());
              getLogger().error(errorBuffer.toString(), ex);
              if (ex.getNextException() != null) {
                getLogger().error("Caused by nested exception: ", ex.getNextException());
              }
            }
            System.err.println("Unable to init matcher " + matcherName);
            System.err.println("Check spool manager logs for more details.");
            // System.exit(1);
            throw ex;
          }
          try {
            mailet = mailetLoader.getMailet(mailetClassName, c);
            if (getLogger().isInfoEnabled()) {
              StringBuffer infoBuffer =
                  new StringBuffer(64)
                      .append("Mailet ")
                      .append(mailetClassName)
                      .append(" instantiated.");
              getLogger().info(infoBuffer.toString());
            }
          } catch (MessagingException ex) {
            // **** Do better job printing out exception
            if (getLogger().isErrorEnabled()) {
              StringBuffer errorBuffer =
                  new StringBuffer(256)
                      .append("Unable to init mailet ")
                      .append(mailetClassName)
                      .append(": ")
                      .append(ex.toString());
              getLogger().error(errorBuffer.toString(), ex);
              if (ex.getNextException() != null) {
                getLogger().error("Caused by nested exception: ", ex.getNextException());
              }
            }
            System.err.println("Unable to init mailet " + mailetClassName);
            System.err.println("Check spool manager logs for more details.");
            // System.exit(1);
            throw ex;
          }
          // Add this pair to the processor
          processor.add(matcher, mailet);
        }

        // Close the processor matcher/mailet lists.
        //
        // Please note that this is critical to the proper operation
        // of the LinearProcessor code.  The processor will not be
        // able to service mails until this call is made.
        processor.closeProcessorLists();

        if (getLogger().isInfoEnabled()) {
          StringBuffer infoBuffer =
              new StringBuffer(64)
                  .append("Processor ")
                  .append(processorName)
                  .append(" instantiated.");
          getLogger().info(infoBuffer.toString());
        }
      } catch (Exception ex) {
        if (getLogger().isErrorEnabled()) {
          StringBuffer errorBuffer =
              new StringBuffer(256)
                  .append("Unable to init processor ")
                  .append(processorName)
                  .append(": ")
                  .append(ex.toString());
          getLogger().error(errorBuffer.toString(), ex);
        }
        throw ex;
      }
    }
    if (getLogger().isInfoEnabled()) {
      StringBuffer infoBuffer =
          new StringBuffer(64)
              .append("Spooler Manager uses ")
              .append(numThreads)
              .append(" Thread(s)");
      getLogger().info(infoBuffer.toString());
    }

    active = true;
    numActive = 0;
    spoolThreads = new java.util.ArrayList(numThreads);
    for (int i = 0; i < numThreads; i++) {
      Thread reader = new Thread(this, "Spool Thread #" + i);
      spoolThreads.add(reader);
      reader.start();
    }
  }
Пример #11
0
  public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
      throws ConfigurationException {

    if (!this.initialized) {
      this.lazy_initialize();
    }
    if (this.defaultInput == null) {
      if (getLogger().isWarnEnabled()) getLogger().warn("No input module given. FAILING");
      return null;
    }

    Configuration inputConfig = null;
    String inputName = null;
    Mapping mapping = this.mapping;
    String prefix = this.prefix;
    String suffix = this.suffix;
    String rmPrefix = this.rmPrefix;
    String rmSuffix = this.rmSuffix;
    if (modeConf != null && modeConf.getChildren().length > 0) {
      inputName = modeConf.getChild("input-module").getAttribute("name", null);
      if (inputName != null) {
        inputConfig = modeConf.getChild("input-module");
      }
      mapping = new Mapping(modeConf);
      prefix = modeConf.getChild("prefix").getValue(null);
      suffix = modeConf.getChild("suffix").getValue(null);
      rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
      rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
    }

    Iterator names =
        getNames(
            objectModel,
            this.input,
            this.defaultInput,
            this.inputConf,
            null,
            inputName,
            inputConfig);

    Set set = new HashSet();
    while (names.hasNext()) {
      String param = (String) names.next();
      if (getLogger().isDebugEnabled())
        getLogger().debug("reverse mapping starts with ['" + param + "']");
      if (prefix != null)
        if (param.startsWith(prefix)) param = param.substring(prefix.length());
        else continue; // prefix is set but parameter does not start with it.

      // if (getLogger().isDebugEnabled())
      //    getLogger().debug("reverse mapping after remove prefix ['"+param+"']");

      if (suffix != null)
        if (param.endsWith(suffix)) param = param.substring(0, param.length() - suffix.length());
        else continue; // suffix is set but parameter does not end with it.

      // if (getLogger().isDebugEnabled())
      //    getLogger().debug("reverse mapping after remove suffix ['"+param+"']");

      if (param.length() < 1) continue; // nothing left

      String newName = mapping.mapFrom(param);

      if (rmPrefix != null) newName = rmPrefix + newName;
      if (rmSuffix != null) newName = newName + rmSuffix;

      if (getLogger().isDebugEnabled())
        getLogger().debug("reverse mapping results in ['" + newName + "']");

      set.add(newName);
    }

    return set.iterator();
  }
Пример #12
0
  public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
      throws ConfigurationException {

    if (!this.initialized) {
      this.lazy_initialize();
    }
    if (this.defaultInput == null) {
      if (getLogger().isWarnEnabled()) getLogger().warn("No input module given. FAILING");
      return null;
    }

    Configuration inputConfig = null;
    String inputName = null;
    Mapping mapping = this.mapping;
    String prefix = this.prefix;
    String suffix = this.suffix;
    String rmPrefix = this.rmPrefix;
    String rmSuffix = this.rmSuffix;

    if (modeConf != null && modeConf.getChildren().length > 0) {
      inputName = modeConf.getChild("input-module").getAttribute("name", null);
      if (inputName != null) {
        inputConfig = modeConf.getChild("input-module");
      }
      mapping = new Mapping(modeConf);
      prefix = modeConf.getChild("prefix").getValue(null);
      suffix = modeConf.getChild("suffix").getValue(null);
      rmPrefix = modeConf.getChild("rm-prefix").getValue(null);
      rmSuffix = modeConf.getChild("rm-suffix").getValue(null);
    }

    // remove rm-prefix and rm-suffix
    if (rmPrefix != null && name.startsWith(rmPrefix)) {
      name = name.substring(rmPrefix.length());
    }
    if (rmSuffix != null && name.endsWith(rmSuffix)) {
      name = name.substring(0, name.length() - rmSuffix.length());
    }
    // map
    String param = mapping.mapTo(name);
    // add prefix and suffix
    if (prefix != null) param = prefix + param;
    if (suffix != null) param = param + suffix;
    if (getLogger().isDebugEnabled())
      getLogger().debug("mapping ['" + name + "'] to ['" + param + "']");

    Object[] res =
        getValues(
            param,
            objectModel,
            this.input,
            this.defaultInput,
            this.inputConf,
            null,
            inputName,
            inputConfig);
    if (getLogger().isDebugEnabled())
      getLogger().debug("getting for real attribute ['" + param + "'] value: " + res);

    return res;
  }