KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.*;
24 import java.util.*;
25 import com.lutris.util.Config;
26 import com.lutris.util.ConfigException;
27 import com.lutris.logging.Logger;
28 import com.lutris.logging.LogChannel;
29 import com.lutris.appserver.server.Enhydra;
30 import golfShop.data.item.CategoryDO;
31 import golfShop.data.item.CategoryStore;
32
33
34 /**
35  *
36  * @author Scott Pirie
37  * @version $Revision: 1.1 $
38  */

39 public class CategoryStoreFile extends CategoryStore {
40
41     /*----------------------------------------------------------------------*/
42     // Class Data
43
/*----------------------------------------------------------------------*/
44     
45     private static Vector allCategories = new Vector();
46
47     /*----------------------------------------------------------------------*/
48     // Class Methods
49
/*----------------------------------------------------------------------*/
50    protected void initializeCategoryStore() {
51      
52    }
53     protected void initializeCategoryStore(String JavaDoc dir) {
54
55     // Create the top level directory
56
CategoryDO newCategory = new CategoryDO(0, 0, "Main Menu");
57     allCategories.addElement(newCategory);
58
59     // Fill in the subcategories
60
dirList(dir,newCategory, "");
61     }
62
63
64     protected boolean isCategoryInStore(long findId) {
65     Enumeration e = allCategories.elements();
66     while (e.hasMoreElements()) {
67         CategoryDO c = (CategoryDO) e.nextElement();
68         if (c.getObjectId() == findId)
69         return true;
70     }
71     return false;
72     }
73
74     protected CategoryDO findCategoryInStore(long findId) {
75     Enumeration e = allCategories.elements();
76     while (e.hasMoreElements()) {
77         CategoryDO c = (CategoryDO) e.nextElement();
78         if (c.getObjectId() == findId) {
79         return c;
80             }
81     }
82     return null;
83     }
84
85     /*----------------------------------------------------------------------*/
86     // Private Methods
87
/*----------------------------------------------------------------------*/
88     private static int nextObjectId = 1;
89
90  private static void dirList (String JavaDoc root, CategoryDO pc, String JavaDoc dir) {
91  
92     String JavaDoc names[] = new String JavaDoc[0]; // list of files in a diretory
93
String JavaDoc filename;
94     File path, fpath;
95
96   
97  
98     path = new File(root +
99             ((dir.length())>0 ? File.separator + dir : ""));
100
101     // get list of files in this dir
102
names = path.list();
103         if (names == null) {
104             return;
105         }
106     for (int i=0; i < names.length; i++) {
107         filename = root +
108             ((dir.length())>0 ? File.separator + dir : "") +
109             File.separator + names[i];
110         
111         fpath = new File(filename);
112         if (fpath.isDirectory()) {
113         CategoryDO newCategory = new CategoryDO(nextObjectId++,
114                             pc.getObjectId(),
115                             names[i]);
116     
117         allCategories.addElement(newCategory);
118
119         // recursively descend dir tree
120
dirList(root, newCategory, dir+File.separator+names[i]);
121         }
122             if (fpath.isFile()) {
123         pc.addItem(Long.parseLong(names[i]));
124         }
125         
126     }
127     }
128     
129 }
130
Popular Tags