package foms.common;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Vector;
/*
2011.02.01 작성
각종 코드 리스트들을 추출하여 쓰기 위해 ( DB트랜잭션 최소화) 만듦
작성자 : 나도몰라
Singleton pattern 으로 제작.
*/
public class codeList {
private static codeList instance = new codeList();
private static HashMap codeListData =new HashMap();
final static String fileUrl ="C:/program1/KDN/Forms/WebContent/test/inspection_list.txt";
/*Creator*/
private codeList(){
System.out.println("Creat Object ~");
}
/*싱글톤 패턴 : 메모리에 단 한번 올라가고 올라간후에는 계속 재사용을 한다. 상단 해쉬맵 포함.*/
public static codeList getInstance(){
if(null==instance){
instance = new codeList();
}
return instance;
}
/* 순시종류 출력을 위한 메쏘드*/
public static String getCodeName(String codeValue){
String codeName ="";
try{
commonFileAccess(fileUrl);
codeName = (String) codeListData.get(codeValue);
}catch(Exception ex){
ex.printStackTrace();
}
return codeName;
}
/*공통파일처리 메쏘드*/
protected static HashMap commonFileAccess(String fileLink){
try{
if(codeListData.isEmpty()){
System.out.println("FILE READING Start~~~~");
FileInputStream fis = new FileInputStream(fileLink);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String buff = null;
int index = 0;
while((buff = br.readLine()) != null){
String[] items = buff.split(",");
for (String item : items) {
codeListData.put(items[0],items[1]);
}
}
}
}catch(Exception e){
e.printStackTrace();
}
return codeListData;
}
}