org.enhydra.barracuda.core.util.data
Class ObjectRepository

java.lang.Object
  |
  +--org.enhydra.barracuda.core.util.data.DefaultStateMap
        |
        +--org.enhydra.barracuda.core.util.data.ObjectRepository
All Implemented Interfaces:
StateMap

public class ObjectRepository
extends DefaultStateMap

This class provides access to several different generic statemap repositories, scoped for Global, Session, Local, or custom (NameSpace or Name...you provide the cleanup). The basic idea here is to make it easy to access object repositories without having to pass references around. The Global object repository represents a common (threadsafe) statemap that is shared across the JVM. You would typically put things here like DataSources, global variables, etc. Any objects that you make available globally need to be threadsafe. The Session object repository is a statemap wrapper around HttpSession. This provides a convenient bridge to the Session interface, without having to have a reference to the HttpServletRequest. Storing items in this object places them in the underlying session. Note that ApplicationGateway and ComponentGateway classes invoke the setupSessionRepository() call for you, so all you have to do is call getSessionRepository() and you're in business. The Local object repository is a statemap object that lasts for the duration of a req-resp cycle. Note that the ApplicationGateway and ComponentGateway classes clean up both Session and Local repositories. You can also get non-scoped ObjectRepositories by using either NameSpace or String keys. IF you use this approach, its up to you to manually remove the repositories when you're done with them (or else you'll end up leaving them in memory taking up space).

Version:
1.0
Author:
Christian Cryder

Field Summary
protected static java.util.Map custom
           
protected static ObjectRepository global
           
protected static java.util.Map local
           
protected static org.apache.log4j.Logger logger
           
protected  java.lang.String name
           
protected static java.util.Map session
           
protected static java.util.Map weaksession
           
 
Fields inherited from class org.enhydra.barracuda.core.util.data.DefaultStateMap
props
 
Constructor Summary
protected ObjectRepository()
          protected constructor
protected ObjectRepository(java.lang.String iname)
           
 
Method Summary
static ObjectRepository getGlobalRepository()
          Get a reference to the Global repository.
static ObjectRepository getLocalRepository()
          Get a reference to the Local repository.
 java.lang.String getName()
          Return the name of this object repository
static ObjectRepository getObjectRepository(NameSpace ns)
          Get an object repository associated with a given NameSpace.
static ObjectRepository getObjectRepository(java.lang.String name)
          Get an object repository based on a given name.
static ObjectRepository getSessionRepository()
          Get a reference to the Session repository.
static ObjectRepository getWeakSessionRepository()
          Get a reference to a Weak Session repository.
static void removeLocalRepository()
          Release the Local repository.
static void removeObjectRepository(NameSpace ns)
          Release an object repository associated with a given NameSpace
static void removeObjectRepository(java.lang.String name)
          Release an object repository associated with a given name
static void removeSessionRepository()
          Release the Session repository
static void setupSessionRepository(javax.servlet.http.HttpServletRequest req)
          Set up the Session repository for this particular thread.
 
Methods inherited from class org.enhydra.barracuda.core.util.data.DefaultStateMap
getState, getStateKeys, getStateValues, putState, removeState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger

global

protected static ObjectRepository global

session

protected static java.util.Map session

weaksession

protected static java.util.Map weaksession

local

protected static java.util.Map local

custom

protected static java.util.Map custom

name

protected java.lang.String name
Constructor Detail

ObjectRepository

protected ObjectRepository()
protected constructor


ObjectRepository

protected ObjectRepository(java.lang.String iname)
Method Detail

getGlobalRepository

public static ObjectRepository getGlobalRepository()
Get a reference to the Global repository. This repository is shared across the entire JVM (consequently its threadsafe). The global repository never really goes away, so you don't need to do any cleanup on this one.


setupSessionRepository

public static void setupSessionRepository(javax.servlet.http.HttpServletRequest req)
Set up the Session repository for this particular thread. You must invoke this method before actually getting the session repository, IFF you actually want the repository to wrapp the Servlet's Session structure. Otherwise, when you get the Session repository (below) it will simply return a regular state map.


getSessionRepository

public static ObjectRepository getSessionRepository()
Get a reference to the Session repository. If you are using this within Barracuda (ie. ApplicationGateway or ComponentGateway), this will return a StateMap that wraps the Servlet session.


removeSessionRepository

public static void removeSessionRepository()
Release the Session repository


getWeakSessionRepository

public static ObjectRepository getWeakSessionRepository()
Get a reference to a Weak Session repository. Objects placed in here are scoped to Session, but may be reclaimed by garbage collecter as needed (so you must always check for null and reinitialize if necessary)


getLocalRepository

public static ObjectRepository getLocalRepository()
Get a reference to the Local repository. This repository is shared across the thread. If you use this repository, it is your responsibility to clean things up (unless something else is cleaning it up for you, like the Barracuda ApplicationGateway or ComponentGateway)


removeLocalRepository

public static void removeLocalRepository()
Release the Local repository.


getObjectRepository

public static ObjectRepository getObjectRepository(NameSpace ns)
Get an object repository associated with a given NameSpace. If the object repository for this namespace does not already exist, it will be created automatically.


removeObjectRepository

public static void removeObjectRepository(NameSpace ns)
Release an object repository associated with a given NameSpace


getObjectRepository

public static ObjectRepository getObjectRepository(java.lang.String name)
Get an object repository based on a given name. If the object repository for this namespace does not already exist, it will be created automatically.


removeObjectRepository

public static void removeObjectRepository(java.lang.String name)
Release an object repository associated with a given name


getName

public java.lang.String getName()
Return the name of this object repository



Copyright © 2001 Enhydra.org