org.exoplatform.services.jcr.ext.common
Class SessionProvider

java.lang.Object
  extended by org.exoplatform.services.jcr.ext.common.SessionProvider
All Implemented Interfaces:
SessionLifecycleListener

public class SessionProvider
extends java.lang.Object
implements SessionLifecycleListener

Created by The eXo Platform SAS .
Provides JCR Session for client program. Usually it is per client thread object Session creates with Repository.login(..) method and then can be stored in some cache if neccessary.

SessionProvider guaranties multithreading use of close() and getSession() methods.
SessionLifecycleListener.onCloseSession() implementation also is synchronized.

To logout all cached Session use close() method.

SessionProvider instance can handle getSession(), getCurrentRepository(), setCurrentRepository(), getCurrentWorkspace(), setCurrentWorkspace() methods after close() method call.

Version:
$Id: SessionProvider.java 35186 2009-08-07 14:23:43Z pnedonosko $
Author:
Gennady Azarenkov

Field Summary
static java.lang.String SESSION_PROVIDER
          Constant for handlers.
 
Constructor Summary
SessionProvider(org.exoplatform.services.security.ConversationState userState)
          Creates SessionProvider for certain identity.
 
Method Summary
 void close()
          Logout all cached Sessions.
static SessionProvider createAnonimProvider()
          Helper for creating Anonymous session provider.
static SessionProvider createSystemProvider()
          Helper for creating System session provider.
 ManageableRepository getCurrentRepository()
          Return current Repository.
 java.lang.String getCurrentWorkspace()
          Return current Workspace.
 javax.jcr.Session getSession(java.lang.String workspaceName, ManageableRepository repository)
          Gets the session from internal cache or creates and caches new one.
 void onCloseSession(ExtendedSession session)
          
 void setCurrentRepository(ManageableRepository currentRepository)
          Set current Repository.
 void setCurrentWorkspace(java.lang.String currentWorkspace)
          Set current Workspace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_PROVIDER

public static final java.lang.String SESSION_PROVIDER
Constant for handlers.

See Also:
Constant Field Values
Constructor Detail

SessionProvider

public SessionProvider(org.exoplatform.services.security.ConversationState userState)
Creates SessionProvider for certain identity.

Parameters:
userState - ConversationState, existing user state
Method Detail

createSystemProvider

public static SessionProvider createSystemProvider()
Helper for creating System session provider.

Returns:
SessionProvider session provider

createAnonimProvider

public static SessionProvider createAnonimProvider()
Helper for creating Anonymous session provider.

Returns:
SessionProvider session provider

getSession

public javax.jcr.Session getSession(java.lang.String workspaceName,
                                    ManageableRepository repository)
                             throws javax.jcr.LoginException,
                                    javax.jcr.NoSuchWorkspaceException,
                                    javax.jcr.RepositoryException
Gets the session from internal cache or creates and caches new one.

Parameters:
workspaceName - workspace name
repository - ManageableRepository, repository instance
Returns:
session Session
Throws:
javax.jcr.LoginException - login error
javax.jcr.NoSuchWorkspaceException - if no workspace name is null
javax.jcr.RepositoryException - Repository error

close

public void close()
Logout all cached Sessions. Session will be removed from cache by the listener (this provider) via ExtendedSession.logout().


onCloseSession

public void onCloseSession(ExtendedSession session)

Specified by:
onCloseSession in interface SessionLifecycleListener

getCurrentRepository

public ManageableRepository getCurrentRepository()
Return current Repository.

Returns:
Repository

getCurrentWorkspace

public java.lang.String getCurrentWorkspace()
Return current Workspace.

Returns:
Workspace

setCurrentRepository

public void setCurrentRepository(ManageableRepository currentRepository)
Set current Repository.

Parameters:
currentRepository - ManageableRepository

setCurrentWorkspace

public void setCurrentWorkspace(java.lang.String currentWorkspace)
Set current Workspace.

Parameters:
currentWorkspace - String


Copyright © 2011 eXo Platform SAS. All Rights Reserved.