KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > data > user > MemoryUserStore


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.user;
22
23 import java.util.Vector JavaDoc;
24 import java.util.Enumeration JavaDoc;
25 import golfShop.data.user.UserDOImpl;
26 import golfShop.data.user.UserStore;
27
28
29
30 /**
31  * This is one flavor of a UserStore. The storage medium in this case
32  * is memory. A set of users is kept in memory. When the application exits,
33  * all the users are lost.
34  *
35  * @author Andrew John
36  * @version $Revision: 1.1 $
37  */

38 public class MemoryUserStore extends UserStore {
39
40     /**
41      * This is the storage medium. Just keep a set of users in memory.
42      */

43     private Vector JavaDoc allUsers = new Vector JavaDoc();
44
45     /**
46      * Initialize the set of users.
47      */

48       protected void initializeUserStore(String JavaDoc dir) {}
49      
50     protected void initializeUserStore() {
51         UserDOImpl u = new UserDOImpl("enhydra", "lutris", "", "", "", "", "", "" ,"");
52         allUsers.addElement(u);
53     }
54
55     protected boolean usernameInUserStore(String JavaDoc username) {
56         Enumeration JavaDoc e = allUsers.elements();
57         while (e.hasMoreElements()) {
58             UserDOImpl u = (UserDOImpl) e.nextElement();
59             if (username.equals(u.username))
60                 return true;
61         }
62         return false;
63     }
64
65     protected UserDOImpl lookupUserFromUserStore(String JavaDoc username) {
66         Enumeration JavaDoc e = allUsers.elements();
67         while (e.hasMoreElements()) {
68             UserDOImpl u = (UserDOImpl) e.nextElement();
69             if (username.equals(u.username))
70                 return u;
71         }
72         return null;
73     }
74     
75     protected void addUserToUserStore(UserDOImpl user) {
76         allUsers.addElement(user);
77     }
78
79     /**
80      * There is nothing to do! A pointer to the object is already in the
81      * storage vector. There is really only one copy of the object. So in
82      * effect, it is already modified in the storeage medium.
83      */

84     protected void updateUserInUserStore(UserDOImpl user) {
85     }
86     
87 }
88
Popular Tags