org.nakedobjects.runtime.context
Class NakedObjectsContext

java.lang.Object
  extended by org.nakedobjects.runtime.context.NakedObjectsContext
All Implemented Interfaces:
DebugInfo
Direct Known Subclasses:
NakedObjectsContextMultiUser, NakedObjectsContextStatic

public abstract class NakedObjectsContext
extends java.lang.Object
implements DebugInfo

Provides singleton access to the current (session scoped) NakedObjectSession, along with convenience methods to obtain application-scoped components and also any transaction-scoped components TransactionScopedComponents if a NakedObjectTransaction is in progress.

Somewhat analogous to (the static methods in) HibernateUtil.


Nested Class Summary
protected static class NakedObjectsContext.ContextReplacePolicy
          Whether the singleton itself may be replaced.
protected static class NakedObjectsContext.SessionClosePolicy
           
 
Constructor Summary
protected NakedObjectsContext(NakedObjectsContext.ContextReplacePolicy replacePolicy, NakedObjectsContext.SessionClosePolicy sessionClosePolicy, NakedObjectSessionFactory sessionFactory)
          Creates a new instance of the NakedObjectSession holder.
 
Method Summary
abstract  java.lang.String[] allSessionIds()
          All known session Ids.
protected  void applySessionClosePolicy()
          Helper method for subclasses' implementation of openSessionInstance(AuthenticationSession).
static void closeAllSessions()
          Convenience method to close all sessions.
protected abstract  void closeAllSessionsInstance()
          Shutdown the application.
static void closeSession()
          Convenience method to close the current NakedObjectSession.
 void closeSessionInstance()
          Closes the NakedObjectSession for the current context.
 void debugData(DebugString debug)
           
static DebugInfo[] debugSession()
           
static DebugInfo[] debugSystem()
           
protected  void doClose()
          Overridable hook method called from closeSessionInstance(), allowing subclasses to clean up (for example datastructures).
static boolean exists()
          Whether a singleton has been created using getInstance().
static AuthenticationManager getAuthenticationManager()
          Convenience method.
static AuthenticationSession getAuthenticationSession()
           
static AuthorizationManager getAuthorizationManager()
          Convenience method.
static NakedObjectConfiguration getConfiguration()
          Convenience method.
static NakedObjectTransaction getCurrentTransaction()
          Convenience method, returning the current transaction (if any).
static DeploymentType getDeploymentType()
          Convenience method.
static NakedObjectsContext getInstance()
          Returns the singleton providing access to the set of execution contexts.
static MessageBroker getMessageBroker()
          Convenience method, returning the MessageBroker of the current transaction.
static PersistenceSession getPersistenceSession()
          Convenience method.
static java.util.List<java.lang.Object> getServices()
           
static NakedObjectSession getSession()
          Convenience method returning the current NakedObjectSession.
static NakedObjectSession getSession(java.lang.String sessionId)
          Convenience method to return NakedObjectSession for specified NakedObjectSession.getId().
static NakedObjectSessionFactory getSessionFactory()
          Convenience method returning the NakedObjectSessionFactory of the current session.
 NakedObjectSessionFactory getSessionFactoryInstance()
          As injected in constructor.
static java.lang.String getSessionId()
          Convenience method to return the current NakedObjectSession's id.
abstract  NakedObjectSession getSessionInstance()
          Locates the current NakedObjectSession.
protected abstract  NakedObjectSession getSessionInstance(java.lang.String sessionId)
          The NakedObjectSession for specified NakedObjectSession.getId().
static SpecificationLoader getSpecificationLoader()
          Convenience method.
static TemplateImageLoader getTemplateImageLoader()
          Convenience method.
static NakedObjectTransactionManager getTransactionManager()
          Convenience methods
static UpdateNotifier getUpdateNotifier()
          Convenience method, returning the UpdateNotifier of the current transaction.
static UserProfile getUserProfile()
          Convenience method.
static UserProfileLoader getUserProfileLoader()
           
static boolean inSession()
           
static boolean inTransaction()
           
 boolean isContextReplaceable()
          Whether a context singleton can simply be replaced or not.
 boolean isSessionAutocloseable()
          Whether any open session can be automatically closed on open.
static NakedObjectSession openSession(AuthenticationSession authenticationSession)
          Convenience method to open a new NakedObjectSession.
abstract  NakedObjectSession openSessionInstance(AuthenticationSession session)
          Creates a new NakedObjectSession and binds into the current context.
static void setConfiguration(NakedObjectConfiguration configuration)
           
static void testReset()
          Resets the singleton, so another can created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nakedobjects.metamodel.commons.debug.DebugInfo
debugTitle
 

Constructor Detail

NakedObjectsContext

protected NakedObjectsContext(NakedObjectsContext.ContextReplacePolicy replacePolicy,
                              NakedObjectsContext.SessionClosePolicy sessionClosePolicy,
                              NakedObjectSessionFactory sessionFactory)
Creates a new instance of the NakedObjectSession holder.

Will throw an exception if an instance has already been created and is not NakedObjectsContext.ContextReplacePolicy.REPLACEABLE.

Method Detail

getInstance

public static NakedObjectsContext getInstance()
Returns the singleton providing access to the set of execution contexts.


exists

public static boolean exists()
Whether a singleton has been created using getInstance().


testReset

public static void testReset()
Resets the singleton, so another can created.

See Also:
#NakedObjects()

getSessionFactoryInstance

