1 20 21 package golfShop.data.item; 22 23 import java.io.*; 24 import java.util.*; 25 import java.lang.Double ; 26 import com.lutris.logging.Logger; 27 import com.lutris.logging.LogChannel; 28 import com.lutris.appserver.server.Enhydra; 29 import com.lutris.util.Config; 30 import com.lutris.util.ConfigException; 31 import golfShop.data.item.ItemDO; 32 import golfShop.data.item.ItemStore; 33 34 35 40 public class ItemStoreFile extends ItemStore 41 { 42 43 44 46 47 private static Vector allItems = new Vector(); 48 49 50 52 protected void initializeItemStore() 53 {} 54 55 protected void initializeItemStore(String dir) 56 { 57 58 59 findAllItems(dir, ""); 61 } 62 63 64 protected boolean isItemInStore(long findId) 65 { 66 Enumeration e = allItems.elements(); 67 while (e.hasMoreElements()) 68 { 69 ItemDO c = (ItemDO) e.nextElement(); 70 if (c.getObjectId() == findId) 71 return true; 72 } 73 return false; 74 } 75 76 protected ItemDO findItemInStore(long findId) 77 { 78 79 Enumeration e = allItems.elements(); 80 while (e.hasMoreElements()) 81 { 82 ItemDO c = (ItemDO) e.nextElement(); 83 if (c.getObjectId() == findId) 84 return c; 85 } 86 return null; 87 } 88 89 90 92 93 private static void findAllItems (String root, String dir) 94 { 95 String names[] = new String [0]; String filename; 97 File path, fpath; 98 99 100 path = new File(root + 101 ((dir.length())>0 ? File.separator + dir : "")); 102 103 105 106 names = path.list(); 107 108 for (int i=0; i < names.length; i++) 109 { 110 filename = root + 111 ((dir.length())>0 ? File.separator + dir : "") + 112 File.separator + names[i]; 113 114 fpath = new File(filename); 115 if ( fpath.isDirectory() ) 116 { 117 findAllItems(root, dir+File.separator+names[i]); 119 } 120 if ( fpath.isFile() ) 121 { 122 try 123 { 124 125 BufferedReader br = new BufferedReader(new FileReader(filename)); 127 128 allItems.addElement(new ItemDO( 129 (Long.parseLong(names[i])), 130 br.readLine(), 131 (Double.valueOf(br.readLine())).doubleValue(), 132 br.readLine(), 133 br.readLine())); 134 } catch (Exception ioErr) { 135 LogChannel chan = Enhydra.getLogChannel(); 136 if (chan != null) 137 chan.write(Logger.ERROR, "Error reading products.\n" + 138 "Couln't open file " + filename); 139 } 140 } 141 142 } 143 } 144 145 } 146 | Popular Tags |