amwebarsentitlementservice.session
Class Session

java.lang.Object
  |
  +--amwebarsentitlementservice.session.Session
All Implemented Interfaces:
java.lang.Cloneable, PoolElement

public class Session
extends java.lang.Object
implements PoolElement

A Session manages all AMWebARSClient of one getEntitlement request. It generates for each combination of AMWebARSProtocol and AMWebARSProvider required a AMWebARSClient. It distributes the container_type_ids that are to be retrieved to the different clients. The Session fulfills Single Instance by ID Pattern. The Session works in cooperation with a SessionTable. This table organizes the creation of the Sessions.


Field Summary
static boolean BOUND_NUMBER_OF_CLIENTS
           
static java.lang.String CLIENT_KEY_DELIMETER
           
static int MAX_NUMBER_OF_CLIENTS
           
 
Method Summary
 void addContainer(AMWebARSContainer container)
          Adds a retrieved container to this Session.
 void addContainerDescriptor(AMWebARSContainerDescriptor descriptor)
          Adds an AMWebARSContainerDescriptor to this Session.
 void addContainerTypeID(java.lang.String container_type_id)
          Adds an AMWebARSContainerDescriptor of an certain container_type_id to this Session.
 void addContainerTypeIDNotFound(java.lang.String container_type_id)
           
 void clear()
          Removed all container descriptors from the Session, but not the corresponding clients.
 void clear(boolean remove_clients)
          Removed all container descriptors from the Session.
 void clearInternalState()
           
 java.lang.Object clone()
           
 java.util.Enumeration containersNotFound()
           
 boolean containsClient(java.lang.String protocol_id, java.lang.String provider_id)
          Tests whether there is a client responsible for the work with a given protocol_id and provider_id.
 boolean containsContainerDescriptor(AMWebARSContainerDescriptor descriptor)
          Tests whether the Session contains a container descriptor.
 boolean containsContainerTypeID(java.lang.String container_type_id)
          Tests whether the Session contains a container descriptor of the given container type id.
 boolean equals(java.lang.Object other_object)
          Tests whether this Session is equal to another.
 java.util.Map getAppContext()
          Returns the app_context.
 AMWebARSClient getClient(java.lang.String protocol_id, java.lang.String provider_id)
          Returns the AMWebARSClient that is responsible for the work with a given protocol_id and provider_id.
 int getClientNumber()
          Returns the number of AMWebARSClients this Session contains.
 java.lang.String getContainersNotFoundString()
           
static Session getInstance(java.lang.String session_id)
          Returns the only instance of Session with this session_id.
 int getPoolIndex()
           
 java.net.URL getRequestUrl()
          Gets the request_url.
 java.lang.String getSessionID()
          Gets the session_id of this Session.
 Subject getSubject()
          Gets the subject.
 TimeInterval getValidityInterval()
          Gets the validity_time.
 boolean hasNoClients()
          Tests whether the Session contains no AMWebARSClients.
 boolean isContainersNotFoundEmpty()
           
 boolean isEmpty()
          Tests whether the Session contains no AMWebARSContainerDescriptors.
 boolean isValidAt(java.util.Date current_date)
          Tests whether the Session is still valid.
 boolean isValidAt(long current_date)
           
 AMWebARSContainerDescriptor removeContainerDescriptor(AMWebARSContainerDescriptor descriptor)
          Removes a AMWebARSContainerDescriptor from this Session.
 AMWebARSContainerDescriptor removeContainerTypeID(java.lang.String container_type_id)
          Removes a AMWebARSContainerDescriptor for a container_type_id from this Session.
 java.util.Enumeration retrievedContainers()
          returns an Enumeration of all retrieved Containers.
 SessionStatus run()
          Shows the session, that the adding of the container descriptors is completed and that the protocol runs can be started.
 void setAppContext(java.util.Map app_context)
          Sets the app_context.
 void setPoolIndex(int index)
           
 void setRequestUrl(java.net.URL request_url)
          Sets the request_url.
 void setSubject(Subject subject)
          Sets the subject.
 void setValidityInterval(TimeInterval validity_interval)
          Sets the validity_time.
 int size()
          Returns the number of AMWebARSContainerDescriptors this Session contains.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BOUND_NUMBER_OF_CLIENTS

public static final boolean BOUND_NUMBER_OF_CLIENTS

