package com.chenyang.nse.bussiness.engine.infa.powercenter961.transferdata;

import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.ASSOCIATEDSOURCEINSTANCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.ATTRIBUTE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.CONFIG;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.CONFIGREFERENCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.CONNECTIONREFERENCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.CONNECTOR;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.ERPINFO;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.FOLDER;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.INSTANCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.MAPPING;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.MAPPLET;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.POWERMART;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.REPOSITORY;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SCHEDULEINFO;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SCHEDULER;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SESSION;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SESSIONEXTENSION;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SESSTRANSFORMATIONINST;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SOURCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.SOURCEFIELD;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TABLEATTRIBUTE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TARGET;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TARGETFIELD;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TARGETLOADORDER;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TASK;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TASKINSTANCE;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TRANSFORMATION;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TRANSFORMFIELD;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.WORKFLOW;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.WORKFLOWLINK;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.WORKFLOWVARIABLE;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubtool.DateUtil;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubtool.StringUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProcessXmlInfoUtil {
   public String columnAndMappletInfo = "";
   public String[][] columnInfoMappletInfo = (String[][])null;
   public String[] columnName = null;
   public String[] mappletName = null;
   public MAPPLET[] mapplet = null;
   public String ubdpDeliverInfo = "";
   public String sqUbdpDeliverInfo = "";
   public String dwUbdpDeliverInfo = "";
   public String mUbdpDeliverInfo = "";
   public String smUbdpDeliverInfo = "";
   public String wfDwUbdpDeliverInfo = "";
   public String workFlowInfo = "";
   public String dbdName = "";
   public String sUserName = "";
   public String tUserName = "";
   public String floderName = "";
   public String repositoryName = "";
   public String tOwner = "Administrator";
   public String targetDbConnectionlinkName = "";
   public String sourceDbConnectionNamelinkName = "";
   public String sqlFilterStr = "";

   public POWERMART getPOWERMART(String dbName, String sourceUserName, String targUserName, List<Map> tableInfoList, String colMaplet, String tableName, String infolderName, String repository_name, String sConnectionNamelinkName, String tDbConnectionlinkName, String orgSqlFilterStr) throws Exception {
      this.dbdName = dbName;
      this.sUserName = sourceUserName;
      this.tUserName = targUserName;
      this.floderName = infolderName;
      this.columnAndMappletInfo = colMaplet;
      this.sourceDbConnectionNamelinkName = sConnectionNamelinkName;
      this.targetDbConnectionlinkName = tDbConnectionlinkName;
      this.sqlFilterStr = orgSqlFilterStr;
      this.repositoryName = repository_name;
      if (!this.columnAndMappletInfo.equals("")) {
         this.columnInfoMappletInfo = StringUtil.getTitleInfoBySplit(this.columnAndMappletInfo);
         this.columnName = this.columnInfoMappletInfo[0];
         this.mappletName = this.columnInfoMappletInfo[1];
      } else {
         this.columnName = null;
         this.mappletName = null;
         this.columnInfoMappletInfo = (String[][])null;
         this.mapplet = null;
      }

      this.ubdpDeliverInfo = tableName.toUpperCase();
      this.sqUbdpDeliverInfo = "SQ_" + this.ubdpDeliverInfo;
      this.dwUbdpDeliverInfo = this.ubdpDeliverInfo + "1";
      this.mUbdpDeliverInfo = "m_" + this.ubdpDeliverInfo;
      this.smUbdpDeliverInfo = "s_m_" + this.ubdpDeliverInfo;
      this.wfDwUbdpDeliverInfo = "wf_" + this.ubdpDeliverInfo;
      this.workFlowInfo = "wf_s_" + this.ubdpDeliverInfo;
      POWERMART powermart = new POWERMART();
      powermart.setREPOSITORYVERSION("184.93");
      powermart.setCREATIONDATE(DateUtil.getRightNowForSimpleFormate());
      powermart.getREPOSITORY().add(this.getREPOSITORY(tableInfoList));
      return powermart;
   }

   public REPOSITORY getREPOSITORY(List<Map> tableInfoList) throws Exception {
      REPOSITORY repository = new REPOSITORY();
      repository.setNAME(this.repositoryName);
      repository.setVERSION("184");
      repository.setCODEPAGE("UTF-8");
      repository.setDATABASETYPE("Oracle");
      repository.getFOLDER().add(this.getFOLDERXml(tableInfoList));
      return repository;
   }

   public FOLDER getFOLDERXml(List<Map> tableInfoList) throws Exception {
      Map mapletMap = new HashMap();
      FOLDER folder = new FOLDER();
      folder.setNAME(this.floderName);
      folder.setGROUP("");
      folder.setSHARED("NOTSHARED");
      folder.setOWNER(this.tOwner);
      folder.setPERMISSIONS("rwx---r--");
      folder.setDESCRIPTION(this.floderName);
      folder.setUUID("fa446df9-5844-48a9-bef6-a533aedf4fa3");
      List<MAPPLET> mappleList = this.getMappletInfoXml(this.columnAndMappletInfo);
      if (null != mappleList && mappleList.size() > 0) {
         this.mapplet = new MAPPLET[mappleList.size()];

         for(int k = 0; k < mappleList.size(); ++k) {
            MAPPLET mapplet1 = (MAPPLET)mappleList.get(k);
            this.mapplet[k] = mapplet1;
            if (null == mapletMap.get(mapplet1.getNAME())) {
               folder.getFOLDERVERSIONOrCONFIGOrSCHEDULEROrTASKOrSESSIONOrWORKLETOrWORKFLOWOrSOURCEOrTARGETOrTRANSFORMATIONOrMAPPLETOrMAPPINGOrSHORTCUTOrEXPRMACRO().add(mapplet1);
               mapletMap.put(mapplet1.getNAME(), "");
            }
         }
      }

      folder.getFOLDERVERSIONOrCONFIGOrSCHEDULEROrTASKOrSESSIONOrWORKLETOrWORKFLOWOrSOURCEOrTARGETOrTRANSFORMATIONOrMAPPLETOrMAPPINGOrSHORTCUTOrEXPRMACRO().add(this.getMAPPINGXml(tableInfoList));
      folder.getFOLDERVERSIONOrCONFIGOrSCHEDULEROrTASKOrSESSIONOrWORKLETOrWORKFLOWOrSOURCEOrTARGETOrTRANSFORMATIONOrMAPPLETOrMAPPINGOrSHORTCUTOrEXPRMACRO().add(this.geCONFIGXml(tableInfoList));
      folder.getFOLDERVERSIONOrCONFIGOrSCHEDULEROrTASKOrSESSIONOrWORKLETOrWORKFLOWOrSOURCEOrTARGETOrTRANSFORMATIONOrMAPPLETOrMAPPINGOrSHORTCUTOrEXPRMACRO().add(this.getWORKFLOW(tableInfoList));
      return folder;
   }

   public SOURCE getSourceXml(String dbtype, String dbname, String sourcename, String ownername, List<String> keytype, List<String> nameList, List<String> typeList, List<String> lengthList, List<String> scalelist, List<String> precisionlist) throws Exception {
      SOURCE sourceBean = new SOURCE();
      sourceBean.setBUSINESSNAME("");
      sourceBean.setDATABASETYPE(dbtype);
      sourceBean.setDBDNAME(dbname);
      sourceBean.setDESCRIPTION("");
      sourceBean.setNAME(sourcename);
      sourceBean.setOBJECTVERSION("1");
      sourceBean.setOWNERNAME(ownername);
      sourceBean.setVERSIONNUMBER("1");

      for(SOURCEFIELD sourcefield : this.getConvertTableInfoToSOURCEFIELD(keytype, nameList, typeList, lengthList, scalelist, precisionlist)) {
         sourceBean.getSOURCEFIELD().add(sourcefield);
      }

      return sourceBean;
   }

   public List<SOURCEFIELD> getConvertTableInfoToSOURCEFIELD(List<String> keytype, List<String> nameList, List<String> typeList, List<String> lengthList, List<String> scalelist, List<String> precisionlist) {
      String tmpFieldName = "";
      List sourceFieldList = new ArrayList();
      int phyOffset = 0;
      int prePhyOffset = 0;
      int offset = 0;
      int preOffset = 0;
      String[] sourceFieldInfoStr = null;

      for(int i = 0; i < nameList.size(); ++i) {
         SOURCEFIELD sourceField = new SOURCEFIELD();
         sourceField.setBUSINESSNAME("");
         sourceField.setDATATYPE((String)typeList.get(i));
         sourceField.setDESCRIPTION("");
         sourceField.setFIELDNUMBER(i + 1 + "");
         sourceField.setFIELDPROPERTY("0");
         sourceField.setFIELDTYPE("ELEMITEM");
         sourceField.setHIDDEN("NO");
         sourceField.setKEYTYPE((String)keytype.get(i));
         sourceField.setLENGTH((String)lengthList.get(i));
         sourceField.setLEVEL("0");
         sourceField.setNAME((String)nameList.get(i));
         if ("PRIMARY KEY".equals(keytype.get(i))) {
            sourceField.setNULLABLE("NOTNULL");
         } else {
            sourceField.setNULLABLE("NULL");
         }

         sourceField.setOCCURS("0");
         offset += preOffset;
         sourceField.setOFFSET(offset + "");
         sourceField.setPHYSICALLENGTH((String)lengthList.get(i));
         phyOffset += prePhyOffset;
         sourceField.setPHYSICALOFFSET(phyOffset + "");
         sourceField.setPICTURETEXT("");
         sourceField.setPRECISION((String)precisionlist.get(i));
         sourceField.setSCALE((String)scalelist.get(i));
         sourceField.setUSAGEFLAGS("");
         sourceFieldList.add(sourceField);
      }

      return sourceFieldList;
   }

   public TARGET getTARGETXml(String dbtype, String targetname, List<String> keytype, List<String> nameList, List<String> typeList, List<String> lengthList, List<String> scalelist, List<String> precisionlist) throws Exception {
      TARGET target = new TARGET();
      target.setBUSINESSNAME("");
      target.setCONSTRAINT("");
      target.setDATABASETYPE(dbtype);
      target.setDESCRIPTION("");
      target.setNAME(targetname);
      target.setOBJECTVERSION("1");
      target.setTABLEOPTIONS("");
      target.setVERSIONNUMBER("1");

      for(TARGETFIELD targetfield : this.getConvertTableInfoToTARGETFIELD(keytype, nameList, typeList, lengthList, scalelist, precisionlist)) {
         target.getTARGETFIELD().add(targetfield);
      }

      return target;
   }

   public List<TARGETFIELD> getConvertTableInfoToTARGETFIELD(List<String> keytype, List<String> nameList, List<String> typeList, List<String> lengthList, List<String> scalelist, List<String> precisionlist) {
      List targetFieldList = new ArrayList();
      String[] targetFieldInfoStr = null;

      for(int i = 0; i < nameList.size(); ++i) {
         TARGETFIELD targetfield = new TARGETFIELD();
         targetfield.setBUSINESSNAME("");
         targetfield.setDATATYPE((String)typeList.get(i));
         targetfield.setDESCRIPTION("");
         targetfield.setFIELDNUMBER("" + (i + 1));
         targetfield.setKEYTYPE((String)keytype.get(i));
         targetfield.setNAME((String)nameList.get(i));
         if ("PRIMARY KEY".equals(keytype.get(i))) {
            targetfield.setNULLABLE("NOTNULL");
         } else {
            targetfield.setNULLABLE("NULL");
         }

         targetfield.setPICTURETEXT("");
         targetfield.setPRECISION((String)precisionlist.get(i));
         targetfield.setSCALE((String)scalelist.get(i));
         targetFieldList.add(targetfield);
      }

      return targetFieldList;
   }

   public List<MAPPLET> getMappletInfoXml(String mappletInfo) throws Exception {
      List<MAPPLET> mappletList = new ArrayList();
      if (mappletInfo.equals("")) {
         return null;
      } else {
         for(int i = 0; i < this.mappletName.length; ++i) {
         }

         return mappletList;
      }
   }

   public MAPPING getMAPPINGXml(List<Map> tableInfoList) throws Exception {
      MAPPING mapping = new MAPPING();
      mapping.setDESCRIPTION("");
      mapping.setISVALID("YES");
      mapping.setNAME(this.mUbdpDeliverInfo);
      mapping.setOBJECTVERSION("1");
      mapping.setVERSIONNUMBER("1");
      mapping.getTRANSFORMATION().add(this.getTRANSFORMATIONXml(tableInfoList));

      for(INSTANCE instance : this.getConvertTableInfoToINSTANCE()) {
         mapping.getINSTANCE().add(instance);
      }

      for(CONNECTOR connector : this.getConvertTableInfoToCONNECTOR(tableInfoList)) {
         mapping.getCONNECTOR().add(connector);
      }

      TARGETLOADORDER targetloadorder = new TARGETLOADORDER();
      targetloadorder.setORDER("1");
      targetloadorder.setTARGETINSTANCE(this.dwUbdpDeliverInfo);
      mapping.getTARGETLOADORDER().add(targetloadorder);
      ERPINFO erpinfo = new ERPINFO();
      mapping.getERPINFO().add(erpinfo);
      return mapping;
   }

   public TRANSFORMATION getTRANSFORMATIONXml(List<Map> tableInfoList) throws Exception {
      TRANSFORMATION transformation = new TRANSFORMATION();
      transformation.setDESCRIPTION("");
      transformation.setNAME(this.sqUbdpDeliverInfo);
      transformation.setOBJECTVERSION("1");
      transformation.setREUSABLE("NO");
      transformation.setTYPE("Source Qualifier");
      transformation.setVERSIONNUMBER("1");

      for(TRANSFORMFIELD transformfield : this.getConvertTableInfoToTRANSFORMFIELD(tableInfoList)) {
         transformation.getTRANSFORMFIELD().add(transformfield);
      }

      for(TABLEATTRIBUTE tableattribute : this.getConvertTableInfoToTABLEATTRIBUTE()) {
         transformation.getTABLEATTRIBUTE().add(tableattribute);
      }

      return transformation;
   }

   public List<TRANSFORMFIELD> getConvertTableInfoToTRANSFORMFIELD(List<Map> tableInfoList) {
      List transformfieldList = new ArrayList();
      String[] dataType = new String[3];
      String tmpFieldName = "";

      for(Map tmpMap : tableInfoList) {
         TRANSFORMFIELD transformfield = new TRANSFORMFIELD();
         tmpFieldName = StringUtil.null2String(tmpMap.get("DATA_TYPE")).toUpperCase();
         transformfield.setDATATYPE(dataType[0]);
         transformfield.setDEFAULTVALUE("");
         transformfield.setDESCRIPTION("");
         transformfield.setNAME(StringUtil.null2String(tmpMap.get("COLUMN_NAME")));
         transformfield.setPICTURETEXT("");
         transformfield.setPORTTYPE("INPUT/OUTPUT");
         transformfield.setPRECISION(dataType[1]);
         transformfield.setSCALE(dataType[2]);
         transformfieldList.add(transformfield);
      }

      return transformfieldList;
   }

   public List<TABLEATTRIBUTE> getConvertTableInfoToTABLEATTRIBUTE() {
      List<TABLEATTRIBUTE> tableattributeList = new ArrayList();
      String infamation_gendata_time_cnt = StringUtil.null2String(this.sqlFilterStr);
      if (!infamation_gendata_time_cnt.equals("")) {
         infamation_gendata_time_cnt = "@" + infamation_gendata_time_cnt;
      }

      String[] tableattributeStr = new String[]{"Sql Query", "User Defined Join", "Source Filter" + infamation_gendata_time_cnt + "", "Number Of Sorted Ports@0", "Tracing Level@Normal", "Select Distinct@NO", "Is Partitionable@NO", "Pre SQL", "Post SQL", "Output is deterministic@NO", "Output is repeatable@Never"};

      for(int i = 0; i < tableattributeStr.length; ++i) {
         TABLEATTRIBUTE tableattribute = new TABLEATTRIBUTE();
         String[] tmpStr = tableattributeStr[i].split("@");
         tableattribute.setNAME(tmpStr[0]);
         if (tmpStr.length > 1) {
            tableattribute.setVALUE(tmpStr[1]);
         } else {
            tableattribute.setVALUE("");
         }

         tableattributeList.add(tableattribute);
      }

      return tableattributeList;
   }

   public List<INSTANCE> getConvertTableInfoToINSTANCE() {
      List<INSTANCE> instanceList = new ArrayList();
      INSTANCE instance = new INSTANCE();
      instance.setDESCRIPTION("");
      instance.setNAME(this.dwUbdpDeliverInfo);
      instance.setTRANSFORMATIONNAME(this.ubdpDeliverInfo);
      instance.setTRANSFORMATIONTYPE("Target Definition");
      instance.setTYPE("TARGET");
      instanceList.add(instance);
      INSTANCE instance2 = new INSTANCE();
      instance2.setDBDNAME(this.dbdName);
      instance2.setDESCRIPTION("");
      instance2.setNAME(this.ubdpDeliverInfo);
      instance2.setTRANSFORMATIONNAME(this.ubdpDeliverInfo);
      instance2.setTRANSFORMATIONTYPE("Source Definition");
      instance2.setTYPE("SOURCE");
      instanceList.add(instance2);
      Map instanceMap = new HashMap();
      int orderNum = 0;
      String instanceName = "";
      if (null != this.mapplet && this.mapplet.length > 0) {
         INSTANCE[] instance3 = new INSTANCE[this.mapplet.length];

         for(int i = 0; i < this.mapplet.length; ++i) {
            if (null == instanceMap.get(this.mapplet[i].getNAME())) {
               orderNum = 0;
               instanceName = this.mapplet[i].getNAME();
               instanceMap.put(this.mapplet[i].getNAME(), orderNum);
            } else {
               orderNum = Integer.parseInt(StringUtil.null2Zero(instanceMap.get(this.mapplet[i].getNAME()))) + 1;
               instanceMap.put(this.mapplet[i].getNAME(), orderNum);
               instanceName = this.mapplet[i].getNAME() + orderNum;
            }

            instance3[i] = new INSTANCE();
            instance3[i].setDESCRIPTION("");
            instance3[i].setNAME(instanceName);
            instance3[i].setREUSABLE("YES");
            instance3[i].setTRANSFORMATIONNAME(this.mapplet[i].getNAME());
            instance3[i].setTRANSFORMATIONTYPE("Mapplet");
            instance3[i].setTYPE("MAPPLET");
            instanceList.add(instance3[i]);
         }
      }

      INSTANCE instance4 = new INSTANCE();
      instance4.setDESCRIPTION("");
      instance4.setNAME(this.sqUbdpDeliverInfo);
      instance4.setREUSABLE("NO");
      instance4.setTRANSFORMATIONNAME(this.sqUbdpDeliverInfo);
      instance4.setTRANSFORMATIONTYPE("Source Qualifier");
      instance4.setTYPE("TRANSFORMATION");
      ASSOCIATEDSOURCEINSTANCE associatedsourceinstance = new ASSOCIATEDSOURCEINSTANCE();
      associatedsourceinstance.setNAME(this.ubdpDeliverInfo);
      instance4.getASSOCIATEDSOURCEINSTANCE().add(associatedsourceinstance);
      instanceList.add(instance4);
      return instanceList;
   }

   public List<CONNECTOR> getConvertTableInfoToCONNECTOR(List<Map> tableInfoList) throws Exception {
      List mappingConnectorlist = new ArrayList();
      Map maplitColmnMap = new HashMap();
      Map connectorMap = new HashMap();
      int orderNum = 0;
      String connectorName = "";
      if (null != this.mapplet && this.mapplet.length > 0) {
         for(int i = 0; i < this.mapplet.length; ++i) {
            if (null == connectorMap.get(this.mapplet[i].getNAME())) {
               orderNum = 0;
               connectorName = this.mapplet[i].getNAME();
               connectorMap.put(this.mapplet[i].getNAME(), orderNum);
            } else {
               orderNum = Integer.parseInt(StringUtil.null2Zero(connectorMap.get(this.mapplet[i].getNAME()))) + 1;
               connectorMap.put(this.mapplet[i].getNAME(), orderNum);
               connectorName = this.mapplet[i].getNAME() + orderNum;
            }

            CONNECTOR connectOr = new CONNECTOR();
            connectOr.setFROMINSTANCE(connectorName);
            connectOr.setFROMINSTANCETYPE("Mapplet");
            connectOr.setTOFIELD(this.columnName[i]);
            maplitColmnMap.put(this.columnName[i], "");
            connectOr.setTOINSTANCE(this.dwUbdpDeliverInfo);
            connectOr.setTOINSTANCETYPE("Target Definition");
            mappingConnectorlist.add(connectOr);
         }
      }

      for(int i = 0; i < tableInfoList.size(); ++i) {
         Map tmpMap = (Map)tableInfoList.get(i);
         if (null == maplitColmnMap.get(StringUtil.null2String(tmpMap.get("COLUMN_NAME")))) {
            CONNECTOR connectOr = new CONNECTOR();
            connectOr.setFROMFIELD(StringUtil.null2String(tmpMap.get("COLUMN_NAME")));
            connectOr.setFROMINSTANCE(this.sqUbdpDeliverInfo);
            connectOr.setFROMINSTANCETYPE("Source Qualifier");
            connectOr.setTOFIELD(StringUtil.null2String(tmpMap.get("COLUMN_NAME")));
            connectOr.setTOINSTANCE(this.dwUbdpDeliverInfo);
            connectOr.setTOINSTANCETYPE("Target Definition");
            mappingConnectorlist.add(connectOr);
         }
      }

      for(int i = 0; i < tableInfoList.size(); ++i) {
         Map tmpMap = (Map)tableInfoList.get(i);
         CONNECTOR connectOr = new CONNECTOR();
         connectOr.setFROMFIELD(StringUtil.null2String(tmpMap.get("COLUMN_NAME")));
         connectOr.setFROMINSTANCE(this.ubdpDeliverInfo);
         connectOr.setFROMINSTANCETYPE("Source Definition");
         connectOr.setTOFIELD(StringUtil.null2String(tmpMap.get("COLUMN_NAME")));
         connectOr.setTOINSTANCE(this.sqUbdpDeliverInfo);
         connectOr.setTOINSTANCETYPE("Source Qualifier");
         mappingConnectorlist.add(connectOr);
      }

      Map sourceConnectorMap = new HashMap();
      orderNum = 0;
      String sourceconnectorName = "";
      if (null != this.mapplet && this.mapplet.length > 0) {
         for(int i = 0; i < this.mapplet.length; ++i) {
            if (null == sourceConnectorMap.get(this.mapplet[i].getNAME())) {
               orderNum = 0;
               sourceconnectorName = this.mapplet[i].getNAME();
               sourceConnectorMap.put(this.mapplet[i].getNAME(), orderNum);
            } else {
               orderNum = Integer.parseInt(StringUtil.null2Zero(sourceConnectorMap.get(this.mapplet[i].getNAME()))) + 1;
               sourceConnectorMap.put(this.mapplet[i].getNAME(), orderNum);
               sourceconnectorName = this.mapplet[i].getNAME() + orderNum;
            }

            CONNECTOR connectOr = new CONNECTOR();
            connectOr.setFROMFIELD(this.columnName[i]);
            connectOr.setFROMINSTANCE(this.sqUbdpDeliverInfo);
            connectOr.setFROMINSTANCETYPE("Source Qualifier");
            connectOr.setTOINSTANCE(sourceconnectorName);
            connectOr.setTOINSTANCETYPE("Mapplet");
            mappingConnectorlist.add(connectOr);
         }
      }

      return mappingConnectorlist;
   }

   public CONFIG geCONFIGXml(List<Map> tableInfoList) throws Exception {
      CONFIG config = new CONFIG();
      config.setDESCRIPTION("Default session configuration object");
      config.setISDEFAULT("YES");
      config.setNAME("default_session_config");
      config.setVERSIONNUMBER("1");

      for(ATTRIBUTE attribute : this.geCONFIGATTRIBUTEXml(tableInfoList)) {
         config.getATTRIBUTE().add(attribute);
      }

      return config;
   }

   public List<ATTRIBUTE> geCONFIGATTRIBUTEXml(List<Map> tableInfoList) throws Exception {
      List<ATTRIBUTE> attributeList = new ArrayList();
      String[] tmpStr = null;
      String[] attributeInfo = new String[]{"Advanced_", "Constraint based load ordering_NO", "Cache LOOKUP() function_YES", "Default buffer block size_Auto", "Line Sequential buffer length_1024", "Maximum Memory Allowed For Auto Memory Attributes_512MB", "Maximum Percentage of Total Memory Allowed For Auto Memory Attributes_5", "Additional Concurrent Pipelines for Lookup Cache Creation_Auto", "Custom Properties_", "Pre-build lookup cache_Auto", "Optimization Level_Medium", "DateTime Format String_MM/DD/YYYY HH24:MI:SS.US", "Pre 85 Timestamp Compatibility_NO", "Log Options_0", "Save session log by_Session runs", "Save session log for these runs_0", "Session Log File Max Size_0", "Session Log File Max Time Period_0", "Maximum Partial Session Log Files_1", "Writer Commit Statistics Log Frequency_1", "Writer Commit Statistics Log Interval_0", "Error handling_", "Stop on errors_0", "Override tracing_None", "On Stored Procedure error_Stop", "On Pre-session command task error_Stop", "On Pre-Post SQL error_Stop", "Enable Recovery_NO", "Error Log Type_None", "Error Log Table Name Prefix_", "Error Log File Name_PMError.log", "Log Source Row Data_NO", "Data Column Delimiter_|", "Partitioning Options_", "Dynamic Partitioning_Disabled", "Number of Partitions_1", "Multiplication Factor_Auto", "Session on Grid_", "Is Enabled_NO"};

      for(int i = 0; i < attributeInfo.length; ++i) {
         ATTRIBUTE attribute = new ATTRIBUTE();
         tmpStr = attributeInfo[i].split("_");
         attribute.setNAME(tmpStr[0]);
         if (tmpStr.length > 1) {
            attribute.setVALUE(tmpStr[1]);
         } else {
            attribute.setVALUE("");
         }

         attributeList.add(attribute);
      }

      return attributeList;
   }

   public WORKFLOW getWORKFLOW(List<Map> tableInfoList) throws Exception {
      WORKFLOW workflow = new WORKFLOW();
      workflow.setDESCRIPTION("");
      workflow.setISENABLED("YES");
      workflow.setISRUNNABLESERVICE("NO");
      workflow.setISSERVICE("NO");
      workflow.setISVALID("YES");
      workflow.setNAME(this.workFlowInfo);
      workflow.setREUSABLESCHEDULER("NO");
      workflow.setSCHEDULERNAME("Scheduler");
      workflow.setSUSPENDONERROR("NO");
      workflow.setTASKSMUSTRUNONSERVER("NO");
      workflow.setVERSIONNUMBER("1");
      workflow.setSCHEDULER(this.getSCHEDULER(tableInfoList));
      workflow.getTASK().add(this.getTASK(tableInfoList));
      workflow.getSESSION().add(this.getSESSION(tableInfoList));

      for(TASKINSTANCE taskinstance : this.getTASKINSTANCE()) {
         workflow.getTASKINSTANCE().add(taskinstance);
      }

      WORKFLOWLINK workflowlink = new WORKFLOWLINK();
      workflowlink.setCONDITION("");
      workflowlink.setFROMTASK("Start");
      workflowlink.setTOTASK(this.smUbdpDeliverInfo);
      workflow.getWORKFLOWLINK().add(workflowlink);

      for(WORKFLOWVARIABLE workflowvariable : this.getWORKFLOWVARIABLE()) {
         workflow.getWORKFLOWVARIABLE().add(workflowvariable);
      }

      for(ATTRIBUTE attribute : this.getATTRIBUTE()) {
         workflow.getATTRIBUTE().add(attribute);
      }

      return workflow;
   }

   public SCHEDULER getSCHEDULER(List<Map> tableInfoList) {
      SCHEDULER scheduler = new SCHEDULER();
      scheduler.setDESCRIPTION("");
      scheduler.setNAME("Scheduler");
      scheduler.setREUSABLE("NO");
      scheduler.setVERSIONNUMBER("1");
      SCHEDULEINFO scheduleinfo = new SCHEDULEINFO();
      scheduleinfo.setSCHEDULETYPE("ONDEMAND");
      scheduler.setSCHEDULEINFO(scheduleinfo);
      return scheduler;
   }

   public TASK getTASK(List<Map> tableInfoList) {
      TASK task = new TASK();
      task.setDESCRIPTION("");
      task.setNAME("Start");
      task.setREUSABLE("NO");
      task.setTYPE("Start");
      task.setVERSIONNUMBER("1");
      return task;
   }

   public SESSION getSESSION(List<Map> tableInfoList) throws Exception {
      SESSION session = new SESSION();
      session.setDESCRIPTION("");
      session.setISVALID("YES");
      session.setMAPPINGNAME(this.mUbdpDeliverInfo);
      session.setNAME(this.smUbdpDeliverInfo);
      session.setREUSABLE("NO");
      session.setSORTORDER("Binary");
      session.setVERSIONNUMBER("1");

      for(SESSTRANSFORMATIONINST sesstransformationinst : this.getSESSTRANSFORMATIONINST(tableInfoList)) {
         session.getSESSTRANSFORMATIONINST().add(sesstransformationinst);
      }

      CONFIGREFERENCE configreference = new CONFIGREFERENCE();
      configreference.setREFOBJECTNAME("default_session_config");
      configreference.setTYPE("Session config");
      session.setCONFIGREFERENCE(configreference);

      for(SESSIONEXTENSION sessionextension : this.getSESSIONEXTENSIONList(tableInfoList)) {
         session.getSESSIONEXTENSION().add(sessionextension);
      }

      for(ATTRIBUTE attribute : this.getATTRIBUTEInfo()) {
         session.getATTRIBUTE().add(attribute);
      }

      return session;
   }

   public List<SESSTRANSFORMATIONINST> getSESSTRANSFORMATIONINST(List<Map> tableInfoList) throws Exception {
      List<SESSTRANSFORMATIONINST> sesstransformationinstList = new ArrayList();
      SESSTRANSFORMATIONINST sesstransformationinst = new SESSTRANSFORMATIONINST();
      sesstransformationinst.setISREPARTITIONPOINT("YES");
      sesstransformationinst.setPARTITIONTYPE("PASS THROUGH");
      sesstransformationinst.setPIPELINE("1");
      sesstransformationinst.setSTAGE("1");
      sesstransformationinst.setSINSTANCENAME(this.dwUbdpDeliverInfo);
      sesstransformationinst.setTRANSFORMATIONNAME(this.dwUbdpDeliverInfo);
      sesstransformationinst.setTRANSFORMATIONTYPE("Target Definition");
      ATTRIBUTE attribute = new ATTRIBUTE();
      attribute.setNAME("Table Name Prefix");
      attribute.setVALUE(this.tUserName);
      sesstransformationinst.getATTRIBUTE().add(attribute);
      sesstransformationinstList.add(sesstransformationinst);
      SESSTRANSFORMATIONINST sesstransformationinst1 = new SESSTRANSFORMATIONINST();
      sesstransformationinst1.setISREPARTITIONPOINT("NO");
      sesstransformationinst1.setPIPELINE("0");
      sesstransformationinst1.setSINSTANCENAME(this.ubdpDeliverInfo);
      sesstransformationinst1.setSTAGE("0");
      sesstransformationinst1.setTRANSFORMATIONNAME(this.ubdpDeliverInfo);
      sesstransformationinst1.setTRANSFORMATIONTYPE("Source Definition");
      ATTRIBUTE attribute1 = new ATTRIBUTE();
      attribute1.setNAME("Owner Name");
      attribute1.setVALUE(this.sUserName);
      sesstransformationinst1.getATTRIBUTE().add(attribute1);
      sesstransformationinstList.add(sesstransformationinst1);
      SESSTRANSFORMATIONINST sesstransformationinst2 = new SESSTRANSFORMATIONINST();
      sesstransformationinst2.setISREPARTITIONPOINT("YES");
      sesstransformationinst2.setPARTITIONTYPE("PASS THROUGH");
      sesstransformationinst2.setPIPELINE("1");
      sesstransformationinst2.setSINSTANCENAME(this.sqUbdpDeliverInfo);
      sesstransformationinst2.setSTAGE("2");
      sesstransformationinst2.setTRANSFORMATIONNAME(this.sqUbdpDeliverInfo);
      sesstransformationinst2.setTRANSFORMATIONTYPE("Source Qualifier");
      sesstransformationinstList.add(sesstransformationinst2);
      new HashMap();
      if (null != this.mappletName) {
      }

      return sesstransformationinstList;
   }

   public List<SESSIONEXTENSION> getSESSIONEXTENSIONList(List<Map> tableInfoList) throws Exception {
      List<SESSIONEXTENSION> sessionextensionList = new ArrayList();
      SESSIONEXTENSION sessionextension = new SESSIONEXTENSION();
      sessionextension.setNAME("Relational Writer");
      sessionextension.setSINSTANCENAME(this.dwUbdpDeliverInfo);
      sessionextension.setSUBTYPE("Relational Writer");
      sessionextension.setTRANSFORMATIONTYPE("Target Definition");
      sessionextension.setTYPE("WRITER");
      CONNECTIONREFERENCE connectionreference = new CONNECTIONREFERENCE();
      connectionreference.setCNXREFNAME("DB Connection");
      connectionreference.setCONNECTIONNAME(this.targetDbConnectionlinkName);
      connectionreference.setCONNECTIONNUMBER("1");
      connectionreference.setCONNECTIONSUBTYPE("Oracle");
      connectionreference.setCONNECTIONTYPE("Relational");
      connectionreference.setVARIABLE("");
      sessionextension.getCONNECTIONREFERENCE().add(connectionreference);
      String[] attributeStr = new String[]{"Target load type@Normal", "Insert@YES", "Update as Update@YES", "Update as Insert@NO", "Update else Insert@NO", "Delete@YES", "Truncate target table option@YES", "Reject file directory@$PMBadFileDir&#x5c;", "Reject filename@" + this.dwUbdpDeliverInfo + "1.bad"};
      String[] tmpAttr = null;
      ATTRIBUTE[] attribute = new ATTRIBUTE[attributeStr.length];

      for(int i = 0; i < attributeStr.length; ++i) {
         tmpAttr = attributeStr[i].split("@");
         attribute[i] = new ATTRIBUTE();
         attribute[i].setNAME(tmpAttr[0]);
         if (tmpAttr.length > 1) {
            attribute[i].setVALUE(tmpAttr[1]);
         } else {
            attribute[i].setVALUE("");
         }

         sessionextension.getATTRIBUTE().add(attribute[i]);
      }

      sessionextensionList.add(sessionextension);
      SESSIONEXTENSION sessionextension3 = new SESSIONEXTENSION();
      sessionextension3.setDSQINSTNAME(this.sqUbdpDeliverInfo);
      sessionextension3.setDSQINSTTYPE("Source Qualifier");
      sessionextension3.setNAME("Relational Reader");
      sessionextension3.setSINSTANCENAME(this.ubdpDeliverInfo);
      sessionextension3.setSUBTYPE("Relational Reader");
      sessionextension3.setTRANSFORMATIONTYPE("Source Definition");
      sessionextension3.setTYPE("READER");
      sessionextensionList.add(sessionextension3);
      SESSIONEXTENSION sessionextension1 = new SESSIONEXTENSION();
      sessionextension1.setNAME("Relational Reader");
      sessionextension1.setSINSTANCENAME(this.sqUbdpDeliverInfo);
      sessionextension1.setSUBTYPE("Relational Reader");
      sessionextension1.setTRANSFORMATIONTYPE("Source Qualifier");
      sessionextension1.setTYPE("READER");
      CONNECTIONREFERENCE connectionreference1 = new CONNECTIONREFERENCE();
      connectionreference1.setCNXREFNAME("DB Connection");
      connectionreference1.setCONNECTIONNAME(this.sourceDbConnectionNamelinkName);
      connectionreference1.setCONNECTIONNUMBER("1");
      connectionreference1.setCONNECTIONSUBTYPE("Oracle");
      connectionreference1.setCONNECTIONTYPE("Relational");
      connectionreference1.setVARIABLE("");
      sessionextension1.getCONNECTIONREFERENCE().add(connectionreference1);
      sessionextensionList.add(sessionextension1);
      new HashMap();
      if (null != this.mappletName) {
         for(int i = 0; i < this.mappletName.length; ++i) {
         }
      }

      return sessionextensionList;
   }

   public List<ATTRIBUTE> getATTRIBUTEInfo() {
      List<ATTRIBUTE> ATTRIBUTEList = new ArrayList();
      String[] attruInfo = new String[]{"General Options@", "Write Backward Compatible Session Log File@NO", "Session Log File Name@" + this.smUbdpDeliverInfo + ".log", "Session Log File directory@$PMSessionLogDir&#x5c;", "Parameter Filename@", "Enable Test Load@NO", "$Source connection value@", "$Target connection value@", "Treat source rows as@Insert", "Commit Type@Target", "Commit Interval@10000", "Commit On End Of File@YES", "Rollback Transactions on Errors@NO", "Recovery Strategy@Fail task and continue workflow", "Java Classpath@", "Performance@", "DTM buffer size@Auto", "Collect performance data@NO", "Write performance data to repository@NO", "Incremental Aggregation@NO", "Enable high precision@NO", "Session retry on deadlock@NO", "Pushdown Optimization@None", "Allow Temporary View for Pushdown@NO", "Allow Temporary Sequence for Pushdown@NO", "Allow Pushdown for User Incompatible Connections@NO"};
      String[] tmpAttr = null;
      ATTRIBUTE[] attribute1 = new ATTRIBUTE[attruInfo.length];

      for(int i = 0; i < attruInfo.length; ++i) {
         tmpAttr = attruInfo[i].split("@");
         attribute1[i] = new ATTRIBUTE();
         attribute1[i].setNAME(tmpAttr[0]);
         if (tmpAttr.length > 1) {
            attribute1[i].setVALUE(tmpAttr[1]);
         } else {
            attribute1[i].setVALUE("");
         }

         ATTRIBUTEList.add(attribute1[i]);
      }

      return ATTRIBUTEList;
   }

   public List<TASKINSTANCE> getTASKINSTANCE() {
      List<TASKINSTANCE> taskinstanceList = new ArrayList();
      TASKINSTANCE taskinstance = new TASKINSTANCE();
      taskinstance.setDESCRIPTION("");
      taskinstance.setISENABLED("YES");
      taskinstance.setNAME("Start");
      taskinstance.setREUSABLE("NO");
      taskinstance.setTASKNAME("Start");
      taskinstance.setTASKTYPE("Start");
      taskinstanceList.add(taskinstance);
      TASKINSTANCE taskinstance1 = new TASKINSTANCE();
      taskinstance1.setDESCRIPTION("");
      taskinstance1.setFAILPARENTIFINSTANCEDIDNOTRUN("NO");
      taskinstance1.setFAILPARENTIFINSTANCEFAILS("YES");
      taskinstance1.setISENABLED("YES");
      taskinstance1.setREUSABLE("NO");
      taskinstance1.setNAME(this.smUbdpDeliverInfo);
      taskinstance1.setTASKNAME(this.smUbdpDeliverInfo);
      taskinstance1.setTASKTYPE("Session");
      taskinstance1.setTREATINPUTLINKASAND("YES");
      taskinstanceList.add(taskinstance1);
      return taskinstanceList;
   }

   public List<WORKFLOWVARIABLE> getWORKFLOWVARIABLE() {
      List<WORKFLOWVARIABLE> workflowvariableList = new ArrayList();
      String[] workflowvariableStr = new String[]{"date/time@The time this task started@NO@NO@$Start.StartTime@NO", "date/time@The time this task completed@NO@NO@$Start.EndTime@NO", "integer@Status of this task&apos;s execution@NO@NO@$Start.Status@NO", "integer@Status of the previous task that is not disabled@NO@NO@$Start.PrevTaskStatus@NO", "integer@Error code for this task&apos;s execution@NO@NO@$Start.ErrorCode@NO", "string@Error message for this task&apos;s execution@NO@NO@$Start.ErrorMsg@NO", "date/time@The time this task started@NO@NO@$" + this.smUbdpDeliverInfo + ".StartTime@NO", "date/time@The time this task completed@NO@NO@$" + this.smUbdpDeliverInfo + ".EndTime@NO", "integer@Status of this task&apos;s execution@NO@NO@$" + this.smUbdpDeliverInfo + ".Status@NO", "integer@Status of the previous task that is not disabled@NO@NO@$" + this.smUbdpDeliverInfo + ".PrevTaskStatus@NO", "integer@Error code for this task&apos;s execution@NO@NO@$" + this.smUbdpDeliverInfo + ".ErrorCode@NO", "string@Error message for this task&apos;s execution@NO@NO@$" + this.smUbdpDeliverInfo + ".ErrorMsg@NO", "integer@Rows successfully read@NO@NO@$" + this.smUbdpDeliverInfo + ".SrcSuccessRows@NO", "integer@Rows failed to read@NO@NO@$" + this.smUbdpDeliverInfo + ".SrcFailedRows@NO", "integer@Rows successfully loaded@NO@NO@$" + this.smUbdpDeliverInfo + ".TgtSuccessRows@NO", "integer@Rows failed to load@NO@NO@$" + this.smUbdpDeliverInfo + ".TgtFailedRows@NO", "integer@Total number of transformation errors@NO@NO@$" + this.smUbdpDeliverInfo + ".TotalTransErrors@NO", "integer@First error code@NO@NO@$" + this.smUbdpDeliverInfo + ".FirstErrorCode@NO", "string@First error message@NO@NO@$" + this.smUbdpDeliverInfo + ".FirstErrorMsg@NO"};
      String[] splitArry = null;
      WORKFLOWVARIABLE[] workflowvariable = new WORKFLOWVARIABLE[workflowvariableStr.length];

      for(int i = 0; i < workflowvariableStr.length; ++i) {
         workflowvariable[i] = new WORKFLOWVARIABLE();
         splitArry = workflowvariableStr[i].split("@");
         workflowvariable[i].setDATATYPE(splitArry[0]);
         workflowvariable[i].setDEFAULTVALUE("");
         workflowvariable[i].setDESCRIPTION(splitArry[1]);
         workflowvariable[i].setISNULL(splitArry[2]);
         workflowvariable[i].setISPERSISTENT(splitArry[3]);
         workflowvariable[i].setNAME(splitArry[4]);
         workflowvariable[i].setUSERDEFINED(splitArry[5]);
         workflowvariableList.add(workflowvariable[i]);
      }

      return workflowvariableList;
   }

   public List<ATTRIBUTE> getATTRIBUTE() {
      List<ATTRIBUTE> attributeList = new ArrayList();
      String[] attributeStr = new String[]{"Parameter Filename@", "Write Backward Compatible Workflow Log File@NO", "Workflow Log File Name@" + this.wfDwUbdpDeliverInfo + ".log", "Workflow Log File Directory@$PMWorkflowLogDir&#x5c;", "Save Workflow log by@By runs", "Save workflow log for these runs@0", "Service Name@", "Service Timeout@0", "Is Service Visible@NO", "Is Service Protected@NO", "Enable HA recovery@NO", "Automatically recover terminated tasks@NO", "Service Level Name@Default", "Allow concurrent run with unique run instance name@NO", "Allow concurrent run with same run instance name@NO", "Maximum number of concurrent runs@0", "Assigned Web Services Hubs@", "Maximum number of concurrent runs per Hub@1000", "Expected Service Time@1"};
      String[] splitArry = null;
      ATTRIBUTE[] attribute = new ATTRIBUTE[attributeStr.length];

      for(int i = 0; i < attributeStr.length; ++i) {
         attribute[i] = new ATTRIBUTE();
         splitArry = attributeStr[i].split("@");
         attribute[i].setNAME(splitArry[0]);
         if (splitArry.length > 1) {
            attribute[i].setVALUE(splitArry[1]);
         } else {
            attribute[i].setVALUE("");
         }

         attributeList.add(attribute[i]);
      }

      return attributeList;
   }
}
