KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > data > item > CategoryStoreMemory


1 /*
2  * Enhydra Java Application Server
3  * The Initial Developer of the Original Code is Lutris Technologies Inc.
4  * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
5  * Inc.
6  * All Rights Reserved.
7  *
8  * The contents of this file are subject to the Enhydra Public License Version
9  * 1.0 (the "License"); you may not use this file except in compliance with the
10  * License. You may obtain a copy of the License at
11  * http://www.enhydra.org/software/license/epl.html
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations under the
16  * License.
17  *
18  *
19  */

20
21 package golfShop.data.item;
22
23 import java.util.Vector JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import golfShop.data.item.CategoryDO;
26 import golfShop.data.item.CategoryStore;
27
28
29
30 /**
31  * This is one flavor of a CategoryStore. The storage medium in this case
32  * is memory.
33  *
34  * A item list is kept in memory. When the application exits,
35  * all the items are lost.
36  *
37  * @author Scott Pirie
38  * @version $Revision: 1.1 $
39  */

40 public class CategoryStoreMemory extends CategoryStore
41 {
42     /*----------------------------------------------------------------------*/
43     // Data
44
/*----------------------------------------------------------------------*/
45     /*
46      * This is the storage medium. Keep a set of categories in memory.
47      */

48     private Vector JavaDoc allCategories = new Vector JavaDoc();
49
50     /*----------------------------------------------------------------------*/
51     // Methods
52
/*----------------------------------------------------------------------*/
53     /*
54      * Initialize the set of items.
55      */

56     protected void initializeCategoryStore(String JavaDoc dir)
57     {}
58     protected void initializeCategoryStore()
59     {
60                              // <objectid> <parentid> <Name>
61
CategoryDO main = new CategoryDO (0, 0, "Main Menu");
62     allCategories.addElement(main);
63     main.addItem(1);
64
65     CategoryDO tech = new CategoryDO (1, 0, "High Tech");
66     allCategories.addElement(tech);
67     tech.addItem(2);
68     tech.addItem(3);
69     tech.addItem(4);
70
71     CategoryDO cds = new CategoryDO (2, 0, "CD Companies");
72     allCategories.addElement(cds);
73     cds.addItem(5);
74     cds.addItem(6);
75
76     CategoryDO finance = new CategoryDO(3, 0, "Financial Institutions");
77     allCategories.addElement(finance);
78
79     CategoryDO banks = new CategoryDO(4, 3, "Banks");
80     allCategories.addElement(banks);
81     banks.addItem(7);
82     banks.addItem(8);
83     banks.addItem(9);
84
85     CategoryDO brokers = new CategoryDO(5, 3, "Brokers");
86     allCategories.addElement(brokers);
87     brokers.addItem(10);
88     }
89
90     protected boolean isCategoryInStore(long findId)
91     {
92     Enumeration JavaDoc e = allCategories.elements();
93     while (e.hasMoreElements())
94     {
95         CategoryDO c = (CategoryDO) e.nextElement();
96         if (c.getObjectId() == findId)
97         return true;
98     }
99     return false;
100     }
101
102     protected CategoryDO findCategoryInStore(long findId)
103     {
104     Enumeration JavaDoc e = allCategories.elements();
105     while (e.hasMoreElements())
106     {
107         CategoryDO c = (CategoryDO) e.nextElement();
108         if (c.getObjectId() == findId)
109         return c;
110     }
111     return null;
112     }
113 }
114
Popular Tags