|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sas.framework.expojo.ModelExposer
public class ModelExposer
Central class for implementing the "Exposed Model" pattern. Supports the 'availability' of the ModelExposer to all objects in a thread via attachment to the thread ie., dependency injection. In most scenarios threads are shared resources (eg., servlet environment) and so should not be permanently attached to a ModelExposer. attachThread and detachThread are provided and work with the ThreadLocal attribute to provide almost 'singleton' like (without the bad bits) access to the model exposer from within a thread that has been attached. No automatic attachment/detachment takes place in the constructor, init or destroy methods because no assumptions are made that these methods are running in the thread that is the one that should be attached to the ModelExposer. Typically in a web app environment the developer will configure the ExpojoServletFilter in web.xml and this will perform the dependency injection automatically. See web/web.xml for an example web.xml file that configures the ExpojoServletContextListener and ExpojoServletFilter for a typical web application.
ExpojoServletContextListener,
ExpojoServletFilter| Field Summary | |
|---|---|
PersistenceProvider |
persistenceProvider
|
PersistenceProviderFactory |
persistenceProviderFactory
|
java.util.Hashtable |
repositories
|
java.util.Hashtable |
services
|
protected boolean |
traceTxDepth
If true dumps information about the transaction depth each time begin, commit or rollback are called. |
| Constructor Summary | |
|---|---|
ModelExposer(PersistenceProviderFactory iPersistenceProviderFactory)
Constructs the object, passing in the persistence provider factory shared by all model exposers accessing a particular datastore. |
|
| Method Summary | |
|---|---|
void |
addRepository(RepositoryComponent repositoryComponent)
Adds a service component to the model exposer. |
void |
addService(ServiceComponent serviceComponent)
Adds a service component to the model exposer. |
void |
attachThread()
Implements Dependency Injection: Attaches this ModelExposer to the current thread. |
void |
destroy()
Destroys this thread's model exposer instance by setting it's ThreadLocal value instance to null. |
void |
detachThread()
Detaches a ModelExposer from the current thread - enabling it to be garbage collected if necessary (assuming ThreadLocal had the last remaining reference to the ModelExposer). |
protected void |
finalize()
Calls to destroy the ModelExposer. |
static ModelExposer |
get()
Returns the ModelExposer for the current thread. |
PersistenceProvider |
getPersistenceProvider()
Returns a ThreadLocal version of the appropriate PersistenceProvider. |
RepositoryComponent |
getRepository(java.lang.String repositoryName)
Returns a repository of the given name or null if not found. |
ServiceComponent |
getService(java.lang.String serviceName)
Returns the service of the given name or null if not found. |
boolean |
getTraceTxDepth()
Returns traceTxDepth |
void |
init()
This should be called after construction to allow initialization of the exposer components that have been added. |
boolean |
isTestDb()
Returns testDb |
void |
setTraceTxDepth(boolean traceTxDepth)
Sets traceTxDepth |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected transient boolean traceTxDepth
public PersistenceProvider persistenceProvider
public transient java.util.Hashtable services
public transient java.util.Hashtable repositories
public transient PersistenceProviderFactory persistenceProviderFactory
| Constructor Detail |
|---|
public ModelExposer(PersistenceProviderFactory iPersistenceProviderFactory)
| Method Detail |
|---|
public void setTraceTxDepth(boolean traceTxDepth)
public boolean getTraceTxDepth()
public void attachThread()
public void detachThread()
protected void finalize()
finalize in class java.lang.Objectpublic boolean isTestDb()
public void init()
public PersistenceProvider getPersistenceProvider()
public RepositoryComponent getRepository(java.lang.String repositoryName)
public ServiceComponent getService(java.lang.String serviceName)
public static ModelExposer get()
public void destroy()
public void addService(ServiceComponent serviceComponent)
public void addRepository(RepositoryComponent repositoryComponent)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||