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

import com.chenyang.nse.bussiness.engine.infa.InfoProperty;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.ATTRIBUTE;
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.FLATFILE;
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.TASK;
import com.chenyang.nse.bussiness.engine.infa.basic.xmlbean.TASKINSTANCE;
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.pubbean.MappletMakeDatabean;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubbean.SourceBean;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubbean.TargetBean;
import com.chenyang.nse.bussiness.engine.infa.powercenter961.pubbean.WorkflowBean;
import java.util.ArrayList;
import java.util.List;

public class WorkflowUtil {
   public WORKFLOW getWorkflow(SourceBean sb, TargetBean tb_file, TargetBean tb_dbase, WorkflowBean work_bean, InfoProperty tengine) throws Exception {
      WORKFLOW workflow = new WORKFLOW();
      workflow.setDESCRIPTION("");
      workflow.setISENABLED("YES");
      workflow.setISRUNNABLESERVICE("NO");
      workflow.setISSERVICE("NO");
      workflow.setISVALID("YES");
      workflow.setNAME(work_bean.getWorkflow_name());
      workflow.setREUSABLESCHEDULER("NO");
      workflow.setSCHEDULERNAME("Scheduler");
      workflow.setSERVERNAME(tengine.getInteservicename());
      workflow.setSERVERDOMAINNAME(tengine.getDomainname());
      workflow.setSUSPENDONERROR("NO");
      workflow.setTASKSMUSTRUNONSERVER("NO");
      workflow.setVERSIONNUMBER("1");
      workflow.setSCHEDULER(this.getSCHEDULER());
      workflow.getTASK().add(this.getTASK());
      workflow.getSESSION().add(this.getSESSION(sb, tb_file, tb_dbase, work_bean.getMapping_name(), work_bean.getWorkflow_name(), work_bean.getSourcedbname(), work_bean.getTargetdbname(), work_bean.getSqname(), work_bean.getMappletbean(), work_bean.getTar_linkname(), work_bean.getSou_linkname(), work_bean.getParampath(), work_bean.getSourceownername(), work_bean.getTargetownername(), work_bean.getSource_dbtype(), work_bean.getTarget_dbtype()));

      for(TASKINSTANCE taskinstance : this.getTASKINSTANCE("s_M_" + work_bean.getMapping_name())) {
         workflow.getTASKINSTANCE().add(taskinstance);
      }

      WORKFLOWLINK workflowlink = new WORKFLOWLINK();
      workflowlink.setCONDITION("");
      workflowlink.setFROMTASK("Start");
      workflowlink.setTOTASK("s_M_" + work_bean.getMapping_name());
      workflow.getWORKFLOWLINK().add(workflowlink);

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

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

      return workflow;
   }

   public SCHEDULER getSCHEDULER() {
      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() {
      TASK task = new TASK();
      task.setDESCRIPTION("");
      task.setNAME("Start");
      task.setREUSABLE("NO");
      task.setTYPE("Start");
      task.setVERSIONNUMBER("1");
      return task;
   }

   public List<TASKINSTANCE> getTASKINSTANCE(String sessionname) {
      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(sessionname);
      taskinstance1.setTASKNAME(sessionname);
      taskinstance1.setTASKTYPE("Session");
      taskinstance1.setTREATINPUTLINKASAND("YES");
      taskinstanceList.add(taskinstance1);
      return taskinstanceList;
   }

   public List<WORKFLOWVARIABLE> getWORKFLOWVARIABLE(String mappingName) {
      List<WORKFLOWVARIABLE> workflowvariableList = new ArrayList();
      String name = "s_M_" + mappingName;
      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@$" + name + ".StartTime@NO", "date/time@The time this task completed@NO@NO@$" + name + ".EndTime@NO", "integer@Status of this task&apos;s execution@NO@NO@$" + name + ".Status@NO", "integer@Status of the previous task that is not disabled@NO@NO@$" + name + ".PrevTaskStatus@NO", "integer@Error code for this task&apos;s execution@NO@NO@$" + name + ".ErrorCode@NO", "string@Error message for this task&apos;s execution@NO@NO@$" + name + ".ErrorMsg@NO", "integer@Rows successfully read@NO@NO@$" + name + ".SrcSuccessRows@NO", "integer@Rows failed to read@NO@NO@$" + name + ".SrcFailedRows@NO", "integer@Rows successfully loaded@NO@NO@$" + name + ".TgtSuccessRows@NO", "integer@Rows failed to load@NO@NO@$" + name + ".TgtFailedRows@NO", "integer@Total number of transformation errors@NO@NO@$" + name + ".TotalTransErrors@NO", "integer@First error code@NO@NO@$" + name + ".FirstErrorCode@NO", "string@First error message@NO@NO@$" + name + ".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].setUSERDEFINED(splitArry[5]);
         workflowvariable[i].setNAME(splitArry[4]);
         workflowvariable[i].setISPERSISTENT(splitArry[3]);
         workflowvariable[i].setISNULL(splitArry[2]);
         workflowvariable[i].setDESCRIPTION(splitArry[1]);
         workflowvariable[i].setDEFAULTVALUE("");
         workflowvariable[i].setDATATYPE(splitArry[0]);
         workflowvariableList.add(workflowvariable[i]);
      }