MAX_NUMBER_OF_CLIENTS

public static final int MAX_NUMBER_OF_CLIENTS

CLIENT_KEY_DELIMETER

public static final java.lang.String CLIENT_KEY_DELIMETER
Method Detail

getInstance

public static Session getInstance(java.lang.String session_id)
Returns the only instance of Session with this session_id. The method asks the session table for the corresponding Session and returns it.

clone

public java.lang.Object clone()
Specified by:
clone in interface PoolElement
Overrides:
clone in class java.lang.Object

getSessionID

public java.lang.String getSessionID()
Gets the session_id of this Session.
Returns:
Returns the String session_id of this Session.

getValidityInterval

public TimeInterval getValidityInterval()
Gets the validity_time.
Returns:
Returns a TimeInterval

setValidityInterval

public void setValidityInterval(TimeInterval validity_interval)
Sets the validity_time.
Parameters:
validity_time - The validity_time to set

isValidAt

public boolean isValidAt(java.util.Date current_date)
Tests whether the Session is still valid. The isValidAt method has to return false, if no validity_interval is set.
Parameters:
current_date - current Date
Returns:
boolean true, if the current_date is inside the validity time.
Throws:
NullPointerException - if null is given as parameter

isValidAt

public boolean isValidAt(long current_date)

addContainerDescriptor

public void addContainerDescriptor(AMWebARSContainerDescriptor descriptor)
                            throws java.lang.CloneNotSupportedException,
                                   java.util.NoSuchElementException
Adds an AMWebARSContainerDescriptor to this Session. The method looks for the AMWebARSClient that is responsible for that kind of container. If such a client doesn't exist, it generates a new one. The Session adds the AMWebARSContainerDescriptor to the client.
Parameters:
descriptor - AMWebARSContainerDescriptor to be added
Throws:
NullPointerException - is parameter is null
java.util.NoSuchElementException - if the you add a descriptor whose protocol_id or provider_id isn't in the corresponding table.
java.lang.CloneNotSupportedException - if a protocol doesn't support cloning.

addContainerTypeID

public void addContainerTypeID(java.lang.String container_type_id)
                        throws java.lang.CloneNotSupportedException,
                               java.util.NoSuchElementException
Adds an AMWebARSContainerDescriptor of an certain container_type_id to this Session. The method looks for the AMWebARSClient that is responsible for that kind of container. If such a client doesn't exist, it generates a new one. The Session adds the AMWebARSContainerDescriptor to the client.
Parameters:
container_type_id - of the conatiner descriptor to be added
Throws:
NullPointerException - is parameter is null
java.lang.CloneNotSupportedException - if a protocol doesn't support cloning.
java.util.NoSuchElementException - if the you add a descriptor whose protocol_id or provider_id isn't in the corresponding table.

removeContainerDescriptor

public AMWebARSContainerDescriptor removeContainerDescriptor(AMWebARSContainerDescriptor descriptor)
Removes a AMWebARSContainerDescriptor from this Session. The method looks for the AMWebARSClient which should contain the descriptor. It asks the client to remove the container descriptor.
Parameters:
descriptor - AMWebARSContainerDescriptor to be removed
Returns:
removed descriptor
Throws:
java.util.NoSuchElementException - if the descriptor wasn't found
NullPointerException - if the parameter is null

removeContainerTypeID

public AMWebARSContainerDescriptor removeContainerTypeID(java.lang.String container_type_id)
Removes a AMWebARSContainerDescriptor for a container_type_id from this Session. The method looks for the AMWebARSClient which should contain the descriptor. It asks the client to remove the container descriptor.
Parameters:
container_type_id - String type of the container descriptor to be removed
Returns:
removed descriptor
Throws:
java.util.NoSuchElementException - if the descriptor wasn't found
NullPointerException - if the parameter is null

containsContainerDescriptor

public boolean containsContainerDescriptor(AMWebARSContainerDescriptor descriptor)
Tests whether the Session contains a container descriptor. Tests whether a suitable client exits. If so, it tests whether the client contains the container descriptor.
Parameters:
descriptor - AMWebARSContainerDescriptor to be looked for.
Returns:
boolean true, if the descriptor is found.
Throws:
NullPointerException - if the parameter is null

containsContainerTypeID

