simple.http.session
Class ReflectionStore

java.lang.Object
  extended by simple.http.session.ReflectionStore
All Implemented Interfaces:
Store

public abstract class ReflectionStore
extends java.lang.Object
implements Store

The ReflectionStore enables initialization to be achieved using arbitrary prepare methods. This will attempt to discover the prepare method implemented by the subclass before invoking it. The discovery is done using Java reflection to match the arguments to the prepare method. For example take the prepare signatures illustrated below.


    public void prepare(Map) throws Exception
    public void prepare(List, String) throws Exception

 
The above methods will be discovered by checking the class of the Object parameter that is issued to the ReflectionStore.prepare(Object) method. The class of the object is determined using getClass. If the parameter to the subclasses prepare is the same class, a superinterface, or a superclass of that class then it will be invoked to initialize that instance.

This treats only a type of Object[] as a special case. If the object parameter is an array of objects then the discovery of the initialization method is performed by matching the method with the class type of each of the individual Object.getClass classes extracted from the array. So if both prepare methods illustrated above were implemented by a single subclass, then to invoke the prepare(List, String) method, use the follwing.


    Object data = new Object[]{new Vector(), "text"};

 
This allows the Store implementation to have several prepare methods and, depending on the type of the issued parameter, have the appropriate method to be invoked when it is loaded by the Manager.

Author:
Niall Gallagher
See Also:
Introspector

Field Summary
protected  Cookie cookie
          This is the cookie that is used to identify the session.
 
Constructor Summary
ReflectionStore(Cookie cookie)
          Constructor for the ReflectionStore.
 
Method Summary
 void prepare(java.lang.Object data)
          This method is used as a driver to the prepare method implemented by the subclass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface simple.http.session.Store
contains, destroy, get, keySet, put, remove
 

Field Detail

cookie

protected Cookie cookie
This is the cookie that is used to identify the session.

Constructor Detail

ReflectionStore

public ReflectionStore(Cookie cookie)
Constructor for the ReflectionStore. This is used to create a store that can have an arbitrary prepare method. This will be used by a Manager to create an instance using the session Cookie.

Parameters:
cookie - this is the session reference cookie
Method Detail

prepare

public void prepare(java.lang.Object data)
             throws StoreException
This method is used as a driver to the prepare method implemented by the subclass. The selection of the prepare method is determined by the class of the issued object, using Object.getClass. This discovers the method using the class and its subclasses.

Specified by:
prepare in interface Store
Parameters:
data - this object's class determines the preparation
Throws:
StoreException - thrown if preparation method fails