KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > rainterface > AddedUserMemory


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 /*
15  * AddedUserMemory.java
16  *
17  * Created on den 27 juli 2002, 22:01
18  */

19 package org.ejbca.ui.web.admin.rainterface;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.Vector JavaDoc;
23
24
25 /**
26  * A class used to remember a RA Admins last added users. It's use is in the adduser.jsp to list
27  * previously added users give the RA admins a better overlook of the his work.
28  *
29  * @author TomSelleck
30  * @version $Id: AddedUserMemory.java,v 1.1 2006/01/17 20:32:20 anatom Exp $
31  */

32 public class AddedUserMemory implements Serializable JavaDoc {
33     // Public Constants
34
public static final int MEMORY_SIZE = 100; // Remember the 100 last users.
35

36     // Public Methods
37

38     /**
39      * Creates a new instance of AddedUserMemory
40      */

41     public AddedUserMemory() {
42         memory = new Vector JavaDoc();
43     }
44
45     /**
46      * Used to add a user tho the memory
47      *
48      * @param user the UserView representation of the user to add.
49      */

50     public void addUser(UserView user) {
51         memory.add(user);
52
53         while (memory.size() > MEMORY_SIZE) {
54             memory.remove(0);
55         }
56     }
57
58     /**
59      * Used to retrieve a number of previously added users.
60      *
61      * @param size the size of the array of users to return
62      *
63      * @return the 'size' or available users in memory.
64      */

65     public UserView[] getUsers(int size) {
66         int endindex = memory.size() - size;
67         int tempsize = size;
68         UserView[] returnval;
69
70         if (endindex < 0) {
71             endindex = 0;
72         }
73
74         if (size > memory.size()) {
75             tempsize = memory.size();
76         }
77
78         returnval = new UserView[tempsize];
79
80         int j = 0;
81
82         for (int i = memory.size() - 1; i >= endindex; i--) {
83             returnval[j] = (UserView) memory.elementAt(i);
84             j++;
85         }
86
87         return returnval;
88     }
89
90     /**
91      * Used to update the data of a user.
92      *
93      * @param user the stringarray representation of the user to change.
94      */

95     public void changeUser(UserView user) {
96         int i;
97
98         // Find user in memory.
99
for (i = 0; i < memory.size(); i++) {
100             if (((UserView) memory.elementAt(i)).getUsername().equals(user.getUsername())) {
101                 memory.set(i, user);
102
103                 break;
104             }
105         }
106     }
107
108     // Private fields
109
private Vector JavaDoc memory = null;
110 }
111
Popular Tags