001: /*
002: * Copyright 2000-2001,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: /*
018:
019: */
020:
021: package org.apache.wsrp4j.consumer.driver;
022:
023: import java.util.Hashtable;
024: import java.util.Iterator;
025:
026: import org.apache.wsrp4j.consumer.User;
027: import org.apache.wsrp4j.consumer.UserRegistry;
028:
029: public class GenericUserRegistryImpl implements UserRegistry {
030:
031: private Hashtable users;
032:
033: public GenericUserRegistryImpl() {
034: this .users = new Hashtable();
035: }
036:
037: /**
038: * Get the user with the given id
039: *
040: * @param userID The ID of the user
041: *
042: * @return The user
043: **/
044: public User getUser(String userID) {
045: if (userID != null) {
046: return (User) users.get(userID);
047: }
048:
049: return null;
050: }
051:
052: /**
053: * Remove a user from the list of known user
054: *
055: * @param userID The ID of the user
056: * @return The user which has been removed or null
057: **/
058: public User removeUser(String userID) {
059: if (userID == null)
060: return null;
061:
062: return (User) users.remove(userID);
063: }
064:
065: /**
066: * Add a user. If a record with the given userid already exists,
067: * the input UserContext object is returned, otherwise a null value.
068: *
069: * @param user The user object to add
070: *
071: * @return Null on success or the input user object
072: * in case a user with the same user id already exists.
073: **/
074: public User addUser(User user) {
075:
076: if (user != null) {
077:
078: String userID = user.getUserID();
079: if (userID != null) {
080: if (!users.containsKey(userID)) {
081: users.put(userID, user);
082:
083: return null;
084: }
085: }
086: }
087:
088: return user;
089: }
090:
091: /**
092: * Get an iterator with all known users
093: *
094: * @return All known user contexts in an iterator
095: **/
096: public Iterator getAllUsers() {
097: return users.values().iterator();
098: }
099:
100: public void removeAllUsers() {
101: users.clear();
102: }
103: }
|