org.salespointframework.core.users
Class UserManager

java.lang.Object
  extended by org.salespointframework.core.users.UserManager
All Implemented Interfaces:
DatasourceChangeListener, DatasourceOnChangeListener, ExternalModificationListener, SpAggregate
Direct Known Subclasses:
UserManagerFilter

public class UserManager
extends java.lang.Object
implements DatasourceChangeListener, DatasourceOnChangeListener, ExternalModificationListener, SpAggregate

Manages users, their capabilities and their associations to other objects.

The UserManager provides possibilities to manage any number of users. Users can be added, retrieved using their name to identify them, and removed from the system. Additionally, users can be associated to, and disassociated from, any object. Their can be a maximum of one user associated to any given object at any given time.

You can provide a set of default capabilities, that every new user will be provided with.

Since:
v2.0
Version:
2.0 05/05/1999
Author:
Steffen Zschaler
See Also:
User, setDefaultCaps(java.util.Map), SalesPoint, logOn(java.lang.Object, org.salespointframework.core.users.User)

Field Summary
protected  ListenerHelper m_lhListeners
          The list of listeners registered with this UserManager.
private  java.util.Map<java.lang.Object,User> m_mpCurrentUsers
          The map used to store all the users currently associated to some object.
private  java.util.Map<java.lang.String,Capability> m_mpDefaultCaps
          The map of default capabilities to be associated with each new user.
private  java.util.Map<java.lang.String,User> m_mpUsers
          The map used to store all the users managed by this UserManager.
private  UserCreator m_ucCreator
          The factory used to create new User objects.
private static UserManager s_umGlobal
          The global UserManager.
 
Constructor Summary
UserManager()
          Create a new UserManager with an empty set of default capabilities, managing direct instances of the User class.
UserManager(java.util.Map<java.lang.String,Capability> mpDefaultCaps)
          Create a new UserManager, using a specific set of default capabilities.
UserManager(java.util.Map<java.lang.String,Capability> mpDefaultCaps, UserCreator ucCreator)
          Create a new UserManager providing both a set of default capabilities and a User creation factory.
UserManager(UserCreator ucCreator)
          Create a new UserManager with an empty set of default capabilities.
 
Method Summary
 void addUser(User usr)
          Add a user to the UserManager.
 void addUserDataListener(UserDataListener udl)
          Add a UserDataListener.
 User createUser(java.lang.String sName)
          Create a new user to be managed by this UserManager.
 void DatasourceChanged(boolean pumpUp)
          the datasource changed
 void DatasourceOnChange()
          call users to free their resources
 User deleteUser(java.lang.String sName)
          Delete a user from this UserManager.
 void externalModificationOccurred()
          simulate DatasourceChanged(boolean) on external modification
protected  void fireUserAdded(User usr)
          Fire a userAdded event to all interested listeners.
protected  void fireUserDataChanged(User usr)
          Fire userDataChanged event
protected  void fireUserDeleted(User usr)
          Fire a userDeleted event to all interested listeners.
 User getCurrentUser(java.lang.Object o)
          Retrieve the user currently associated with some Object.
static UserManager getGlobalUM()
          Deprecated. 
static UserManager getInstance()
          Get the global UserManager instance
 User getUser(java.lang.String sName)
          Retrieve a user by name.
 java.util.Set<java.lang.String> getUserNames()
          Return all user names registered with this UserManager.
 java.util.Collection<User> getUsers()
          Return all users registered with this UserManager.
 User logOff(java.lang.Object o)
          Disassociate the current user from an Object.
 User logOn(java.lang.Object o, User u)
          Associate a user with an object.
 void removeUserDataListener(UserDataListener udl)
          Remove a UserDataListener.
 void setDefaultCapability(Capability cap)
          Set a capability to be used as a default capability henceforward.
 void setDefaultCaps(java.util.Map<java.lang.String,Capability> mpDefaultCaps)
          Specify the set of default capabilities to be used when creating new User objects.
static UserManager setGlobalUM(UserManager umNew)
          Deprecated. 
static void setInstance(UserManager um)
          Set the UserManager instance
 void setUserCreator(UserCreator ucCreator)
          Set the factory to be used when creating new User objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_mpUsers

private java.util.Map<java.lang.String,User> m_mpUsers
The map used to store all the users managed by this UserManager.

The user's name is being used as the key. The user itself is being stored as the value.

See Also:
User

m_mpCurrentUsers

private java.util.Map<java.lang.Object,User> m_mpCurrentUsers
The map used to store all the users currently associated to some object.

The key of the map is the object to which a given user is associated. The user itself is being stored as the value.

See Also:
User, logOn(java.lang.Object, org.salespointframework.core.users.User)

m_mpDefaultCaps

private java.util.Map<java.lang.String,Capability> m_mpDefaultCaps
The map of default capabilities to be associated with each new user.

