コード例 #1
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");
    }

    // obtain correct configuration objects
    // default vs dynamic
    Configuration inputConfig = this.inputConf;
    Configuration mConf = null;
    String inputName = null;
    if (modeConf != null) {
      mConf = modeConf.getChild("input-module");
      inputName = modeConf.getChild("input-module").getAttribute("name", null);
      if (inputName != null) {
        inputConfig = modeConf.getChild("input-module");
      }
    }

    // done reading configuration
    // setup modules and read values
    Iterator enumeration =
        getNames(objectModel, this.input, this.defaultInput, inputConfig, null, inputName, mConf);
    return enumeration;
  }
コード例 #2
0
  public void configure(Configuration config) throws ConfigurationException {

    // It seems that even if there is no config, we'll get an empty
    // input-module element here, so it will never be null (JT)
    this.inputConf = config.getChild("input-module");
    this.defaultInput = this.inputConf.getAttribute("name", this.defaultInput);
    this.prefix = config.getChild("prefix").getValue(null);
    this.suffix = config.getChild("suffix").getValue(null);
    this.rmPrefix = config.getChild("rm-prefix").getValue(null);
    this.rmSuffix = config.getChild("rm-suffix").getValue(null);
    this.mapping = new Mapping(config);
  }
コード例 #3
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);
    }
  }
コード例 #4
0
ファイル: HTMLTransformer.java プロジェクト: tpso-src/cocoon
  /** Configure this transformer, possibly passing to it a jtidy configuration file location. */
  public void configure(Configuration config) throws ConfigurationException {
    super.configure(config);

    String configUrl = config.getChild("jtidy-config").getValue(null);
    if (configUrl != null) {
      org.apache.excalibur.source.SourceResolver resolver = null;
      Source configSource = null;
      try {
        resolver =
            (org.apache.excalibur.source.SourceResolver)
                this.manager.lookup(org.apache.excalibur.source.SourceResolver.ROLE);
        configSource = resolver.resolveURI(configUrl);
        if (getLogger().isDebugEnabled()) {
          getLogger().debug("Loading configuration from " + configSource.getURI());
        }
        this.properties = new Properties();
        this.properties.load(configSource.getInputStream());

      } catch (Exception e) {
        getLogger().warn("Cannot load configuration from " + configUrl);
        throw new ConfigurationException("Cannot load configuration from " + configUrl, e);
      } finally {
        if (null != resolver) {
          this.manager.release(resolver);
          resolver.release(configSource);
        }
      }
    }
  }
コード例 #5
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;
  }
コード例 #6
0
  /** Create root jxpath configuration */
  public JXPathHelperConfiguration(Configuration config) throws ConfigurationException {
    this.lenient = config.getChild("lenient").getValueAsBoolean(true);
    this.library = new FunctionLibrary();
    setup(config);

    // the following is necessary to be able to use methods on objects without
    // explicitely registering extension functions (see PackageFunctions javadoc)
    this.library.addFunctions(new PackageFunctions("", null));
  }
コード例 #7
0
  public void configure(Configuration config) throws ConfigurationException {

    this.inputConf = config.getChild("input-module");
    this.defaultInput = this.inputConf.getAttribute("name", this.defaultInput);
    this.defaultFormat = this.inputConf.getAttribute("format", this.defaultFormat);
    if (this.defaultFormat != null) {
      this.defaultFormatter = new SimpleDateFormat(this.defaultFormat);
    }
  }
コード例 #8
0
ファイル: ClientTimeImpl.java プロジェクト: TU-Berlin/Mumie
 /** Configures this instance. See class decription for details. */
 public void configure(Configuration configuration) throws ConfigurationException {
   final String METHOD_NAME = "configure";
   this.logDebug(METHOD_NAME + " 1/2: Started");
   try {
     this.offset = Long.parseLong(configuration.getChild("offset").getValue("0").trim());
     this.logDebug(METHOD_NAME + " 2/2: Done. offset = " + offset);
   } catch (Exception exception) {
     throw new ConfigurationException("Wrapped exception", exception);
   }
 }
コード例 #9
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);
   }
 }
