GenericUserRegistryImpl.java |
1 /* 2 * Copyright 2000-2001,2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 19 */ 20 21 package org.apache.wsrp4j.consumer.driver; 22 23 import java.util.Hashtable; 24 import java.util.Iterator; 25 26 import org.apache.wsrp4j.consumer.User; 27 import org.apache.wsrp4j.consumer.UserRegistry; 28 29 public class GenericUserRegistryImpl implements UserRegistry { 30 31 private Hashtable users; 32 33 public GenericUserRegistryImpl() { 34 this.users = new Hashtable(); 35 } 36 37 /** 38 * Get the user with the given id 39 * 40 * @param userID The ID of the user 41 * 42 * @return The user 43 **/ 44 public User getUser(String userID) { 45 if (userID != null) { 46 return (User) users.get(userID); 47 } 48 49 return null; 50 } 51 52 /** 53 * Remove a user from the list of known user 54 * 55 * @param userID The ID of the user 56 * @return The user which has been removed or null 57 **/ 58 public User removeUser(String userID) { 59 if (userID == null) 60 return null; 61 62 return (User) users.remove(userID); 63 } 64 65 /** 66 * Add a user. If a record with the given userid already exists, 67 * the input UserContext object is returned, otherwise a null value. 68 * 69 * @param user The user object to add 70 * 71 * @return Null on success or the input user object 72 * in case a user with the same user id already exists. 73 **/ 74 public User addUser(User user) { 75 76 if (user != null) { 77 78 String userID = user.getUserID(); 79 if (userID != null) { 80 if (!users.containsKey(userID)) { 81 users.put(userID, user); 82 83 return null; 84 } 85 } 86 } 87 88 return user; 89 } 90 91 /** 92 * Get an iterator with all known users 93 * 94 * @return All known user contexts in an iterator 95 **/ 96 public Iterator getAllUsers() { 97 return users.values().iterator(); 98 } 99 100 public void removeAllUsers() { 101 users.clear(); 102 } 103 }