The keys and values are being used in the same way as User uses them, i.e. the capabilities names are used as keys and the capabilities themselves as values.

See Also:
setDefaultCaps(java.util.Map), Capability, User.setCapabilities(java.util.Map)

m_ucCreator

private UserCreator m_ucCreator
The factory used to create new User objects.

See Also:
createUser(java.lang.String), setUserCreator(org.salespointframework.core.users.UserCreator), User

m_lhListeners

protected ListenerHelper m_lhListeners
The list of listeners registered with this UserManager.


s_umGlobal

private static UserManager s_umGlobal
The global UserManager.

Constructor Detail

UserManager

public UserManager()
Create a new UserManager with an empty set of default capabilities, managing direct instances of the User class.

See Also:
setDefaultCaps(java.util.Map), createUser(java.lang.String)

UserManager

public UserManager(java.util.Map<java.lang.String,Capability> mpDefaultCaps)
Create a new UserManager, using a specific set of default capabilities. This UserManager will manage direct instances of User.

Parameters:
mpDefaultCaps - a map describing the default capabilities any new user should have. The keys of this map should be the name of their associated capability. Specifying null will result in there being no default capabilities.
See Also:
setDefaultCaps(java.util.Map), createUser(java.lang.String), Capability

UserManager

public UserManager(UserCreator ucCreator)
Create a new UserManager with an empty set of default capabilities. This UserManager will create instances of a developer defined subclass of User.

Parameters:
ucCreator - the factory to be used to create new User objects. Specifying null will result in a default implementation being used, which will create direct instances of the User class.
See Also:
setDefaultCaps(java.util.Map), createUser(java.lang.String)

UserManager

public UserManager(java.util.Map<java.lang.String,Capability> mpDefaultCaps,
                   UserCreator ucCreator)
Create a new UserManager providing both a set of default capabilities and a User creation factory.

Parameters:
mpDefaultCaps - a map describing the default capabilities any new user should have. The keys of this map should be the name of their associated capability. Specifying null will result in there being no default capabilities.
ucCreator - the factory to be used to create new User objects. Specifying null will result in a default implementation being used, which will create direct instances of the User class.
See Also:
setDefaultCaps(java.util.Map), Capability, createUser(java.lang.String), User
Method Detail

setUserCreator

public void setUserCreator(UserCreator ucCreator)
Set the factory to be used when creating new User objects.

Parameters:
ucCreator - the factory to be used to create new User objects. Specifying null will result in a default implementation being used, which will create direct instances of the User class.
See Also:
createUser(java.lang.String), User

setDefaultCaps

public void setDefaultCaps(java.util.Map<java.lang.String,Capability> mpDefaultCaps)
Specify the set of default capabilities to be used when creating new User objects.

Calling this method will not influence the capabilities of users already created.

Parameters:
mpDefaultCaps - a map describing the default capabilities any new user should have. The keys of this map should be the name of their associated capability. Specifying null will result in there being no default capabilities.
See Also:
createUser(java.lang.String), Capability

setDefaultCapability

public void setDefaultCapability(Capability cap)
Set a capability to be used as a default capability henceforward.

Calling this method will not influence the capabilities of users already created.

If a default capability of the same name as the one given did already exist, it will be replaced by the new capability.

Parameters:
cap - the capability to be set as a default capability.
See Also:
createUser(java.lang.String)

createUser

public User createUser(java.lang.String sName)
Create a new user to be managed by this UserManager.

This method uses the defined UserCreator (see setUserCreator(org.salespointframework.core.users.UserCreator)) to create the new User object. The new user will later be accessible using its name.

The newly created user will get all the default capabilities defined at the time this method is called.

A userAdded event will be received by any UserDataListener that registered an interest in this UserManager.

Parameters:
sName - the name of the new user. This must be unique, i.e. there must not be a user with the same name already managed by this UserManager.
Returns:
the newly created user.
Throws:
DuplicateUserException - if there already was a user with the given name.
See Also:
setDefaultCaps(java.util.Map), setUserCreator(org.salespointframework.core.users.UserCreator), User, UserCreator.createUser(java.lang.String), UserDataListener.userAdded(org.salespointframework.core.users.events.UserDataEvent)

addUser

public void addUser(User usr)
Add a user to the UserManager.

A userAdded event will be received by any UserDataListener that registered an interest in this UserManager.

Parameters:
usr - the user to be added.
Throws:
DuplicateUserException - if there already is a user of the same name.
See Also:
UserDataListener.userAdded(org.salespointframework.core.users.events.UserDataEvent)

getUser

public User getUser(java.lang.String sName)
Retrieve a user by name.

If no user with the given name exists, this method will return null.

Parameters:
sName - the name of the user looked for.
Returns:
the user corresponding to the given name, if any. null will be returned if no such user can be found.
See Also:
createUser(java.lang.String)

getUserNames