public final NakedObjectSessionFactory getSessionFactoryInstance()
As injected in constructor.


isContextReplaceable

public final boolean isContextReplaceable()
Whether a context singleton can simply be replaced or not.


isSessionAutocloseable

public final boolean isSessionAutocloseable()
Whether any open session can be automatically closed on open.


applySessionClosePolicy

protected void applySessionClosePolicy()
Helper method for subclasses' implementation of openSessionInstance(AuthenticationSession).


openSessionInstance

public abstract NakedObjectSession openSessionInstance(AuthenticationSession session)
Creates a new NakedObjectSession and binds into the current context.

Throws:
java.lang.IllegalStateException - if already opened.

closeSessionInstance

public final void closeSessionInstance()
Closes the NakedObjectSession for the current context.

Ignored if already closed.


doClose

protected void doClose()
Overridable hook method called from closeSessionInstance(), allowing subclasses to clean up (for example datastructures).

The current NakedObjectSession will already have been closed.


closeAllSessionsInstance

protected abstract void closeAllSessionsInstance()
Shutdown the application.


getSessionInstance

public abstract NakedObjectSession getSessionInstance()
Locates the current NakedObjectSession.

This might just be a singleton (eg NakedObjectsContextStatic), or could be retrieved from the thread (eg NakedObjectsContextThreadLocal).


getSessionInstance

protected abstract NakedObjectSession getSessionInstance(java.lang.String sessionId)
The NakedObjectSession for specified NakedObjectSession.getId().


allSessionIds

public abstract java.lang.String[] allSessionIds()
All known session Ids.

Provided primarily for debugging.


openSession

public static NakedObjectSession openSession(AuthenticationSession authenticationSession)
Convenience method to open a new NakedObjectSession.

See Also:
openSessionInstance(AuthenticationSession)

closeSession

public static void closeSession()
Convenience method to close the current NakedObjectSession.

See Also:
closeSessionInstance()

getSession

public static NakedObjectSession getSession(java.lang.String sessionId)
Convenience method to return NakedObjectSession for specified NakedObjectSession.getId().

Provided primarily for debugging.

See Also:
getSessionInstance(String)

closeAllSessions

public static void closeAllSessions()
Convenience method to close all sessions.


getSessionFactory

public static NakedObjectSessionFactory getSessionFactory()
Convenience method returning the NakedObjectSessionFactory of the current session.


getConfiguration

public static NakedObjectConfiguration getConfiguration()
Convenience method.

See Also:
NakedObjectSessionFactory.getConfiguration()

setConfiguration

public static void setConfiguration(NakedObjectConfiguration configuration)

getDeploymentType

public static DeploymentType getDeploymentType()
Convenience method.

See Also:
NakedObjectSessionFactory.getDeploymentType()

getSpecificationLoader

public static SpecificationLoader getSpecificationLoader()
Convenience method.

See Also:
NakedObjectSessionFactory.getSpecificationLoader()

getAuthenticationManager

public static AuthenticationManager getAuthenticationManager()
Convenience method.

See Also:
NakedObjectSessionFactory.getAuthenticationManager()

getAuthorizationManager

public static AuthorizationManager getAuthorizationManager()
Convenience method.

See Also:
NakedObjectSessionFactory.getAuthorizationManager()

getTemplateImageLoader

public static TemplateImageLoader getTemplateImageLoader()
Convenience method.

See Also:
NakedObjectSessionFactory.getTemplateImageLoader()

getUserProfileLoader

public static UserProfileLoader getUserProfileLoader()

getServices

public static java.util.List<java.lang.Object> getServices()

inSession

public static boolean inSession()

getSession

public static NakedObjectSession getSession()
Convenience method returning the current NakedObjectSession.


getSessionId

public static java.lang.String getSessionId()
Convenience method to return the current NakedObjectSession's id.

See Also:
NakedObjectSession.getId()

getAuthenticationSession

public static AuthenticationSession getAuthenticationSession()
See Also:
NakedObjectSession.getAuthenticationSession()

getPersistenceSession

public static PersistenceSession getPersistenceSession()
Convenience method.

See Also:
NakedObjectSession.getPersistenceSession()

getUserProfile

public static UserProfile getUserProfile()
Convenience method.

See Also:
NakedObjectSession.getUserProfile()

getTransactionManager

public static NakedObjectTransactionManager getTransactionManager()
Convenience methods

See Also:
NakedObjectSession.getPersistenceSession(), PersistenceSession.getTransactionManager()

inTransaction

public static boolean inTransaction()

getCurrentTransaction

public static NakedObjectTransaction getCurrentTransaction()
Convenience method, returning the current transaction (if any).

Transactions are managed using the NakedObjectTransactionManager obtainable from the NakedObjectSession's PersistenceSession.

See Also:
NakedObjectSession.getCurrentTransaction(), PersistenceSession.getTransactionManager()

getMessageBroker

public static MessageBroker getMessageBroker()
Convenience method, returning the MessageBroker of the current transaction.


getUpdateNotifier

public static UpdateNotifier getUpdateNotifier()
Convenience method, returning the UpdateNotifier of the current transaction.


debugSystem

public static DebugInfo[] debugSystem()

debugSession

public static DebugInfo[] debugSession()

debugData

public void debugData(DebugString debug)
Specified by:
debugData in interface DebugInfo


Copyright © 2001-2009 Naked Objects Group Ltd.. All Rights Reserved.