ikrs.util.session
Class AbstractSession<K,V,U>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by ikrs.util.MapDelegation<K,V>
          extended by ikrs.util.EnvironmentDelegation<K,V>
              extended by ikrs.util.session.AbstractSession<K,V,U>
All Implemented Interfaces:
Environment<K,V>, Session<K,V,U>, java.util.Map<K,V>
Direct Known Subclasses:
DefaultSession

public abstract class AbstractSession<K,V,U>
extends EnvironmentDelegation<K,V>
implements Session<K,V,U>

A simple session interface. Basically a session is nothing more than a named environment that is bound to a specific system user (remote or local). Each session is identified by its unique session ID.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 java.util.UUID sessionID
          The session's ID (must not be null and must never change).
 
Constructor Summary
AbstractSession(U userID, Environment<K,V> environment)
          Creates a new AbstractSession.
AbstractSession(U userID, EnvironmentFactory<K,V> environmentFactory)
          Creates a new AbstractSession.
 
Method Summary
 boolean allowsMultipleChildNames()
          This method indicates if the environment allows multiple names for child environments.
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 Environment<K,V> createChild(java.lang.String name)
          This method creates a new child environment and returns it.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
           
 boolean equals(java.lang.Object o)
           
 V get(java.lang.Object key)
           
 java.util.List<Environment<K,V>> getAllChildren()
          This method simply returns a list containing _all_ children.
 Environment<K,V> getChild(java.lang.String name)
          Get the child environment with the given name; there might be different children with the same name! The method will return the first match then.
 int getChildCount()
          This method returns the number of all children.
 java.util.List<Environment<K,V>> getChildren(java.lang.String name)
          Get *all* children with the given name.
 java.util.Date getCreationTime()
          This method return the date/time of the session's creation.
 java.util.Date getLastAccessTime()
          This method returns the date/time of the last read OR write access to this session.
 java.util.Date getLastModified()
          This method returns the date/time of the last write access to this session.
 Environment<K,V> getParent()
          Get the environments parent.
 java.util.UUID getSessionID()
          Get the session's unique ID.
 U getUserID()
          Get the session's user ID.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set<K> keySet()
           
 V put(K key, V value)
           
 void putAll(java.util.Map<? extends K,? extends V> m)
           
 V remove(java.lang.Object key)
           
 Environment<K,V> removeChild(java.lang.String name)
          This method removes the child with the given name and returns its old value.
 int size()
           
 java.lang.String toString()
           
 java.lang.StringBuffer toString(java.lang.StringBuffer b)
           
 java.util.Collection<V> values()
           
 
Methods inherited from class ikrs.util.EnvironmentDelegation
locateChild, removeAllChildren
 
Methods inherited from class java.util.AbstractMap
clone
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ikrs.util.Environment
locateChild, removeAllChildren
 

Field Detail

sessionID

public java.util.UUID sessionID
The session's ID (must not be null and must never change).

Constructor Detail

AbstractSession

public AbstractSession(U userID,
                       EnvironmentFactory<K,V> environmentFactory)
                throws java.lang.NullPointerException
Creates a new AbstractSession.

Parameters:
userID - The session's user ID.
environment - A factory to create the base environment to use.
Throws:
java.lang.NullPointerException - If the userID or the environment factory are null.

AbstractSession

public AbstractSession(U userID,
                       Environment<K,V> environment)
                throws java.lang.NullPointerException
Creates a new AbstractSession.

Parameters:
userID - The session's user ID.
environment - The base environment to use.
Throws:
java.lang.NullPointerException - If the userID or the environment factory are null.
Method Detail

getSessionID

public java.util.UUID getSessionID()
Get the session's unique ID. The returned ID must never be null and it must never change.

Specified by:
getSessionID in interface Session<K,V,U>
Returns:
The session's ID.

getUserID

public U getUserID()
Get the session's user ID. The user ID must not be null and must not change.

Specified by:
getUserID in interface Session<K,V,U>
Returns:
The session's user ID.

getCreationTime

public java.util.Date getCreationTime()
This method return the date/time of the session's creation.

Specified by:
getCreationTime in interface Session<K,V,U>
Returns:
The date/time of the session's creation.

getLastModified

public java.util.Date getLastModified()
This method returns the date/time of the last write access to this session.

Specified by:
getLastModified in interface Session<K,V,U>
Returns:
The date/time of the last write access to this session.

getLastAccessTime

