Ejemplo n.º 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. 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();
  }