com.webmethods.caf.jcr.faces.bean
Class RepositorySessionManager

java.lang.Object
  extended by com.webmethods.caf.faces.bean.BaseFacesBean
      extended by com.webmethods.caf.faces.bean.BaseFacesSessionBean
          extended by com.webmethods.caf.jcr.faces.bean.RepositorySessionManager
All Implemented Interfaces:
IPageFlowScopeAdapter

public class RepositorySessionManager
extends BaseFacesSessionBean

Wrapper around a JCR session that takes care of cleaning up when the http session is invalidated. Also exposes a few JCR session methods in a JSF friendly way.

Since:
8.0

Field Summary
protected  Credentials fCredentials
          Holds reference to the user credentials.
protected  Session fCurrentSession
          Holds the current JCR session
protected  String fImpersonatedUser
          Holds the id of the impersonated user
protected  Repository fRepository
          Holds reference to the JCR Repository
protected  String fRepositoryJNDIName
          Holds the JNDI name to get a reference to the Repository
protected  String fWorkspaceName
          Holds the current workspace name
protected  String fWorkspaceNameJNDIName
          Holds the JNDI name of the workspace name
 
Fields inherited from class com.webmethods.caf.faces.bean.BaseFacesSessionBean
fExpireWithPageFlow
 
Fields inherited from class com.webmethods.caf.faces.bean.BaseFacesBean
DATA_BINDING_CLIENTS, OUTCOME_ERROR, OUTCOME_OK, resourcesProviders
 
Constructor Summary
RepositorySessionManager()
           
 
Method Summary
protected  void finalize()
          Overrides the default to logout the current JCR session
 Credentials getCredentials()
          Return the credentials used to create a JCR session
 Session getCurrentSession()
          Return the currently active session is it exists and is still live, otherwise a new JCR session is created and returned.
 String getImpersonatedUser()
          Returns the user that the current session will impersonate
 Repository getRepository()
          Get the handle to the repository by using a JNDI lookup
 String refreshDiscardUnsaved()
          This is a convenience method to expose the Session#refresh(boolean) API for use in a MethodBinding expression.
 String refreshKeepUnsaved()
          This is a convenience method to expose the Session#refresh(boolean) API for use in a MethodBinding expression.
protected  void release()
          Overrides the default to logout the current JCR session
 String save()
          This is a convenience method to expose the Session#save() API for use in a MethodBinding expression.
 void setCredentials(Credentials credentials)
          Sets the credentials to use
 void setImpersonatedUser(String impersonatedUser)
          Sets the user that the session will attempt to impersonate
 String startNewSession()
          This is a convenience method to throw away the current JCR session.
 
Methods inherited from class com.webmethods.caf.faces.bean.BaseFacesSessionBean
getExpireWithPageFlow, setExpireWithPageFlow, valueBound, valueUnbound
 
Methods inherited from class com.webmethods.caf.faces.bean.BaseFacesBean
createMethodBinding, createValueBinding, error, error, error, error, error, getBean, getFacesContext, getLocale, getResourceInputStream, getResources, getResourcesProvider, getRootCause, getStackTrace, getTreeAttribute, isUserInRole, log, log, log, putTreeAttribute, resetDataBindingClients, resolveDataBinding, resolveDataBinding, resolveExpression, setValue
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fRepositoryJNDIName

protected String fRepositoryJNDIName
Holds the JNDI name to get a reference to the Repository


fWorkspaceNameJNDIName

protected String fWorkspaceNameJNDIName
Holds the JNDI name of the workspace name


fWorkspaceName

protected String fWorkspaceName
Holds the current workspace name


fCurrentSession

protected Session fCurrentSession
Holds the current JCR session


fImpersonatedUser

protected String fImpersonatedUser
Holds the id of the impersonated user


fRepository

protected Repository fRepository
Holds reference to the JCR Repository


fCredentials

protected Credentials fCredentials
Holds reference to the user credentials. If this is null, and we are a MwS inproc app, then the current MwS user will be used.

Constructor Detail

RepositorySessionManager

public RepositorySessionManager()
Method Detail

getRepository

public Repository getRepository()
Get the handle to the repository by using a JNDI lookup

Returns:
the repository

getCredentials

public Credentials getCredentials()
Return the credentials used to create a JCR session


setCredentials

public void setCredentials(Credentials credentials)
Sets the credentials to use

Parameters:
credentials - the credentials to set

getCurrentSession

public Session getCurrentSession()
Return the currently active session is it exists and is still live, otherwise a new JCR session is created and returned. This API will also attempt user impersonation if an impersonatedUser has been supplied. NOTE: the real user must be a member of the admin role to impersonate other users.

Returns:
the currentSession

release

protected void release()
Overrides the default to logout the current JCR session

Specified by:
release in class BaseFacesSessionBean
See Also:
BaseFacesSessionBean.release()

finalize

protected void finalize()
                 throws Throwable
Overrides the default to logout the current JCR session

Overrides:
finalize in class Object
Throws:
Throwable
See Also:
Object.finalize()

startNewSession

public String startNewSession()
This is a convenience method to throw away the current JCR session.

Returns:
action status: "ok" or "error"

save

public String save()
This is a convenience method to expose the Session#save() API for use in a MethodBinding expression. Any RepositoryException is caught and exposed as a FacesMessage.

Returns:
action status: "ok" or "error"

refreshDiscardUnsaved

public String refreshDiscardUnsaved()
This is a convenience method to expose the Session#refresh(boolean) API for use in a MethodBinding expression. Any RepositoryException is caught and exposed as a FacesMessage. Refreshes the state in the current session. All unsaved transient nodes/properties will be discarded.

Returns:
action status: "ok" or "error"

refreshKeepUnsaved

public String refreshKeepUnsaved()
This is a convenience method to expose the Session#refresh(boolean) API for use in a MethodBinding expression. Any RepositoryException is caught and exposed as a FacesMessage. Refresh the state in the current session. All unsaved transient nodes/properties will be preserved.

Returns:
action status: "ok" or "error"

getImpersonatedUser

public String getImpersonatedUser()
Returns the user that the current session will impersonate


setImpersonatedUser

public void setImpersonatedUser(String impersonatedUser)
Sets the user that the session will attempt to impersonate

Parameters:
impersonatedUser - the userid to impersonate