Project 3

cscie259.project3.wahoo
Class UserManager

java.lang.Object
  extended by cscie259.project3.wahoo.UserManager

public final class UserManager
extends java.lang.Object

This class keeps track of users of the Wahoo portal by writing out information to an xml file. You MAY modify this file.

Version:
8.0
Author:
Computer Science E-259, YOUR NAME GOES HERE

Nested Class Summary
private  class UserManager.UserReader
          An inner class which is the SAX2 handler used to read the user XML file into Java objects.
 
Field Summary
private  javax.servlet.ServletContext context_
          a reference to the servlet context
private static UserManager instance_
          a reference to the one and only instance of this class
private  java.util.Map<java.lang.String,User> users_
          a hash table of all users
 
Constructor Summary
private UserManager(javax.servlet.ServletContext context)
          A constructor that reads the user DB from an input stream.
 
Method Summary
static User addUser(java.lang.String username, java.lang.String password)
          Adds a new user using the given username and password.
private  User addUserImpl(java.lang.String username, java.lang.String password)
          Adds a new user using the supplied username and password.
static User getUser(java.lang.String username)
          Returns a User object for given username or null if one is not found.
private  User getUserImpl(java.lang.String username)
          Returns a User object for given username or null if one is not found.
static void init(javax.servlet.ServletContext context)
          Must be called (e.g., by Login's init() method) once before using any other method in class.
private static UserManager instance()
          Returns the one and only instance of this class, throwing an exception if it has not been initialized.
private  void readUsers(java.io.InputStream in)
          Read the user info from the input stream.
static void save()
          Saves the information about all users to the information database (stored as a file).
private  void writeUsers()
          Writes users info to the config file, overwriting old contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context_

private javax.servlet.ServletContext context_
a reference to the servlet context


instance_

private static UserManager instance_
a reference to the one and only instance of this class


users_

private java.util.Map<java.lang.String,User> users_
a hash table of all users

Constructor Detail

UserManager

private UserManager(javax.servlet.ServletContext context)
A constructor that reads the user DB from an input stream.

Method Detail

addUser

public static User addUser(java.lang.String username,
                           java.lang.String password)
Adds a new user using the given username and password. Returns the new User object if the operation succeeded or null if the user could not be added because the username was already taken.

Parameters:
username - user's username
password - user's password
Returns:
User object belonging to given username and password

addUserImpl

private User addUserImpl(java.lang.String username,
                         java.lang.String password)
Adds a new user using the supplied username and password. Returns the new User object if the operation succeeded or null if the user could not be added becuase the username was already taken.

Parameters:
username - user's username
password - user's password
Returns:
User object belonging to given username and password

getUser

public static User getUser(java.lang.String username)
Returns a User object for given username or null if one is not found.

Parameters:
username - user's username
Returns:
User object belonging to given username

getUserImpl

private User getUserImpl(java.lang.String username)
Returns a User object for given username or null if one is not found.

Parameters:
username - user's username
Returns:
User object belonging to given username

init

public static void init(javax.servlet.ServletContext context)
Must be called (e.g., by Login's init() method) once before using any other method in class.

Parameters:
context - servlet's context object

instance

private static UserManager instance()
Returns the one and only instance of this class, throwing an exception if it has not been initialized.


readUsers

private void readUsers(java.io.InputStream in)
Read the user info from the input stream.

Parameters:
in - input stream

save

public static void save()
Saves the information about all users to the information database (stored as a file). Call this methods whenever you have made changed to User objects you would like to save. If you do not call this method, your chages will be lost next time you start up the server.


writeUsers

private void writeUsers()
Writes users info to the config file, overwriting old contents.


Project 3