コード例 #10
0
  /**
   * 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);
  }
コード例 #11
0
    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());
      }
    }
コード例 #12
0
  /**
   * 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));
      }
    }
  }
コード例 #13
0
  /** @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 += " ";
    }
  }
コード例 #14
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);
       }
     }
   }
 }
コード例 #15
0
  /**
   * 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);
      }
    }
  }
コード例 #16
0
ファイル: SendNewsletter.java プロジェクト: wyona/lenya
 /* (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");
   }
 }
コード例 #17
0
  /**
   * 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
        }
      }
    }
  }
コード例 #18
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;
 }
コード例 #19
0
  /**
   * 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);
      }
    }
  }
コード例 #20
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;
  }
コード例 #21
0
  public void configure(Configuration configuration) throws ConfigurationException {
    configure = true;

    plexusHome = configuration.getChild("plexus-home").getValue();
  }
コード例 #22
0
 /**
  * Configures the factory.
  *
  * @param configuration the Configuration
  * @exception ConfigurationException if an error occurs
  */
 public void configure(final Configuration configuration) throws ConfigurationException {
   super.configure(configuration);
   m_verifyServerIdentity =
       configuration.getChild("verify-server-identity").getValueAsBoolean(false);
 }
コード例 #23
0
 /** @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration) */
 public void configure(Configuration conf) throws ConfigurationException {
   this.conf = conf;
   numThreads = conf.getChild("threads").getValueAsInteger(1);
 }
コード例 #24
0
  /** Configure this transformer. */
  public void configure(Configuration conf) throws ConfigurationException {
    Configuration child;

    child = conf.getChild("use-request-parameters");
    this.useParameters = child.getValueAsBoolean(false);
    this._useParameters = this.useParameters;

    child = conf.getChild("use-cookies");
    this.useCookies = child.getValueAsBoolean(false);
    this._useCookies = this.useCookies;

    child = conf.getChild("use-session-info");
    this.useSessionInfo = child.getValueAsBoolean(false);
    this._useSessionInfo = this.useSessionInfo;

    child = conf.getChild("transformer-factory");
    // traxFactory is null, if transformer-factory config is unspecified
    final String traxFactory = child.getValue(null);

    child = conf.getChild("xslt-processor-role");
    String xsltProcessorRole = child.getValue(XSLTProcessor.ROLE);
    if (!xsltProcessorRole.startsWith(XSLTProcessor.ROLE)) {
      xsltProcessorRole = XSLTProcessor.ROLE + '/' + xsltProcessorRole;
    }

    child = conf.getChild("check-includes");
    this.checkIncludes = child.getValueAsBoolean(this.checkIncludes);

    child = conf.getChild("default-src", false);
    if (child != null) {
      this.defaultSrc = child.getValue();
    }

    if (getLogger().isDebugEnabled()) {
      getLogger().debug("Use parameters is " + this.useParameters);
      getLogger().debug("Use cookies is " + this.useCookies);
      getLogger().debug("Use session info is " + this.useSessionInfo);
      getLogger().debug("Use TrAX Processor " + xsltProcessorRole);
      getLogger().debug("Check for included stylesheets is " + this.checkIncludes);
      if (traxFactory != null) {
        getLogger().debug("Use TrAX Transformer Factory " + traxFactory);
      } else {
        getLogger().debug("Use default TrAX Transformer Factory.");
      }
      getLogger().debug("Default source = " + this.defaultSrc);
    }

    try {
      this.xsltProcessor = (XSLTProcessor) this.manager.lookup(xsltProcessorRole);
      if (traxFactory != null) {
        this.xsltProcessor.setTransformerFactory(traxFactory);
      }
    } catch (ServiceException e) {
      throw new ConfigurationException("Cannot load XSLT processor", e);
    }

    try {
      // see the recyle() method to see what we need this for
      Class dtmManagerClass = Class.forName("org.apache.xml.dtm.DTMManager");
      xalanDtmManagerGetIncrementalMethod = dtmManagerClass.getMethod("getIncremental", null);
    } catch (ClassNotFoundException e) {
      // do nothing -- user does not use xalan, so we don't need the dtm manager
    } catch (NoSuchMethodException e) {
      throw new ConfigurationException(
          "Was not able to get getIncremental method from Xalan's DTMManager.", e);
    }
  }
コード例 #25
0
  /** @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();
    }
  }
コード例 #26
0
 public void configure(Configuration config) throws ConfigurationException {
   this.defaultName = config.getChild("parameter-name").getValue(null);
 }
コード例 #27
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();
  }
コード例 #28
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;
  }