public java.util.Set<java.lang.String> getUserNames()
Return all user names registered with this UserManager.

The returned set is backed by the UserManager, i.e. it will reflect changes made through createUser() or removeUser(). The set itself is unmodifiable and ordered alphabetically.

Returns:
an unmodifiable, ordered set of all user names in this UserManager.
See Also:
createUser(java.lang.String), deleteUser(java.lang.String)

getUsers

public java.util.Collection<User> getUsers()
Return all users registered with this UserManager.

The returned collection is backed by the UserManager, i.e. it will reflect changes made through createUser() or removeUser(). The collection itself is unmodifiable and ordered alphabetically by the users' names.

Returns:
an unmodifiable, ordered set of all users in this UserManager.
See Also:
createUser(java.lang.String), deleteUser(java.lang.String)

deleteUser

public User deleteUser(java.lang.String sName)
Delete a user from this UserManager.

The user will be removed from the UserManager and will no longer be available via getUser(java.lang.String). A userDeleted event will be received by all UserDataListeners registered with this UserManager if a user was removed. If no user with the given name existed no exception will be thrown and no event will be fired.

If the user is currently associated to some object, it will stay so until it is disassociated explicitly. It will not have the possibility to log in again, though.

Parameters:
sName - the name of the user to be removed
Returns:
the user that was just removed or null if none.
See Also:
UserDataListener.userDeleted(org.salespointframework.core.users.events.UserDataEvent)

addUserDataListener

public void addUserDataListener(UserDataListener udl)
Add a UserDataListener. UserDataListeners will receive an event whenever a user was created or removed.

Parameters:
udl - the UserDataListener to add.

removeUserDataListener

public void removeUserDataListener(UserDataListener udl)
Remove a UserDataListener.

Parameters:
udl - the UserDataListener to remove.

fireUserAdded

protected void fireUserAdded(User usr)
Fire a userAdded event to all interested listeners.

Parameters:
usr - the user that was added.

fireUserDataChanged

protected void fireUserDataChanged(User usr)
Fire userDataChanged event

Parameters:
usr - user which data changed

fireUserDeleted

protected void fireUserDeleted(User usr)
Fire a userDeleted event to all interested listeners.

Parameters:
usr - the user that was deleted.

logOn

public User logOn(java.lang.Object o,
                  User u)
Associate a user with an object.

Only one user at a time can be associated with one Object. If there is already another user associated with the given Object, its association is undone and the user is returned.

Only users that are actually managed by this UserManager can be logged in. An exception will be thrown if you try to log in a user that is unknown to this UserManager. Especially, this can happen if you try to log in a user that was previously removed using deleteUser(java.lang.String).

Parameters:
o - the Object with which to associate the user.
u - the user to associate with the Object
Returns:
the user that was previously associated with the Object or null if none.
Throws:
UnknownUserException - if the user to log in is not known at this UserManager. A user is known at a UserManager, if the User object is registered, i.e. no equals() method of any kind is called.
See Also:
User.loggedOn(java.lang.Object)

logOff

public User logOff(java.lang.Object o)
Disassociate the current user from an Object.

Parameters:
o - the Object from which to disassociate a user.
Returns:
the user just logged off or null if none.
See Also:
User.loggedOff(java.lang.Object)

getCurrentUser

public User getCurrentUser(java.lang.Object o)
Retrieve the user currently associated with some Object.

Parameters:
o - the Object with which the searched user must be associated.
Returns:
the user associated with the given Object or null if none.

getGlobalUM

@Deprecated
public static UserManager getGlobalUM()
Deprecated. 

Get the global UserManager. Use getInstance() instead

The global UserManager can be used as a centralized instance to manage all the users in an application.

Returns:
the global UserManager.

setGlobalUM

@Deprecated
public static UserManager setGlobalUM(UserManager umNew)
Deprecated. 

Set a new UserManager to be the global UserManager from now on. use setInstance(UserManager) instead

Parameters:
umNew - the new global UserManager.
Returns:
the previous UserManager.

setInstance

public static void setInstance(UserManager um)
Set the UserManager instance

Parameters:
um - The new UserManager

getInstance

public static UserManager getInstance()
Get the global UserManager instance

Returns:
The UserManager

DatasourceChanged

public void DatasourceChanged(boolean pumpUp)
the datasource changed

Specified by:
DatasourceChanged in interface DatasourceChangeListener
Parameters:
pumpUp - true if the event should be pumped up to hosts, because this event is mostly triggered twice. first time to invalidate caches. second time for load new data

DatasourceOnChange

public void DatasourceOnChange()
call users to free their resources

Specified by:
DatasourceOnChange in interface DatasourceOnChangeListener

externalModificationOccurred

public void externalModificationOccurred()
simulate DatasourceChanged(boolean) on external modification

Specified by:
externalModificationOccurred in interface ExternalModificationListener