D:\CRM_Project\CRM_Metadata_Structure\NetBeamsICM_TestProject\ICM_DB_TestComponents\src\java\unstructured_data_parser\DAO2SOAP_XML_Converter.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 package unstructured_data_parser;
  7 
  8 import javax.xml.soap.MessageFactory;
  9 import javax.xml.soap.SOAPBody;
 10 import javax.xml.soap.SOAPBodyElement;
 11 import javax.xml.soap.SOAPEnvelope;
 12 import javax.xml.soap.SOAPHeader;
 13 import javax.xml.soap.SOAPMessage;
 14 import javax.xml.soap.SOAPPart;
 15 import javax.xml.soap.Name;
 16 import javax.xml.soap.SOAPElement;
 17 
 18 import constants.MainConstants;
 19 import java.io.FileOutputStream;
 20 import java.util.ArrayList;
 21 import unstructured_data_idao.ExcelCellMap2DAO;
 22 import unstructured_data_idao.ExcelDAO_Constants;
 23 import unstructured_data_idao.OneRow_ExcelCells;
 24 import unstructured_data_idao.SOAP_XML_Constants;
 25 
 26 /**
 27  *
 28  * @author sameldin
 29  */
 30 public class DAO2SOAP_XML_Converter {
 31     
 32     public DAO2SOAP_XML_Converter(ArrayList <OneRow_ExcelCells> passedAllRows) {
 33 
 34         String javaCompliedCodePath = "D:/CRM_Project/CRM_Metadata_Structure/ICM_InputData/SOAP_XMLfiles/";
 35         
 36         try
 37         {
 38             MessageFactory factory = MessageFactory.newInstance();
 39             SOAPMessage localSOAPMessage = factory.createMessage();
 40             SOAPPart localSOAPPart = localSOAPMessage.getSOAPPart();
 41 
 42             SOAPEnvelope soapEnvelope = localSOAPPart.getEnvelope();
 43             SOAPHeader soapHeader = soapEnvelope.getHeader();
 44             SOAPBody soapBody = soapEnvelope.getBody();
 45 
 46             soapHeader.addTextNode("Converting Excel sheet to ArrayList of DAO, and to SOAP XML file.");
 47             //==========================
 48             Name classInformation_Name = soapEnvelope.createName(SOAP_XML_Constants.CLASS_INFORMATION_STRING  + SOAP_XML_Constants.CLASS_INFORMATION_XML_PROCESS_INDEX);
 49             Name packageName_Name = soapEnvelope.createName(SOAP_XML_Constants.PACKAGE_NAME_STRING + SOAP_XML_Constants.PACKAGE_NAME_XML_PROCESS_INDEX);
 50             Name pathName_Name = soapEnvelope.createName(SOAP_XML_Constants.CLASS_PATH_STRING + SOAP_XML_Constants.CLASS_PATH_XML_PROCESS_INDEX);
 51             Name daoName_Name = soapEnvelope.createName(SOAP_XML_Constants.CLASS_NAME_STRING + SOAP_XML_Constants.CLASS_NAME_XML_PROCESS_INDEX);
 52             //==========================           
 53             SOAPBodyElement classInformationBodyElement = soapBody.addBodyElement(classInformation_Name);
 54             SOAPElement packageElement  = classInformationBodyElement.addChildElement(packageName_Name);
 55             SOAPElement pathElement     = classInformationBodyElement.addChildElement(pathName_Name);
 56             SOAPElement daoElement      = classInformationBodyElement.addChildElement(daoName_Name);
 57             
 58             packageElement.addTextNode("using_business_rule_1 ");
 59             pathElement.addTextNode(javaCompliedCodePath);
 60             daoElement.addTextNode("SimpleInputExcelSheet.class");
 61             //==========================
 62             Name daoObjectName = soapEnvelope.createName(SOAP_XML_Constants.DAO_OBJECT_STRING + SOAP_XML_Constants.DAO_OBJECT_XML_PROCESS_INDEX);
 63             Name propertiesName = soapEnvelope.createName(SOAP_XML_Constants.DAO_FIELDS_START + SOAP_XML_Constants.DAO_FIELDS_XML_PROCESS_INDEX);
 64 
 65             SOAPElement propertiesAllSubElement = null;
 66             SOAPElement propertyNameElement = null;
 67             SOAPElement propertyTypeElement = null;           
 68             SOAPElement propertyValueElement = null;            
 69             SOAPElement propertyIDElement = null;
 70             //=======================================
 71             Name propertyTagName_Name       = soapEnvelope.createName(SOAP_XML_Constants.FIELD_NAME_STRING  + SOAP_XML_Constants.FIELD_NAME_XML_PROCESS_INDEX);
 72             Name propertyTagType_Name       = soapEnvelope.createName(SOAP_XML_Constants.FIELD_TYPE_STRING  + SOAP_XML_Constants.FIELD_TYPE_XML_PROCESS_INDEX);
 73             Name propertyTagValue_Name      = soapEnvelope.createName(SOAP_XML_Constants.FIELD_VALUE_STRING + SOAP_XML_Constants.FIELD_VALUE_XML_PROCESS_INDEX);
 74             Name propertyTagID_Name         = soapEnvelope.createName(SOAP_XML_Constants.FIELD_ID_STRING    + SOAP_XML_Constants.FIELD_ID_XML_PROCESS_INDEX);
 75             //=======================================
 76             // first row has all the names of all fields
 77             OneRow_ExcelCells firstCell2DAORowObject  = passedAllRows.get(0);
 78             ArrayList <ExcelCellMap2DAO> FirstrowArrayList = firstCell2DAORowObject.getOneRowDAOArrayList();
 79             int rowNumber = 1;
 80             for(rowNumber = 1; rowNumber < passedAllRows.size(); rowNumber++){
 81 //            for(rowNumber = 1; rowNumber < 6; rowNumber++){
 82                 
 83             SOAPBodyElement daoObjectBodyElement = soapBody.addBodyElement(daoObjectName);
 84                 
 85                 OneRow_ExcelCells oneCell2DAORowObject  = passedAllRows.get(rowNumber);
 86                 ArrayList <ExcelCellMap2DAO> rowsArrayList = oneCell2DAORowObject.getOneRowDAOArrayList();
 87                 int columnNumber = 0;
 88                 for(columnNumber = 0; columnNumber < rowsArrayList.size(); columnNumber++) {
 89 
 90             //=======================================
 91             propertiesAllSubElement = daoObjectBodyElement.addChildElement(propertiesName);                       
 92                     
 93                         ExcelCellMap2DAO localExcelCellMap2DAO = rowsArrayList.get(columnNumber);
 94                         String propertyNameString   = "";
 95                         String propertyTypeString   = "";
 96                         String propertyValueString  = "";
 97                         String propertyIDString     = "";
 98                         
 99                         int rowIndex     = localExcelCellMap2DAO.getRowIndex() + 1;
100                         int columnIndex  = localExcelCellMap2DAO.getColumnIndex() + 1;
101                         int rowColumnID  = rowIndex * ExcelDAO_Constants.DAO_ROW_COLUMN_ID_CONVERTER + columnIndex;
102                         propertyIDString = "" + rowColumnID;
103                         propertyIDElement = propertiesAllSubElement.addChildElement(propertyTagID_Name);
104                         propertyIDElement.addTextNode(propertyIDString);
105                         //===================================================================
106                         // first row of cells has the column names
107                         ExcelCellMap2DAO tempNameCellDAO_object = FirstrowArrayList.get(columnNumber);
108                         propertyNameString = tempNameCellDAO_object.getPossibleVariableName();
109                         propertyNameElement = propertiesAllSubElement.addChildElement(propertyTagName_Name);
110                         propertyNameElement.addTextNode(propertyNameString);
111                         //===================================================================
112                         int cellTypeIndex = localExcelCellMap2DAO.getCellType();
113         
114                         switch(cellTypeIndex)
115                         {
116                             case ExcelDAO_Constants.EXCEL_CELL_TYPE_BLANK:
117                                 propertyTypeString = "Blank";
118                                 propertyValueString = "BLANK";
119                                 break;
120                             case ExcelDAO_Constants.EXCEL_CELL_TYPE_STRING:
121                                 propertyTypeString = "String";
122                                 propertyValueString = localExcelCellMap2DAO.getPossibleVariableName();
123                                 break;
124                             case ExcelDAO_Constants.EXCEL_CELL_TYPE_NUMERIC:
125                                 propertyTypeString = "double";
126                                 propertyValueString = "" + localExcelCellMap2DAO.getDoubleCellValue();
127                                 break;
128                             case ExcelDAO_Constants.EXCEL_CELL_TYPE_BOOLEAN:
129                                 propertyTypeString = "BOOLEAN";
130                                 propertyValueString = "BOOLEAN";
131                                 break;
132                             case ExcelDAO_Constants.EXCEL_CELL_TYPE_FORMULA:
133                                 propertyTypeString = "FORMULA";
134                                 propertyValueString = "FORMULA";
135                                 break;
136                             case ExcelDAO_Constants.EXCEL_CELL_TYPE_ERROR:
137                                 propertyTypeString = "Error";
138                                 propertyValueString = "Error";
139                                 break;
140                             case ExcelDAO_Constants.EXCEL_CELL_TYPE_DEFAULT:
141                                 propertyTypeString = "Error";
142                                 propertyValueString = "error";
143                                 break;
144                            default:
145                                 System.out.println("default ");
146 
147                         }          
148                         
149                         propertyTypeElement = propertiesAllSubElement.addChildElement(propertyTagType_Name);
150                         propertyTypeElement.addTextNode(propertyTypeString);
151                         //===================================================================
152                         propertyValueElement = propertiesAllSubElement.addChildElement(propertyTagValue_Name);
153                         propertyValueElement.addTextNode(propertyValueString);
154                 }
155             }
156             //================================
157             //localSOAPMessage.writeTo(System.out);
158 
159             FileOutputStream fOut = new FileOutputStream(javaCompliedCodePath + "SimpleInputExcelSheet_XML.xml");
160             localSOAPMessage.writeTo(fOut);
161 
162             System.out.println();
163             System.out.println("good job??");
164             
165 
166         }
167         catch(Exception e){
168             e.printStackTrace();
169         }
170     }
171     /*
172        
173     */
174     public static void main(String[] args){
175         
176         // should not be tested unless you all the rows popualted
177         // ArrayList <OneRow_ExcelCells> localAllRows = null; //
178         // DAO2SOAP_XML_Converter tempDAO2SOAP_XML_Converter = new DAO2SOAP_XML_Converter(localAllRows);
179         int stopdebugger = 0;
180     }    
181 }
182