public java.util.Date getLastAccessTime()
This method returns the date/time of the last read OR write access to this session.

Specified by:
getLastAccessTime in interface Session<K,V,U>
Returns:
The date/time of the last read OR write access to this session.

allowsMultipleChildNames

public boolean allowsMultipleChildNames()
This method indicates if the environment allows multiple names for child environments. If this method returns false the method createChild MUST NOT create a new child if there already exists a child with that name.

Specified by:
allowsMultipleChildNames in interface Environment<K,V>
Overrides:
allowsMultipleChildNames in class EnvironmentDelegation<K,V>

getParent

public Environment<K,V> getParent()
Get the environments parent. If there is no parent the method will return null. Only the root environment has not parent. *

Specified by:
getParent in interface Environment<K,V>
Overrides:
getParent in class EnvironmentDelegation<K,V>

getChild

public Environment<K,V> getChild(java.lang.String name)
Get the child environment with the given name; there might be different children with the same name! The method will return the first match then. If no such child exists the method returns null.

Specified by:
getChild in interface Environment<K,V>
Overrides:
getChild in class EnvironmentDelegation<K,V>
Parameters:
name - The child's name (if the child search is case sensitive depends on the actual implementation).
See Also:
DefaultEnvironment

getAllChildren

public java.util.List<Environment<K,V>> getAllChildren()
This method simply returns a list containing _all_ children.

Specified by:
getAllChildren in interface Environment<K,V>
Overrides:
getAllChildren in class EnvironmentDelegation<K,V>

getChildren

public java.util.List<Environment<K,V>> getChildren(java.lang.String name)
Get *all* children with the given name.

Specified by:
getChildren in interface Environment<K,V>
Overrides:
getChildren in class EnvironmentDelegation<K,V>
Parameters:
name - The child's name (if the child search is case sensitive depends on the actual implementation).
See Also:
DefaultEnvironment

createChild

public Environment<K,V> createChild(java.lang.String name)
This method creates a new child environment and returns it. Note A: if allowsMultipleChildNames() returns true, this method always creates a new child. Note B: if allowsMultipleChildNames() returns false, and if a child with the given name already exists there will be no modifications to the environment. In this case the method return the old child.

Specified by:
createChild in interface Environment<K,V>
Overrides:
createChild in class EnvironmentDelegation<K,V>
Parameters:
name - The child's name.

removeChild

public Environment<K,V> removeChild(java.lang.String name)
This method removes the child with the given name and returns its old value. If no such child can be found the method returns null. *

Specified by:
removeChild in interface Environment<K,V>
Overrides:
removeChild in class EnvironmentDelegation<K,V>
Parameters:
name - The child's name.

getChildCount

public int getChildCount()
This method returns the number of all children.

Specified by:
getChildCount in interface Environment<K,V>
Overrides:
getChildCount in class EnvironmentDelegation<K,V>

clear

public void clear()
Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class MapDelegation<K,V>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<K,V>
Overrides:
containsKey in class java.util.AbstractMap<K,V>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<K,V>
Overrides:
containsValue in class java.util.AbstractMap<K,V>

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,V>
Overrides:
entrySet in class MapDelegation<K,V>

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map<K,V>
Overrides:
equals in class java.util.AbstractMap<K,V>

get

public V get(java.lang.Object key)
Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.AbstractMap<K,V>

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map<K,V>
Overrides:
hashCode in class java.util.AbstractMap<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<K,V>
Overrides:
isEmpty in class java.util.AbstractMap<K,V>

keySet

public java.util.Set<K> keySet()
Specified by:
keySet in interface java.util.Map<K,V>
Overrides:
keySet in class java.util.AbstractMap<K,V>

put

public V put(K key,
             V value)
Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class MapDelegation<K,V>

putAll

public void putAll(java.util.Map<? extends K,? extends V> m)
Specified by:
putAll in interface java.util.Map<K,V>
Overrides:
putAll in class MapDelegation<K,V>

remove

public V remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<K,V>
Overrides:
remove in class MapDelegation<K,V>

size

public int size()
Specified by:
size in interface java.util.Map<K,V>
Overrides:
size in class java.util.AbstractMap<K,V>

values

public java.util.Collection<V> values()
Specified by:
values in interface java.util.Map<K,V>
Overrides:
values in class java.util.AbstractMap<K,V>

toString

public java.lang.String toString()
Overrides:
toString in class MapDelegation<K,V>

toString

public java.lang.StringBuffer toString(java.lang.StringBuffer b)