public boolean containsContainerTypeID(java.lang.String container_type_id)
Tests whether the Session contains a container descriptor of the given container type id. Tests whether a suitable client exits. If so, it tests whether the client contains the container descriptor.
Parameters:
container_type_id - String typt of the container to be looked for.
Returns:
boolean true, if the descriptor is found.
Throws:
NullPointerException - if the parameter is null

getClient

public AMWebARSClient getClient(java.lang.String protocol_id,
                                java.lang.String provider_id)
                         throws java.util.NoSuchElementException
Returns the AMWebARSClient that is responsible for the work with a given protocol_id and provider_id. If it doesn't exit the method throws a NoSuchElementException.
Parameters:
protocol_id - String ID of the AMWebARSProtocol the client uses.
provider_id - String ID of the AMWebARSProvider the client communicates with.
Returns:
AMWebARSClient that is responsible for this combination
Throws:
java.util.NoSuchElementException - if the client isn't contained in the session.
NullPointerException - if one of the params is null.

containsClient

public boolean containsClient(java.lang.String protocol_id,
                              java.lang.String provider_id)
Tests whether there is a client responsible for the work with a given protocol_id and provider_id.
Parameters:
protocol_id - String ID of the AMWebARSProtocol the client uses.
provider_id - String ID of the AMWebARSProvider the client communicates with.
Returns:
true if a client for that combination exists
Throws:
NullPointerException - if one of the params is null.

size

public int size()
Returns the number of AMWebARSContainerDescriptors this Session contains. This is canonical because the Session behaves like a container for container descriptors.
Returns:
int number of container descriptors
See Also:
getClientNumber()

getClientNumber

public int getClientNumber()
Returns the number of AMWebARSClients this Session contains.
Returns:
int number of clients of this Session
See Also:
size()

isEmpty

public boolean isEmpty()
Tests whether the Session contains no AMWebARSContainerDescriptors.
Returns:
boolean true if the Session contains no container descriptors
See Also:
hasNoClients()

hasNoClients

public boolean hasNoClients()
Tests whether the Session contains no AMWebARSClients.
Returns:
boolean true if the Session contains no clients
See Also:
isEmpty()

clear

public void clear()
Removed all container descriptors from the Session, but not the corresponding clients.

clear

public void clear(boolean remove_clients)
Removed all container descriptors from the Session. If remove_clients is true remove the clients too.

clearInternalState

public void clearInternalState()
Specified by:
clearInternalState in interface PoolElement

setPoolIndex

public void setPoolIndex(int index)
Specified by:
setPoolIndex in interface PoolElement

getPoolIndex

public int getPoolIndex()
Specified by:
getPoolIndex in interface PoolElement

addContainer

public void addContainer(AMWebARSContainer container)
Adds a retrieved container to this Session.
Parameters:
container - to be added

retrievedContainers

public java.util.Enumeration retrievedContainers()
returns an Enumeration of all retrieved Containers.
Returns:
Enumeration of containers retrieved so far.

addContainerTypeIDNotFound

public void addContainerTypeIDNotFound(java.lang.String container_type_id)

containersNotFound

public java.util.Enumeration containersNotFound()

getContainersNotFoundString

public java.lang.String getContainersNotFoundString()

isContainersNotFoundEmpty

public boolean isContainersNotFoundEmpty()

getSubject

public Subject getSubject()
Gets the subject.
Returns:
Returns a Subject

setSubject

public void setSubject(Subject subject)
Sets the subject.
Parameters:
subject - The subject to set

getAppContext

public java.util.Map getAppContext()
Returns the app_context.
Returns:
Map

setAppContext

public void setAppContext(java.util.Map app_context)
Sets the app_context.
Parameters:
app_context - The app_context to set

getRequestUrl

public java.net.URL getRequestUrl()
Gets the request_url.
Returns:
Returns a URL

setRequestUrl

public void setRequestUrl(java.net.URL request_url)
Sets the request_url.
Parameters:
request_url - The request_url to set

run

public SessionStatus run()
Shows the session, that the adding of the container descriptors is completed and that the protocol runs can be started. The session calls the run() methods of the different clients.
Throws:
NullPointerException - if the subject isn't set.

equals

public boolean equals(java.lang.Object other_object)
Tests whether this Session is equal to another.
Overrides:
equals in class java.lang.Object
Returns:
boolean true if both obj are the same.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object