package com.rf.util; import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; /* * Revision History(Created on 2006. 9. 30) * ========================================================= * Author Date Description * --------------------------------------------------------- * ÃÖÀç¿ë ¹®ÀÚ¿­µéÀÇ Á¦¾à»çÇ׿¡ ´ëÇÑ Ã³¸®°¡ ¾ÈµÇ¾î ÀÖÀ½. * --------------------------------------------------------- */ class RFStringToClass{ private int GETVALUES = 1; private ArrayList list = null; private String ingKey = ""; private String ingValue = ""; private String str = ""; private StringBuffer toStr = new StringBuffer(); private Vector vector = new Vector(); private int workingMode = -1; private String workingKey = ""; private boolean tempIndexTrue = true; private String tempIndexNumber = ""; private String tempIndexName = ""; /** * true:key, false:value */ private boolean ingMode = true; private RFStringToClass(){} /** * ConsultingArrayMapping »ý¼ºÀÚ * @param str */ public RFStringToClass(String str){ this.str = str.trim(); list = convertArray(new ArrayList()); } /** * data±¸Á¶¸¦ ¸®ÅÏÇÑ´Ù. */ public String toString(){ if(list.size()<=0){ return "[have no data]"; } printArray("",list); return toStr.toString(); } /** * ÇØ´ç À妽ºÀÇ °ªÀ» °¡Á®¿Â´Ù. * @param indexes * @return */ public String getValue(String indexes){ if(indexes.indexOf("[")<0){ return getValueUseDot(indexes); }else{ String index = convertIndexToDot(indexes,""); return getValueUseDot(index); } } /** * key°ª¿¡ ÇØ´çÇÏ´Â valueµéÀ» ¹è¿­·Î ¸®ÅÏÇÑ´Ù. * @param key * @return */ public String[] getValues(String key){ String[] returnValueArray; workingMode = GETVALUES; workingKey = key; printArray("",list); if(vector.size()<=0)returnValueArray = new String[0]; else returnValueArray = convertObjArrToStrArr(vector.toArray()); vector = new Vector(); resetWorking(); return returnValueArray; } private String convertIndexToDot(String indexes, String ingStr){ while(true){ if(indexes.length()<=0){ ingStr+=tempIndexName; tempIndexName = ""; tempIndexNumber = ""; tempIndexTrue = true; break; } String one = indexes.substring(0,0+1); indexes = indexes.substring(0+1,indexes.length()); if(one.equals("[")){ if(!tempIndexTrue){ ingStr+=tempIndexName+"."; } tempIndexName = ""; tempIndexNumber = ""; tempIndexTrue = true; }else if(one.equals("]")){ ingStr+=tempIndexNumber+"."; tempIndexNumber = ""; }else if(one.equals(".")){ tempIndexTrue = false; }else{ if(tempIndexTrue){ tempIndexNumber+=one; }else{ tempIndexName+=one; } } } return ingStr; } /** * value¿¡ ´ëÇÑ Á¢±Ù¹æ¹ýÀÌ .(dot)·Î ±¸ºÐµÇ¾î Àִ°æ¿ì »ç¿ëÇÑ´Ù. * @param dotIndex * ex) 0.user.1.naver.4.name * @return */ private String getValueUseDot(String dotIndex){ String returnStr = ""; String[] indexArr = dotIndex.split("\\.");; ArrayList arrayList = list; Hashtable hashtable = new Hashtable(); for(int i=0 ; i