Exemplo n.º 1
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);
    }
  }
Exemplo n.º 2
0
  public ProcessingNode buildNode(Configuration config) throws Exception {
    String source = config.getAttribute("src");

    this.node = new ScriptNode(source);
    this.treeBuilder.setupNode(this.node, config);

    return this.node;
  }
  /**
   * Create a LogTarget based on a supplied configuration
   *
   * @param config the target coonfiguration
   * @return the log target
   */
  public LogTarget createTarget(final Configuration config) throws LogTargetException {
    final String spec = config.getAttribute("artifact", null);
    if (null == spec) {
      final String error = REZ.getString("plugin.error.missing-artifact");
      throw new LogTargetException(error);
    }

    LogTargetFactory factory = getLogTargetFactory(spec);
    return factory.createTarget(config);
  }
Exemplo n.º 4
0
 /* (non-Javadoc)
  * @see org.apache.lenya.cms.usecase.AbstractUsecase#configure(org.apache.avalon.framework.configuration.Configuration)
  */
 public void configure(Configuration config) throws ConfigurationException {
   super.configure(config);
   Configuration newsletterConfig = config.getChild(NEWSLETTER_ELEMENT_NAME);
   Configuration senderConfig = newsletterConfig.getChild(SENDER_ELEMENT_NAME);
   if (senderConfig == null) {
     throw new ConfigurationException("A newsletter must have a sender");
   }
   this.senderName = senderConfig.getAttribute(NAME_ATTRIBUTE_NAME);
   if (this.senderName == null) {
     throw new ConfigurationException("The sender name has to be specified");
   }
   this.senderEmailAddress = senderConfig.getAttribute(ADDR_ATTRIBUTE_NAME);
   if (this.senderEmailAddress == null) {
     throw new ConfigurationException("The sender email address has to be specified");
   }
   Configuration formatConfiguration = newsletterConfig.getChild(FORMAT_ELEMENT_NAME);
   this.formatName = formatConfiguration.getAttribute(NAME_ATTRIBUTE_NAME);
   if (this.formatName == null) {
     throw new ConfigurationException("The format name must be specified");
   }
 }
    public void process(XPathContext context) throws XPathException {
      String effMessage = message.evaluateAsString(context);
      int effOrientation = 0;
      if (orientation != null) {
        String s = orientation.evaluateAsString(context);
        try {
          effOrientation = Integer.parseInt(s);
          effOrientation = BarcodeDimension.normalizeOrientation(effOrientation);
        } catch (NumberFormatException nfe) {
          throw new ValidationException(nfe);
        } catch (IllegalArgumentException iae) {
          throw new ValidationException(iae);
        }
      }

      try {
        SequenceReceiver out = context.getReceiver();

        // Acquire BarcodeGenerator
        final BarcodeGenerator gen = BarcodeUtil.getInstance().createBarcodeGenerator(cfg);

        // Setup Canvas
        final SVGCanvasProvider svg;
        if (cfg.getAttributeAsBoolean("useNamespace", true)) {
          svg = new SVGCanvasProvider(cfg.getAttribute("prefix", "svg"), effOrientation);
        } else {
          svg = new SVGCanvasProvider(false, effOrientation);
        }
        // Generate barcode
        gen.generateBarcode(svg, effMessage);

        DocumentWrapper wrapper =
            new DocumentWrapper(
                svg.getDOM(), SVGCanvasProvider.SVG_NAMESPACE, context.getConfiguration());
        out.append(wrapper, this.getLocationId(), 1);

      } catch (ConfigurationException ce) {
        throw new DynamicError("(Barcode4J) " + ce.getMessage());
      } catch (BarcodeException be) {
        throw new DynamicError("(Barcode4J) " + be.getMessage());
      }
    }
Exemplo n.º 6
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");
    }

    // obtain correct configuration objects
    // default vs dynamic
    Configuration mConf = null;
    String inputName = null;
    String parameter = name;
    String format = this.defaultFormat;
    DateFormat formatter = null;
    if (modeConf != null) {
      mConf = modeConf.getChild("input-module");
      inputName = modeConf.getChild("input-module").getAttribute("name", null);
      parameter = modeConf.getAttribute("parameter", parameter);
      format = modeConf.getAttribute("format", format);
      // preferred:
      parameter = modeConf.getChild("parameter").getValue(parameter);
      format = modeConf.getChild("format").getValue(format);
    }
    if (this.defaultFormat.equals(format)) {
      formatter = this.defaultFormatter;
    } else {
      formatter = new SimpleDateFormat(format);
    }

    Object[] values =
        getValues(
            parameter,
            objectModel,
            this.input,
            this.defaultInput,
            this.inputConf,
            null,
            inputName,
            mConf);

    Object[] dates = null;
    if (values != null) {
      dates = new Object[values.length];
      for (int i = 0; i < values.length; i++)
        try {
          dates[i] = formatter.parse(String.valueOf(values[i]));
        } catch (Exception e) {
          if (getLogger().isWarnEnabled())
            getLogger()
                .warn(
                    "Problem: Aquired '"
                        + values[i]
                        + "' from '"
                        + inputName
                        + "' for '"
                        + name
                        + "' using format '"
                        + format
                        + "' : "
                        + e.getMessage());
        }
    }
    return dates;
  }
  /** @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();
    }
  }