1 20 21 package golfShop.data.item; 22 23 import java.util.Vector ; 24 import java.util.Enumeration ; 25 import java.lang.Object ; 26 27 28 31 37 public class CategoryDO 38 { 39 40 42 private static CategoryStore storage = null; 43 44 45 47 48 51 52 public static void InitializeStorageOption(String opt,String dir) { 53 54 try 55 { 56 57 if (opt.equalsIgnoreCase("memory")){ 58 storage = new CategoryStoreMemory(); 59 storage.initializeCategoryStore(); 60 } 61 else if (opt.equalsIgnoreCase("file")) 62 { 63 storage = new CategoryStoreFile(); 64 storage.initializeCategoryStore(dir); 65 66 } 67 else 68 { 69 storage = new CategoryStoreMemory(); 70 storage.initializeCategoryStore(); 71 } 72 } 73 catch (Exception e) 74 { 75 } 76 77 } 78 79 80 81 82 85 protected CategoryDO(long objectId, long parentId, String name) 86 { 87 this.objectId = objectId; 88 this.parentId = parentId; 89 this.name = name; 90 this.subList = new Vector (); 91 this.itemList = new Vector (); 92 this.isDirty = false; 93 94 CategoryDO parent = getCategory(parentId); 96 if ( parent != null ) 97 parent.addSubCategory(objectId); 98 } 99 100 103 public static CategoryDO getCategory(long objid) 104 { 105 return(storage.findCategoryInStore(objid)); 106 } 107 108 109 111 private long objectId; private long parentId; private String name; private Vector subList; private Vector itemList; private boolean isDirty; 118 119 121 122 public long getObjectId() 123 { 124 return this.objectId; 125 } 126 protected void setObjectId(long newId) 128 { 129 this.objectId = newId; 130 } 131 132 public long getParentId() 133 { 134 return this.parentId; 135 } 136 public void setParentId(long newId) 137 { 138 this.parentId = newId; 139 } 140 141 public String getName() 142 { 143 return this.name; 144 } 145 public void setName(String newName) 146 { 147 this.name = newName; 148 } 149 150 public void addSubCategory(long subObjectId) 151 { 152 for ( Enumeration e = this.subList.elements(); e.hasMoreElements() ; ) 154 { 155 Long o = (Long ) e.nextElement() ; 156 if (o.longValue() == subObjectId) 157 return; 158 } 159 160 Long newsub = new Long (subObjectId); 162 this.subList.addElement(newsub); 163 } 164 public void removeSubCategory(long subObjectId) 165 { 166 for ( Enumeration e = this.subList.elements(); e.hasMoreElements() ; ) 167 { 168 Long o = (Long ) e.nextElement() ; 169 if (o.longValue() == subObjectId) 170 this.subList.removeElement((Object ) o); 171 } 172 } 173 174 177 public long[] getSubCategories() 178 { 179 Enumeration e; 180 int count; 181 182 long[] list = new long[this.subList.size()]; 183 184 for ( e = this.subList.elements(), count = 0 ; 185 e.hasMoreElements() ; 186 count++ ) 187 { 188 Long o = (Long ) e.nextElement() ; 189 list[count] = o.longValue(); 190 } 191 return list; 192 } 193 194 197 public void addItem(long objectId) 198 { 199 for ( Enumeration e = this.itemList.elements(); e.hasMoreElements() ; ) 201 { 202 Long o = (Long ) e.nextElement() ; 203 if (o.longValue() == objectId) 204 return; 205 } 206 207 Long newitem = new Long (objectId); 209 this.itemList.addElement(newitem); 210 } 211 public void removeItem(long objectId) 212 { 213 for ( Enumeration e = this.itemList.elements(); e.hasMoreElements() ; ) 214 { 215 Long o = (Long ) e.nextElement() ; 216 if (o.longValue() == objectId) 217 this.itemList.removeElement(o); 218 } 219 } 220 223 public long[] getItems() 224 { 225 Enumeration e; 226 int count; 227 228 long[] list = new long[this.itemList.size()]; 229 230 for ( e = this.itemList.elements(), count = 0 ; 231 e.hasMoreElements() ; 232 count ++) 233 { 234 Long o = (Long ) e.nextElement() ; 235 list[count] = o.longValue(); 236 } 237 return list; 238 } 239 } 240 | Popular Tags |