      return workflowvariableList;
   }

   public List<ATTRIBUTE> getATTRIBUTE(String workflowname) {
      List<ATTRIBUTE> attributeList = new ArrayList();
      String[] attributeStr = new String[]{"Parameter Filename@", "Write Backward Compatible Workflow Log File@NO", "Workflow Log File Name@" + workflowname + ".log", "Workflow Log File Directory@$PMWorkflowLogDir\\", "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@YES", "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("@");
         if (splitArry.length > 1) {
            attribute[i].setVALUE(splitArry[1]);
         } else {
            attribute[i].setVALUE("");
         }

         attribute[i].setNAME(splitArry[0]);
         attributeList.add(attribute[i]);
      }

      return attributeList;
   }

   public SESSION getSESSION(SourceBean sb, TargetBean tb_file, TargetBean tb_dbase, String mappingName, String workflowname, String sourceDbname, String tragetDbname, String sqname, List<MappletMakeDatabean> mapplet, String co_target, String sourcedatabasename, String paramFilepath, String source_ownername, String target_ownername, String source_dbtype, String target_dbtype) throws Exception {
      SESSION session = new SESSION();
      session.setDESCRIPTION("");
      session.setISVALID("YES");
      session.setMAPPINGNAME(mappingName);
      session.setNAME("s_M_" + mappingName);
      session.setREUSABLE("NO");
      session.setSORTORDER("Binary");
      session.setVERSIONNUMBER("1");

      for(SESSTRANSFORMATIONINST sesstransformationinst : this.getSESSTRANSFORMATIONINST(sb, tb_file, mappingName, sourceDbname, tragetDbname, sqname, mapplet, source_ownername, target_ownername, source_dbtype, target_dbtype)) {
         session.getSESSTRANSFORMATIONINST().add(sesstransformationinst);
      }

      for(SESSTRANSFORMATIONINST sesstransformationinst : this.getSESSTRANSFORMATIONINST(sb, tb_dbase, mappingName, sourceDbname, tb_dbase.getDbdname(), sqname, mapplet, source_ownername, tb_dbase.getTargetownername(), source_dbtype, tb_dbase.getDatabasetype())) {
         session.getSESSTRANSFORMATIONINST().add(sesstransformationinst);
      }

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

      for(SESSIONEXTENSION sessionextension : this.getSESSIONEXTENSION(sb, tb_file, sourceDbname, tragetDbname, sqname, co_target, sourcedatabasename, source_dbtype, target_dbtype, mapplet)) {
         session.getSESSIONEXTENSION().add(sessionextension);
      }

      for(SESSIONEXTENSION sessionextension : this.getSESSIONEXTENSION(sb, tb_dbase, sourceDbname, tb_dbase.getDbdname(), sqname, tb_dbase.getLinkname(), sourcedatabasename, source_dbtype, tb_dbase.getDatabasetype(), mapplet)) {
         session.getSESSIONEXTENSION().add(sessionextension);
      }

      for(ATTRIBUTE attribute : this.getATTRIBUTEInfo(tb_file, workflowname, paramFilepath)) {
         session.getATTRIBUTE().add(attribute);
      }

      return session;
   }

   public List<SESSTRANSFORMATIONINST> getSESSTRANSFORMATIONINST(SourceBean sb, TargetBean tb, String mappingName, String sourcename, String targetname, String sqname, List<MappletMakeDatabean> mapplet, String source_ownername, String target_ownername, String sourcetype, String targettype) throws Exception {
      List<SESSTRANSFORMATIONINST> sesstransformationinstList = new ArrayList();
      SESSTRANSFORMATIONINST sesstransformationinst = new SESSTRANSFORMATIONINST();
      sesstransformationinst.setTRANSFORMATIONTYPE("Target Definition");
      sesstransformationinst.setTRANSFORMATIONNAME(tb.getTar_name());
      sesstransformationinst.setSINSTANCENAME(tb.getTar_name());
      sesstransformationinst.setSTAGE("1");
      sesstransformationinst.setPIPELINE("1");
      sesstransformationinst.setPARTITIONTYPE("PASS THROUGH");
      sesstransformationinst.setISREPARTITIONPOINT("YES");
      if ("Flat File".equals(targettype)) {
         FLATFILE flatfile = new FLATFILE();
         if ("1".equals(tb.getFileparam())) {
            flatfile.setCODEPAGE(tb.getFilebean().getCodepage());
            flatfile.setCONSECDELIMITERSASONE(tb.getFilebean().getConsecdelimitersasone());
            flatfile.setDELIMITED(tb.getFilebean().getDelimited());
            flatfile.setDELIMITERS(tb.getFilebean().getDelimiters());
            flatfile.setESCAPECHARACTER(tb.getFilebean().getEscape_character());
            flatfile.setKEEPESCAPECHAR(tb.getFilebean().getKeepescapechar());
            flatfile.setLINESEQUENTIAL("NO");
            flatfile.setMULTIDELIMITERSASAND(tb.getFilebean().getMultidelimitersasand());
            flatfile.setNULLCHARTYPE("ASCII");
            flatfile.setNULLCHARACTER("*");
            flatfile.setPADBYTES("1");
            flatfile.setQUOTECHARACTER(tb.getFilebean().getQuote_character());
            flatfile.setREPEATABLE("NO");
            flatfile.setROWDELIMITER(tb.getFilebean().getRowdelimiter());
            flatfile.setSHIFTSENSITIVEDATA("NO");
            flatfile.setSKIPROWS(tb.getFilebean().getSkiprows());
            flatfile.setSTRIPTRAILINGBLANKS("NO");
            sesstransformationinst.getFLATFILE().add(flatfile);
         } else {
            flatfile.setCODEPAGE(tb.getFilebean().getCodepage());
            flatfile.setCONSECDELIMITERSASONE("NO");
            flatfile.setDELIMITED("NO");
            flatfile.setDELIMITERS("NO");
            flatfile.setESCAPECHARACTER("");
            flatfile.setKEEPESCAPECHAR("DOUBLE");
            flatfile.setLINESEQUENTIAL(tb.getFilebean().getLinesequential());
            flatfile.setMULTIDELIMITERSASAND("NO");
            flatfile.setNULLCHARTYPE(tb.getFilebean().getNullchartype());
            flatfile.setNULLCHARACTER(tb.getFilebean().getNull_character());
            flatfile.setPADBYTES(tb.getFilebean().getPadbytes());
            flatfile.setQUOTECHARACTER("DOUBLE");
            flatfile.setREPEATABLE(tb.getFilebean().getRepeatable());
            flatfile.setROWDELIMITER("0");
            flatfile.setSHIFTSENSITIVEDATA(tb.getFilebean().getShiftsensitivedata());
            flatfile.setSKIPROWS(tb.getFilebean().getSkiprows());
            flatfile.setSTRIPTRAILINGBLANKS(tb.getFilebean().getStriptrailingblanks());
            sesstransformationinst.getFLATFILE().add(flatfile);
         }
      } else if (target_ownername != null) {
         ATTRIBUTE a1 = new ATTRIBUTE();
         a1.setNAME("Table Name Prefix");
         a1.setVALUE(target_ownername);
         sesstransformationinst.getATTRIBUTE().add(a1);
      }

      sesstransformationinstList.add(sesstransformationinst);
      if ("Flat File".equals(targettype)) {
         SESSTRANSFORMATIONINST sesstransformationinst1 = new SESSTRANSFORMATIONINST();
         sesstransformationinst1.setTRANSFORMATIONTYPE("Source Definition");
         sesstransformationinst1.setTRANSFORMATIONNAME(sourcename);
         sesstransformationinst1.setSTAGE("0");
         sesstransformationinst1.setSINSTANCENAME(sourcename);
         sesstransformationinst1.setPIPELINE("0");
         sesstransformationinst1.setISREPARTITIONPOINT("NO");
         if ("Flat File".equals(sourcetype)) {
            FLATFILE flatfile = new FLATFILE();
            if ("1".equals(sb.getFileparam())) {
               flatfile.setCODEPAGE(sb.getFilebean().getCodepage());
               flatfile.setCONSECDELIMITERSASONE(sb.getFilebean().getConsecdelimitersasone());
               flatfile.setDELIMITED(sb.getFilebean().getDelimited());
               flatfile.setDELIMITERS(sb.getFilebean().getDelimiters());
               flatfile.setESCAPECHARACTER(sb.getFilebean().getEscape_character());
               flatfile.setKEEPESCAPECHAR(sb.getFilebean().getKeepescapechar());
               flatfile.setLINESEQUENTIAL("NO");
               flatfile.setMULTIDELIMITERSASAND(sb.getFilebean().getMultidelimitersasand());
               flatfile.setNULLCHARTYPE("ASCII");
               flatfile.setNULLCHARACTER("*");
               flatfile.setPADBYTES("1");
               flatfile.setQUOTECHARACTER(sb.getFilebean().getQuote_character());
               flatfile.setREPEATABLE("NO");
               flatfile.setROWDELIMITER(sb.getFilebean().getRowdelimiter());
               flatfile.setSHIFTSENSITIVEDATA("NO");
               flatfile.setSKIPROWS(sb.getFilebean().getSkiprows());
               flatfile.setSTRIPTRAILINGBLANKS("NO");
               sesstransformationinst1.getFLATFILE().add(flatfile);
            } else {
               flatfile.setCODEPAGE(sb.getFilebean().getCodepage());
               flatfile.setCONSECDELIMITERSASONE("NO");
               flatfile.setDELIMITED("NO");
               flatfile.setDELIMITERS("NO");
               flatfile.setESCAPECHARACTER("");
               flatfile.setKEEPESCAPECHAR("DOUBLE");
               flatfile.setLINESEQUENTIAL(sb.getFilebean().getLinesequential());
               flatfile.setMULTIDELIMITERSASAND("NO");
               flatfile.setNULLCHARTYPE(sb.getFilebean().getNullchartype());
               flatfile.setNULLCHARACTER(sb.getFilebean().getNull_character());
               flatfile.setPADBYTES(sb.getFilebean().getPadbytes());
               flatfile.setQUOTECHARACTER("DOUBLE");
               flatfile.setREPEATABLE(sb.getFilebean().getRepeatable());
               flatfile.setROWDELIMITER("0");
               flatfile.setSHIFTSENSITIVEDATA(sb.getFilebean().getShiftsensitivedata());
               flatfile.setSKIPROWS(sb.getFilebean().getSkiprows());
               flatfile.setSTRIPTRAILINGBLANKS(sb.getFilebean().getStriptrailingblanks());
               sesstransformationinst1.getFLATFILE().add(flatfile);
            }
         } else if (source_ownername != null) {
            ATTRIBUTE attribute1 = new ATTRIBUTE();
            attribute1.setNAME("Owner Name");
            attribute1.setVALUE(source_ownername);
            sesstransformationinst1.getATTRIBUTE().add(attribute1);
         }

         sesstransformationinstList.add(sesstransformationinst1);
         SESSTRANSFORMATIONINST sesstransformationinst2 = new SESSTRANSFORMATIONINST();
         sesstransformationinst2.setTRANSFORMATIONTYPE("Source Qualifier");
         sesstransformationinst2.setTRANSFORMATIONNAME(sqname);
         sesstransformationinst2.setSTAGE("2");
         sesstransformationinst2.setSINSTANCENAME(sqname);
         sesstransformationinst2.setPIPELINE("1");
         sesstransformationinst2.setPARTITIONTYPE("PASS THROUGH");
         sesstransformationinst2.setISREPARTITIONPOINT("YES");
         sesstransformationinstList.add(sesstransformationinst2);
      }

      return sesstransformationinstList;
   }

   public List<SESSIONEXTENSION> getSESSIONEXTENSION(SourceBean sb, TargetBean tb, String sourceDbname, String tragetDbname, String sq_name, String co_target, String sourcedatabasename, String source_dbtype, String target_dbtype, List<MappletMakeDatabean> mapplet) throws Exception {
      List<SESSIONEXTENSION> sessionextensionList = new ArrayList();
      SESSIONEXTENSION sessionextension = new SESSIONEXTENSION();
      CONNECTIONREFERENCE connectionreference = new CONNECTIONREFERENCE();
      if ("Flat File".equals(tb.getDatabasetype())) {
         sessionextension.setNAME("File Writer");
         sessionextension.setSINSTANCENAME(tragetDbname);
         sessionextension.setSUBTYPE("File Writer");
         sessionextension.setTRANSFORMATIONTYPE("Target Definition");
         sessionextension.setTYPE("WRITER");
         connectionreference.setCNXREFNAME("Connection");
         connectionreference.setCONNECTIONNUMBER("1");
         connectionreference.setCONNECTIONSUBTYPE("");
         connectionreference.setCONNECTIONTYPE("");
         connectionreference.setVARIABLE("");
         if ("1".equals(tb.getIsftp())) {
            connectionreference.setCONNECTIONNAME(tb.getFtplink());
            connectionreference.setCONNECTIONTYPE("FTP");
            ATTRIBUTE arr = new ATTRIBUTE();
            arr.setNAME("Remote Filename");
            arr.setVALUE("/" + tb.getFilepath() + "/" + tb.getFilename());
            connectionreference.getATTRIBUTE().add(arr);
         } else {
            connectionreference.setCONNECTIONNAME("");
         }

         for(ATTRIBUTE attribute1 : this.getATTRIBUTETarget(tb.getFilepath(), tb.getFilename(), tb.getTar_name())) {
            sessionextension.getATTRIBUTE().add(attribute1);
         }

         sessionextension.getCONNECTIONREFERENCE().add(connectionreference);
      } else {
         sessionextension.setNAME("Relational Writer");
         sessionextension.setSINSTANCENAME(tb.getTar_name());
         sessionextension.setSUBTYPE("Relational Writer");
         sessionextension.setTRANSFORMATIONTYPE("Target Definition");
         sessionextension.setTYPE("WRITER");
         connectionreference.setCNXREFNAME("DB Connection");
         connectionreference.setCONNECTIONNAME(co_target);
         connectionreference.setCONNECTIONNUMBER("1");
         if ("ORACLE".equals(target_dbtype)) {
            if (sb.getConnectmode().equals("0")) {
               connectionreference.setCONNECTIONSUBTYPE(source_dbtype);
            } else {
               connectionreference.setCONNECTIONSUBTYPE("ODBC");
            }
         } else if ("DB2".equals(target_dbtype)) {
            if (sb.getConnectmode().equals("0")) {
               connectionreference.setCONNECTIONSUBTYPE(source_dbtype);
            } else {
               connectionreference.setCONNECTIONSUBTYPE("ODBC");
            }
         } else if ("Flat File".equals(target_dbtype)) {
            connectionreference.setCONNECTIONSUBTYPE(target_dbtype);
         } else {
            connectionreference.setCONNECTIONSUBTYPE("ODBC");
         }

         connectionreference.setCONNECTIONTYPE("Relational");
         connectionreference.setVARIABLE("");
         sessionextension.getCONNECTIONREFERENCE().add(connectionreference);
         String update = "";
         String insert = "";
         String delete = "";
         String elseinsert = "";
         if ("insert".equals(tb.getInserttype())) {
            insert = "YES";
         } else {
            insert = "NO";
         }

         if ("update".equals(tb.getInserttype())) {
            update = "YES";
         } else {
            update = "NO";
         }

         if ("delete".equals(tb.getInserttype())) {
            delete = "YES";
         } else {
            delete = "NO";
         }

         if ("insertelseupdate".equals(tb.getInserttype())) {
            elseinsert = "YES";
         } else {
            elseinsert = "NO";
         }

         String tranc = "";
         if ("YES".equals(tb.getTranctype())) {
            tranc = "YES";
         } else {
            tranc = "NO";
         }

         String[] attributeStr = new String[]{"Target load type@Normal", "Insert@" + insert, "Update as Update@" + update, "Update as Insert@NO", "Update else Insert@" + elseinsert, "Delete@" + delete, "Truncate target table option@" + tranc, "Reject file directory@$PMBadFileDir", "Reject filename@" + tragetDbname + ".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();
            if (tmpAttr.length > 1) {
               attribute[i].setVALUE(tmpAttr[1]);
            } else {
               attribute[i].setVALUE("");
            }

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

      sessionextensionList.add(sessionextension);
      if ("Flat File".equals(tb.getDatabasetype())) {
         SESSIONEXTENSION sessionextension1 = new SESSIONEXTENSION();
         CONNECTIONREFERENCE connectionreference1 = new CONNECTIONREFERENCE();
         if ("Flat File".equals(sb.getDatabasetype())) {
            sessionextension1.setNAME("File Reader");
            sessionextension1.setSINSTANCENAME(sb.getSo_name());
            sessionextension1.setSUBTYPE("File Reader");
            sessionextension1.setTRANSFORMATIONTYPE("Source Definition");
            sessionextension1.setTYPE("READER");
            sessionextension1.setDSQINSTNAME(sq_name);
            sessionextension1.setDSQINSTTYPE("Source Qualifier");
            connectionreference1.setCNXREFNAME("Connection");
            connectionreference1.setCONNECTIONNUMBER("1");
            connectionreference1.setCONNECTIONSUBTYPE("");
            connectionreference1.setCONNECTIONTYPE("");
            connectionreference1.setVARIABLE("");
         } else {
            sessionextension1.setNAME("Relational Reader");
            sessionextension1.setSINSTANCENAME(sq_name);
            sessionextension1.setSUBTYPE("Relational Reader");
            sessionextension1.setTRANSFORMATIONTYPE("Source Qualifier");
            sessionextension1.setTYPE("READER");
            connectionreference1.setCNXREFNAME("DB Connection");
            connectionreference1.setCONNECTIONNUMBER("1");
            if ("ORACLE".equals(source_dbtype)) {
               if (sb.getConnectmode().equals("0")) {
                  connectionreference1.setCONNECTIONSUBTYPE(source_dbtype);
               } else {
                  connectionreference1.setCONNECTIONSUBTYPE("ODBC");
               }
            } else if ("DB2".equals(source_dbtype)) {
               if (sb.getConnectmode().equals("0")) {
                  connectionreference1.setCONNECTIONSUBTYPE(source_dbtype);
               } else {
                  connectionreference1.setCONNECTIONSUBTYPE("ODBC");
               }
            } else if ("Flat File".equals(source_dbtype)) {
               connectionreference1.setCONNECTIONSUBTYPE(source_dbtype);
            } else {
               connectionreference1.setCONNECTIONSUBTYPE("ODBC");
            }

            connectionreference1.setCONNECTIONTYPE("Relational");
            connectionreference1.setVARIABLE("");
         }

         if ("Flat File".equals(sb.getDatabasetype())) {
            if ("1".equals(sb.getIsftp())) {
               connectionreference1.setCONNECTIONNAME(sb.getFtplink());
               connectionreference1.setCONNECTIONTYPE("FTP");
               ATTRIBUTE arr = new ATTRIBUTE();
               arr.setNAME("Remote Filename");
               arr.setVALUE(sb.getFilename());
               connectionreference1.getATTRIBUTE().add(arr);
            } else {
               connectionreference1.setCONNECTIONNAME("");
            }
         } else {
            connectionreference1.setCONNECTIONNAME(sourcedatabasename);
         }

         sessionextension1.getCONNECTIONREFERENCE().add(connectionreference1);
         if ("Flat File".equals(sb.getDatabasetype())) {
            for(ATTRIBUTE attribute1 : this.getATTRIBUTESource(sb.getFilepath(), sb.getFilename(), sb.getFiledirect())) {
               sessionextension1.getATTRIBUTE().add(attribute1);
            }
         }

         sessionextensionList.add(sessionextension1);
         SESSIONEXTENSION sessionextension3 = new SESSIONEXTENSION();
         if ("Flat File".equals(sb.getDatabasetype())) {
            sessionextension3.setNAME("File Reader");
            sessionextension3.setSINSTANCENAME(sq_name);
            sessionextension3.setSUBTYPE("File Reader");
            sessionextension3.setTRANSFORMATIONTYPE("Source Qualifier");
            sessionextension3.setTYPE("READER");
         } else {
            sessionextension3.setDSQINSTNAME(sq_name);
            sessionextension3.setDSQINSTTYPE("Source Qualifier");
            sessionextension3.setNAME("Relational Reader");
            sessionextension3.setSINSTANCENAME(sourceDbname);
            sessionextension3.setSUBTYPE("Relational Reader");
            sessionextension3.setTRANSFORMATIONTYPE("Source Definition");
            sessionextension3.setTYPE("READER");
         }

         sessionextensionList.add(sessionextension3);
      }

      return sessionextensionList;
   }

   public List<ATTRIBUTE> getATTRIBUTESource(String filepath, String filename, String filedirect) {
      List<ATTRIBUTE> ATTRIBUTEList = new ArrayList();
      if (filepath == null) {
         filepath = "";
      }

      if (filename == null) {
         filename = "";
      }

      String[] attruInfo = new String[]{"Input Type@File", "Concurrent read partitioning@Optimize throughput", "Command Type@Command Generating Data", "Source filetype@" + filedirect, "Source file directory@" + filepath, "Source filename@" + filename, "Command@", "File Reader Truncate String Null@NO", "Codepage Parameter@"};
      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<ATTRIBUTE> getATTRIBUTETarget(String filepath, String filename, String targetname) {
      List<ATTRIBUTE> ATTRIBUTEList = new ArrayList();
      if (filepath == null) {
         filepath = "";
      }

      if (filename == null) {
         filename = "";
      }

      String[] attruInfo = new String[]{"Merge Type@No Merge", "Merge File Directory@$PMTargetFileDir\\", "Merge File Name@" + targetname + ".out", "Append if Exists@NO", "Create Target Directory@NO", "Header Options@No Header", "Header Command@", "Footer Command@", "Output Type@File", "Merge Command@", "Output file directory@/" + filepath, "Output filename@" + filename, "Reject file directory@$PMTargetFileDir\\", "Reject filename@" + targetname + ".bad", "Command@", "Codepage Parameter@"};
      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<ATTRIBUTE> getATTRIBUTEInfo(TargetBean tar, String workflowname, String paramFilepath) {
      List<ATTRIBUTE> ATTRIBUTEList = new ArrayList();
      if (paramFilepath == null) {
         paramFilepath = "";
      }

      String insertype = "";
      if ("insert".equals(tar.getInserttype())) {
         insertype = "Insert";
      } else if ("delete".equals(tar.getInserttype())) {
         insertype = "Delete";
      } else if ("update".equals(tar.getInserttype())) {
         insertype = "Update";
      } else {
         insertype = "Insert";
      }

      String[] attruInfo = new String[]{"General Options@", "Write Backward Compatible Session Log File@NO", "Session Log File Name@" + workflowname + ".log", "Session Log File directory@$PMSessionLogDir\\", "Parameter Filename@" + paramFilepath, "Enable Test Load@NO", "$Source connection value@", "$Target connection value@", "Treat source rows as@" + insertype, "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;
   }
}
