D:\CRM_Project\CRM_Metadata_Structure\NetBeamsICM_TestProject\ICM_DB_TestComponents\src\java\unstructured_data_parser\LoadTokenValueArrayList.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 constants.MainConstants;
  9 import java.io.BufferedInputStream;
 10 import java.io.File;
 11 import java.io.FileInputStream;
 12 import java.io.DataInputStream;
 13 import java.io.BufferedReader;
 14 import java.io.FileReader;
 15 import java.io.IOException;
 16 import java.util.ArrayList;
 17 import unstructured_data_idao.TokenValueDAO;
 18 import java.util.StringTokenizer;
 19 
 20 
 21 /**
 22  *
 23  * @author sameldin
 24  */
 25 public class LoadTokenValueArrayList {
 26 
 27     ArrayList <TokenValueDAO> classTokenValueDAOArrayList = null;
 28     
 29     public LoadTokenValueArrayList() {
 30         
 31         String ICM_TextInputFolder = MainConstants.ICM_INPUT_TEXY_FOLDER_PATH;
 32         String businessTokenIDFilename = ICM_TextInputFolder + "\\" + MainConstants.BUSINESS_TOKEN_ID_TEXT_FILE_NAME;
 33         BufferedReader localBufferedReader = null;
 34         try {
 35 
 36             localBufferedReader = getBufferedReader(businessTokenIDFilename);
 37             if(null == localBufferedReader){
 38                 System.out.println("Error: file " + businessTokenIDFilename + MainConstants.MSG_ERROR_FILE_DOES_NOT_EXIST);
 39                 return;
 40             }
 41             String inputLine = null;
 42             classTokenValueDAOArrayList = new ArrayList<TokenValueDAO>();
 43             while ((inputLine = localBufferedReader.readLine()) != null) { // while loop begins here
 44                 //System.out.println(inputLine);
 45                 StringTokenizer localStringTokenizer = new StringTokenizer(inputLine, ",");
 46                 TokenValueDAO localTokenValueDAO = new TokenValueDAO();
 47                 if(localTokenValueDAO != null){
 48                     String stringToken = localStringTokenizer.nextToken();
 49                     //System.out.println(stringToken);
 50                     String stringValue = localStringTokenizer.nextToken();
 51                     stringValue = stringValue.trim();
 52                     //System.out.println(stringValue);
 53                     localTokenValueDAO.setStringToken(stringToken);
 54                     try {
 55                             int tempInt = Integer.parseInt(stringValue);
 56                             localTokenValueDAO.setTokenValue(tempInt);
 57                         }catch(NumberFormatException e){
 58                             e.printStackTrace();
 59                         }
 60                     String variableNameString = localStringTokenizer.nextToken();;
 61                     //System.out.println(variableNameString);
 62                     localTokenValueDAO.setVariableNameString(variableNameString);
 63                     classTokenValueDAOArrayList.add(localTokenValueDAO);    
 64                 }
 65 //              while (localStringTokenizer.hasMoreElements()) {
 66 //                      System.out.println(localStringTokenizer.nextElement());
 67 //              }
 68                 
 69                 
 70             } // end while 
 71 
 72         } catch (IOException e) {
 73             e.printStackTrace();
 74         } finally {
 75             try {
 76                     localBufferedReader.close();
 77                 } catch (IOException ex) {
 78                         ex.printStackTrace();
 79                 }
 80         }
 81     }
 82     
 83     BufferedReader getBufferedReader(String passedFileName){
 84         
 85         File inFile;
 86         BufferedReader localBufferedReader = null;
 87                 try
 88                 {
 89                 
 90                     inFile = new File(passedFileName);
 91                     if(!inFile.exists()){
 92                         System.out.println("Error: file " + inFile + MainConstants.MSG_ERROR_FILE_DOES_NOT_EXIST);
 93                                 return (null);
 94                     }
 95                     if(inFile.isDirectory()){
 96                         System.out.println("Error: " + inFile + MainConstants.MSG_ERROR_IS_NOT_FILE);
 97                         return(null);
 98                     }
 99                     localBufferedReader = new BufferedReader(new FileReader(passedFileName));                   
100                     // tempReadBufferedFile.close();
101 
102                 }
103                 catch(IOException eIOException)
104                 {
105                         System.out.println("IOException:  " + eIOException);
106                 }
107        
108 
109         return(localBufferedReader);
110     }
111     /*
112     
113     */
114     public ArrayList <TokenValueDAO> getTokenValueArrayList() {
115         
116         return(classTokenValueDAOArrayList);
117     }
118     
119     /*
120     
121     */
122         public static void main(String[] args) {
123             
124             LoadTokenValueArrayList localloadTokenValueArrayList = new LoadTokenValueArrayList();
125             int t = 0;
126             t++;
127         }    
128 }
129