|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.iplanet.jato.ModelManager
A factory for the instantiation and retrieval of Model
objects
within a request. This class guarantees that only a single instance of a
requested model is created during each request. Models obtained via this
class are shared between all objects in the current request. This class
lazily instantiates objects as needed, but never creates more than one
instance of a given type with the same instance name.
Developers need not create any instances of this class. A single instance is automatically created at the beginning of the request and stored in the request context.
Some user-defined models may wish to remain stateful between user requests (none of the models provided with JATO are stateful). Therefore, this class is capable of automatically storing and retreiving models from the HTTP session. However, because storing objects in the session is performance overhead, we anticipate that most models will be instantiated on a per-request, as-needed basis. Regardless, the capability to store and retrieve model instances from the session is supported here.
This class anticipates that most of its callers will not supply an instance name
for a model, since in most requests a single instance of a given model is
sufficient. Therefore, when a client only requests a model by type and does not
supply a specific instance name, the manager returns an instance reserved for
instance nameless requests. The name used to store these models in the
ModelManager
can be obtained by calling the
getDefaultModelInstanceName()
method.
RequestContext
,
ModelTypeMap
,
Model
Constructor Summary | |
ModelManager(RequestContext requestContext,
ModelTypeMap typeMap)
|
Method Summary | |
void |
addToSession(Model model)
This method allows the caller to schedule the specified model for addition to the session. |
java.lang.String |
getDefaultModelInstanceName(java.lang.Class modelClass)
Returns the default model instance name for the given model interface class |
java.lang.String |
getDefaultModelInstanceName(java.lang.String modelClassName)
Returns the default model instance name for the given model interface class name |
Model |
getModel(java.lang.Class modelClass)
Returns a reference to the unnamed instance that implements the requested Model interface. |
Model |
getModel(java.lang.Class modelClass,
java.lang.String instanceName)
Returns a reference to the named instance that implements the requested Model interface. |
Model |
getModel(java.lang.Class modelClass,
java.lang.String instanceName,
boolean lookInSession)
Returns a reference to the named instance that implements the requested Model interface. |
Model |
getModel(java.lang.Class modelClass,
java.lang.String instanceName,
boolean lookInSession,
boolean storeInSession)
Returns a reference to the named instance that implements the requested Model interface. |
Model |
getModel(java.lang.String className)
Returns a reference to the unnamed instance that implements the requested Model interface |
Model |
getModel(java.lang.String className,
java.lang.String instanceName)
Returns a reference to the named instance that implements the requested Model interface. |
Model |
getModel(java.lang.String className,
java.lang.String instanceName,
boolean lookInSession)
Returns a reference to the named instance that implements the requested Model interface. |
Model |
getModel(java.lang.String className,
java.lang.String instanceName,
boolean lookInSession,
boolean storeInSession)
Returns a reference to the named instance that implements the requested Model interface. |
protected RequestContext |
getRequestContext()
Returns the request context |
void |
notifyRequestCompletionListeners()
Deprecated. Code that calls this method is no longer required and should be removed |
void |
removeFromSession(Model model)
This method allows the caller to schedule the specified model for immediate removal from the session. |
void |
requestComplete()
Called when the request is at an end. |
void |
setTypeMap(ModelTypeMap value)
Sets the current ModelTypeMap instance |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ModelManager(RequestContext requestContext, ModelTypeMap typeMap)
requestContext
- The request context of the current requesttypeMap
- An application-specific map that associates Model
interfaces with corresponding Model
implementation
classes.Method Detail |
protected RequestContext getRequestContext()
public Model getModel(java.lang.String className) throws java.lang.ClassNotFoundException
Model
interfaceclassName
- The Model
's interface or implementation class name.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.Model
instance that corresponds to the supplied
model class namepublic Model getModel(java.lang.String className, java.lang.String instanceName) throws java.lang.ClassNotFoundException
Model
interface.className
- The Model
's interface or implementation class name.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.instanceName
- The name of the requested instanceModel
instance that corresponds to the supplied
model class namepublic Model getModel(java.lang.String className, java.lang.String instanceName, boolean lookInSession) throws java.lang.ClassNotFoundException
Model
interface. If the caller requests that
the model be fetched from session but does not currrently exist
in session, the ModelManager
will create the instance
but will not store it in the session before returning the
reference to the caller.className
- The Model
's interface or implementation class name.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.instanceName
- The name of the requested instancelookInSession
- Directs the ModelManager
to look or not look into
the current user's HttpSession
for the named model
instance.Model
instance that corresponds to the supplied
model class namepublic Model getModel(java.lang.String className, java.lang.String instanceName, boolean lookInSession, boolean storeInSession) throws java.lang.ClassNotFoundException
Model
interface. If the caller requests that the
model be fetched from session but does not currrently exist in
session, the ModelManager
will create the instance, schedule
it for storage in the session if the value of the storeInSession
parameter is true
, and return the reference to the caller. The
model is stored in the session under its instance name.className
- The Model
's interface or implementation class name.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.instanceName
- The name of the requested instancelookInSession
- Directs the ModelManager
to look or not look into
the current user's HttpSession
for the named model
instance.storeInSession
- Directs the ModelManager
to schedule the model for
addition to the current user's HttpSession
under
the provided instance nameModel
instance that corresponds to the supplied
model class namepublic Model getModel(java.lang.Class modelClass)
Model
interface.modelClass
- The Model
's interface or implementation class name.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.Model
instance that corresponds to the supplied
model classpublic Model getModel(java.lang.Class modelClass, java.lang.String instanceName)
Model
interface.modelClass
- The Model
's interface or implementation class.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.instanceName
- The name of the requested instanceModel
instance that corresponds to the supplied
model classpublic Model getModel(java.lang.Class modelClass, java.lang.String instanceName, boolean lookInSession)
Model
interface. If the caller requests that the
model be fetched from session but does not currrently exist in
session, the ModelManager
will create the instance, schedule
it for storage in the session if the value of the storeInSession
parameter is true
, and return the reference to the caller. The
model is stored in the session under its instance name.modelClass
- The Model
's interface or implementation class.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.instanceName
- The name of the requested instancelookInSession
- Directs the ModelManager
to look or not look into
the current user's HttpSession
for the named model
instance.Model
instance that corresponds to the supplied
model classpublic Model getModel(java.lang.Class modelClass, java.lang.String instanceName, boolean lookInSession, boolean storeInSession)
Model
interface. If the caller requests that the
model be fetched from session but does not currrently exist in
session, the ModelManager
will create the instance, schedule
it for storage in the session if the value of the storeInSession
parameter is true
, and return the reference to the caller. The
model is stored in the session under its instance name.modelClass
- The Model
's interface or implementation class.
The ModelManager
initially assumes this class is a
model interface class and will attempt to map it to a class that
implements the specified interface using its ModelTypeMap
object. However, if no mapping is found, it assumes
the provided class is the model implementation class and
attempts to return an instance of that class.instanceName
- The name of the requested instancelookInSession
- Directs the ModelManager
to look or not look into
the current user's HttpSession
for the named model
instance.storeInSession
- Directs the ModelManager
to schedule the model for
addition to the current user's HttpSession
under
the provided instance nameModel
instance that corresponds to the supplied
model classpublic void addToSession(Model model)
Model.getName()
.model
- The model to store in session. The model must conform
the container's requirements for being added to
session. For example, it may need to be serializable.public void removeFromSession(Model model)
model
- The model to remove from session. It is assumed that the model
had been previously stored in session under the name
returned by Model.getName()
.public void setTypeMap(ModelTypeMap value)
ModelTypeMap
instancevalue
- The map that will be used to map model interfaces to
implementationspublic java.lang.String getDefaultModelInstanceName(java.lang.String modelClassName)
public java.lang.String getDefaultModelInstanceName(java.lang.Class modelClass)
public final void notifyRequestCompletionListeners()
public void requestComplete()
addToSession()
method with the model as a parameter.
Each model is added to the session using the value returned by
Model.getName()
method as the attribute key. If a model returns
null
from this method, it is added under the name returned by
the getDefaultModelInstanceName(Class)
method.
requestComplete
in interface RequestCompletionListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |