public static void setParameterValue(ParametersType paType, String paramName, Object value) {
   if (value == null) {
     return;
   }
   EList listParamType = paType.getElementParameter();
   if (!isContains(paType, paramName)) {
     ElementParameterType etype = TalendFileFactory.eINSTANCE.createElementParameterType();
     etype.setName(paramName);
     listParamType.add(etype);
   }
   for (int j = 0; j < listParamType.size(); j++) {
     ElementParameterType pType = (ElementParameterType) listParamType.get(j);
     if (pType != null && paramName.equals(pType.getName())) {
       pType.setValue(value.toString());
       return;
     }
   }
 }
Пример #2
0
  /**
   * wchen Comment method "updateParameters".
   *
   * @param node
   * @param attrMap
   * @param statAndLogs
   */
  private void updateParameters(final Node node, final NamedNodeMap attrMap, List statAndLogs) {
    boolean added = false;
    for (Object obj : statAndLogs) {
      ElementParameterType type = (ElementParameterType) obj;
      if (type.getName().equals(attrMap.getNamedItem("name").getTextContent())) { // $NON-NLS-1$
        type.setValue(node.getTextContent());
        added = true;
      }
    }
    // if there is no such parameter in current settings add one
    TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
    if (added == false) {

      ElementParameterType type = talendF.createElementParameterType();
      type.setName(attrMap.getNamedItem("name").getTextContent()); // $NON-NLS-1$
      type.setValue(node.getTextContent());
      statAndLogs.add(type);
    }
  }
 /**
  * load project settings to no-opened process
  *
  * @param elemParam
  * @param projectPaType
  */
 public static void loadElementParameters(
     ParametersType processType, ParametersType projectPaType, EParameterName paramName) {
   EList listParamType = projectPaType.getElementParameter();
   for (int j = 0; j < listParamType.size(); j++) {
     ElementParameterType pType = (ElementParameterType) listParamType.get(j);
     EList processParameters = processType.getElementParameter();
     ElementParameterType processParam = null;
     for (int i = 0; i < processParameters.size(); i++) {
       ElementParameterType paramType = (ElementParameterType) processParameters.get(i);
       if (paramType.getName().equals(pType.getName())
           && paramType.getField() != null
           && paramType.getField().equals(pType.getField())) {
         processParam = paramType;
       } else if (pType.getName().contains(":")) {
         StringTokenizer token = new StringTokenizer(pType.getName(), ":"); // $NON-NLS-1$
         String parentId = token.nextToken();
         String childId = token.nextToken();
         String[] split = paramType.getName().split(":");
         if (split.length != 2) {
           continue;
         }
         String complexName = paramName + ":" + childId;
         if (complexName.equals(paramType.getName())) {
           processParam = paramType;
         }
       }
       if (processParam != null) {
         break;
       }
     }
     if (processParam != null) {
       processParam.setValue(pType.getValue());
     } else {
       TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
       ElementParameterType processTypes = fileFact.createElementParameterType();
       processTypes.setName(pType.getName());
       processTypes.setField(pType.getField());
       processTypes.setValue(pType.getValue());
       processType.getElementParameter().add(processTypes);
     }
   }
 }
  public static ElementParameterType getElemeterParameterType(IElementParameter param) {
    if (param == null) {
      return null;
    }
    ElementParameterType targetPramType = TalendFileFactory.eINSTANCE.createElementParameterType();
    if (param.getParentParameter() != null) {
      targetPramType.setName(
          param.getParentParameter().getName() + ":" + param.getName()); // $NON-NLS-1$
    } else {
      targetPramType.setName(param.getName());
    }
    targetPramType.setField(param.getFieldType().getName());
    targetPramType.setContextMode(param.isContextMode());
    Object value = param.getValue();
    if (param.getFieldType().equals(EParameterFieldType.TABLE) && value != null) {
      List<Map<String, Object>> tableValues = (List<Map<String, Object>>) value;
      for (Map<String, Object> currentLine : tableValues) {
        for (int i = 0; i < param.getListItemsDisplayCodeName().length; i++) {
          ElementValueType elementValue = TalendFileFactory.eINSTANCE.createElementValueType();
          elementValue.setElementRef(param.getListItemsDisplayCodeName()[i]);
          Object o = currentLine.get(param.getListItemsDisplayCodeName()[i]);

          IElementParameter tmpParam = null;
          Object[] listItemsValue = param.getListItemsValue();
          if (listItemsValue.length > i) {
            tmpParam = (IElementParameter) listItemsValue[i];
          }
          String strValue = ""; // $NON-NLS-1$
          if (o instanceof Integer && tmpParam != null) {
            if (tmpParam.getListItemsValue().length == 0) {
              strValue = ""; // $NON-NLS-1$
            } else {
              strValue = (String) tmpParam.getListItemsValue()[(Integer) o];
            }
          } else {
            if (o instanceof String) {
              strValue = (String) o;
            } else {
              if (o instanceof Boolean) {
                strValue = ((Boolean) o).toString();
              }
            }
          }
          if (tmpParam != null && tmpParam.getFieldType().equals(EParameterFieldType.PASSWORD)) {
            elementValue.setValue(strValue, true);
          } else {
            elementValue.setValue(strValue);
          }
          //
          Object object =
              currentLine.get(param.getListItemsDisplayCodeName()[i] + IEbcdicConstant.REF_TYPE);
          if (object != null) {
            elementValue.setType((String) object);
          }
          targetPramType.getElementValue().add(elementValue);
        }
      }
    } else {
      if (value == null) {
        targetPramType.setValue(""); // $NON-NLS-1$
      } else {
        if (value instanceof Boolean) {
          targetPramType.setValue(((Boolean) value).toString());
        } else {
          if (value instanceof String) {
            targetPramType.setRawValue(value.toString());
          }
        }
      }
    }

    return targetPramType;
  }