|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.salespointframework.core.users.UserManager
public class UserManager
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.
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 |
---|
private java.util.Map<java.lang.String,User> m_mpUsers
The user's name is being used as the key. The user itself is being stored as the value.
User
private java.util.Map<java.lang.Object,User> m_mpCurrentUsers
The key of the map is the object to which a given user is associated. The user itself is being stored as the value.
User
,
logOn(java.lang.Object, org.salespointframework.core.users.User)
private java.util.Map<java.lang.String,Capability> m_mpDefaultCaps
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.
setDefaultCaps(java.util.Map)
,
Capability
,
User.setCapabilities(java.util.Map)
private UserCreator m_ucCreator
createUser(java.lang.String)
,
setUserCreator(org.salespointframework.core.users.UserCreator)
,
User
protected ListenerHelper m_lhListeners
private static UserManager s_umGlobal
Constructor Detail |
---|
public UserManager()
setDefaultCaps(java.util.Map)
,
createUser(java.lang.String)
public UserManager(java.util.Map<java.lang.String,Capability> mpDefaultCaps)
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.setDefaultCaps(java.util.Map)
,
createUser(java.lang.String)
,
Capability
public UserManager(UserCreator ucCreator)
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.setDefaultCaps(java.util.Map)
,
createUser(java.lang.String)
public UserManager(java.util.Map<java.lang.String,Capability> mpDefaultCaps, UserCreator ucCreator)
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.setDefaultCaps(java.util.Map)
,
Capability
,
createUser(java.lang.String)
,
User
Method Detail |
---|
public void setUserCreator(UserCreator ucCreator)
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.createUser(java.lang.String)
,
User
public void setDefaultCaps(java.util.Map<java.lang.String,Capability> mpDefaultCaps)
Calling this method will not influence the capabilities of users already created.
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.createUser(java.lang.String)
,
Capability
public void setDefaultCapability(Capability cap)
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.
cap
- the capability to be set as a default capability.createUser(java.lang.String)
public User createUser(java.lang.String sName)
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
.
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.
DuplicateUserException
- if there already was a user with the given name.setDefaultCaps(java.util.Map)
,
setUserCreator(org.salespointframework.core.users.UserCreator)
,
User
,
UserCreator.createUser(java.lang.String)
,
UserDataListener.userAdded(org.salespointframework.core.users.events.UserDataEvent)
public void addUser(User usr)
A userAdded
event will be received by any UserDataListener
that
registered an interest in this UserManager.
usr
- the user to be added.
DuplicateUserException
- if there already is a user of the same name.UserDataListener.userAdded(org.salespointframework.core.users.events.UserDataEvent)
public User getUser(java.lang.String sName)
If no user with the given name exists, this method will return null
.
sName
- the name of the user looked for.
null
will
be returned if no such user can be found.createUser(java.lang.String)
public java.util.Set<java.lang.String> getUserNames()
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.
createUser(java.lang.String)
,
deleteUser(java.lang.String)
public java.util.Collection<User> getUsers()
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.
createUser(java.lang.String)
,
deleteUser(java.lang.String)
public User deleteUser(java.lang.String sName)
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.
sName
- the name of the user to be removed
null
if none.UserDataListener.userDeleted(org.salespointframework.core.users.events.UserDataEvent)
public void addUserDataListener(UserDataListener udl)
udl
- the UserDataListener to add.public void removeUserDataListener(UserDataListener udl)
udl
- the UserDataListener to remove.protected void fireUserAdded(User usr)
userAdded
event to all interested listeners.
usr
- the user that was added.protected void fireUserDataChanged(User usr)
usr
- user which data changedprotected void fireUserDeleted(User usr)
userDeleted
event to all interested listeners.
usr
- the user that was deleted.public User logOn(java.lang.Object o, User u)
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)
.
o
- the Object with which to associate the user.u
- the user to associate with the Object
null
if none.
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.User.loggedOn(java.lang.Object)
public User logOff(java.lang.Object o)
o
- the Object from which to disassociate a user.
null
if none.User.loggedOff(java.lang.Object)
public User getCurrentUser(java.lang.Object o)
o
- the Object with which the searched user must be associated.
null
if none.@Deprecated public static UserManager getGlobalUM()
getInstance()
instead
The global UserManager can be used as a centralized instance to manage all the users in an application.
@Deprecated public static UserManager setGlobalUM(UserManager umNew)
setInstance(UserManager)
instead
umNew
- the new global UserManager.
public static void setInstance(UserManager um)
um
- The new UserManagerpublic static UserManager getInstance()
public void DatasourceChanged(boolean pumpUp)
DatasourceChanged
in interface DatasourceChangeListener
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 datapublic void DatasourceOnChange()
DatasourceOnChange
in interface DatasourceOnChangeListener
public void externalModificationOccurred()
DatasourceChanged(boolean)
on external modification
externalModificationOccurred
in interface ExternalModificationListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |