org.springframework.extensions.jcr
Class JcrSessionFactory

java.lang.Object
  extended by org.springframework.extensions.jcr.JcrSessionFactory
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, SessionFactory
Direct Known Subclasses:
JackrabbitSessionFactory

public class JcrSessionFactory
extends java.lang.Object
implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, SessionFactory

Jcr Session Factory. This class is just a simple wrapper around the repository which facilitates session retrieval through a central point. No exception conversion from Jcr Repository exceptions to Spring DAO exceptions is done.

The session factory is able to add event listener definitions for each session and some utility methods.
Note that for added functionality (like JackRabbit SessionListener) you can use the decorators package (available from JackRabbit).

This factory beans allows registration for namespaces. By default, newly registered namespaces will not be unregistered once the FactoryBean is destroyed and existing namespaces registered under the same suffix will not be overwritten since most JCR implementations do not support these features. One can change this behavior using the setForceNamespacesRegistration(boolean), {@link #setKeepNewNamespaces(boolean) and

Author:
Costin Leau, Brian Moseley , Sergio Bossa, Salvatore Incandela

Constructor Summary
JcrSessionFactory()
          Empty constructor.
JcrSessionFactory(javax.jcr.Repository repository, java.lang.String workspaceName, javax.jcr.Credentials credentials)
          Constructor with all the required fields.
JcrSessionFactory(javax.jcr.Repository repository, java.lang.String workspaceName, javax.jcr.Credentials credentials, SessionHolderProviderManager sessionHolderProviderManager)
          Constructor containing all the fields available.
 
Method Summary
protected  javax.jcr.Session addListeners(javax.jcr.Session session)
          Hook for adding listeners to the newly returned session.
 void afterPropertiesSet()
           
 void destroy()
           
 boolean equals(java.lang.Object obj)
           
 javax.jcr.Credentials getCredentials()
           
 EventListenerDefinition[] getEventListeners()
           
 java.util.Properties getNamespaces()
           
 javax.jcr.Repository getRepository()
           
 javax.jcr.Session getSession()
          Returns a JCR Session using the credentials and workspace on this JcrSessionFactory.
 SessionHolder getSessionHolder(javax.jcr.Session session)
          Returns a specific SessionHolder for the given Session.
protected  SessionHolderProvider getSessionHolderProvider()
          Used internally.
 SessionHolderProviderManager getSessionHolderProviderManager()
           
 java.lang.String getWorkspaceName()
           
 int hashCode()
           
 boolean isForceNamespacesRegistration()
           
 boolean isKeepNewNamespaces()
           
 boolean isSkipExistingNamespaces()
           
protected  void registerNamespaces()
          Register the namespaces.
protected  void registerNodeTypes()
          Hook for registering node types on the underlying repository.
 void setCredentials(javax.jcr.Credentials credentials)
           
 void setEventListeners(EventListenerDefinition[] eventListenerDefinitions)
           
 void setForceNamespacesRegistration(boolean forceNamespacesRegistration)
          Indicate if the given namespace registrations will override the namespace already registered in the repository under the same prefix.
 void setKeepNewNamespaces(boolean keepNamespaces)
          Indicate if the given namespace registrations will be kept (the default) when the application context closes down or if they will be unregistered.
 void setNamespaces(java.util.Properties namespaces)
           
 void setRepository(javax.jcr.Repository repository)
           
protected  void setSessionHolderProvider(SessionHolderProvider sessionHolderProvider)
          Used internally.
 void setSessionHolderProviderManager(SessionHolderProviderManager sessionHolderProviderManager)
           
 void setSkipExistingNamespaces(boolean skipRegisteredNamespace)
          Indicate if the given namespace registrations will skip already registered namespaces or not.
 void setWorkspaceName(java.lang.String workspaceName)
           
 java.lang.String toString()
           
protected  void unregisterNamespaces()
          Removes the namespaces.
protected  void unregisterNodeTypes()
          Hook for un-registering node types on the underlying repository.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JcrSessionFactory

public JcrSessionFactory(javax.jcr.Repository repository,
                         java.lang.String workspaceName,
                         javax.jcr.Credentials credentials)
Constructor with all the required fields.

Parameters:
repository -
workspaceName -
credentials -

JcrSessionFactory

public JcrSessionFactory(javax.jcr.Repository repository,
                         java.lang.String workspaceName,
                         javax.jcr.Credentials credentials,
                         SessionHolderProviderManager sessionHolderProviderManager)
Constructor containing all the fields available.

Parameters:
repository -
workspaceName -
credentials -
sessionHolderProviderManager -

JcrSessionFactory

public JcrSessionFactory()
Empty constructor.

Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

registerNodeTypes

protected void registerNodeTypes()
                          throws java.lang.Exception
Hook for registering node types on the underlying repository. Since this process is not covered by the spec, each implementation requires its own subclass. By default, this method doesn't do anything.

Throws:
java.lang.Exception

unregisterNodeTypes

protected void unregisterNodeTypes()
                            throws java.lang.Exception
Hook for un-registering node types on the underlying repository. Since this process is not covered by the spec, each implementation requires its own subclass. By default, this method doesn't do anything.

Throws:
java.lang.Exception

registerNamespaces

protected void registerNamespaces()
                           throws java.lang.Exception
Register the namespaces.

Parameters:
session -
Throws:
javax.jcr.RepositoryException
java.lang.Exception

destroy

public void destroy()
             throws java.lang.Exception
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
java.lang.Exception
See Also:
DisposableBean.destroy()

unregisterNamespaces

protected void unregisterNamespaces()
                             throws java.lang.Exception
Removes the namespaces.

Parameters:
session -
Throws:
java.lang.Exception

getSession

public javax.jcr.Session getSession()
                             throws javax.jcr.RepositoryException
Description copied from interface: SessionFactory
Returns a JCR Session using the credentials and workspace on this JcrSessionFactory. The session factory doesn't allow specification of a different workspace name because:

" Each Session object is associated one-to-one with a Workspace object. The Workspace object represents a `view` of an actual repository workspace entity as seen through the authorization settings of its associated Session." (quote from javax.jcr.Session javadoc).

Specified by:
getSession in interface SessionFactory
Returns:
the JCR session.
Throws:
javax.jcr.RepositoryException
See Also:
SessionFactory.getSession()

getSessionHolder

public SessionHolder getSessionHolder(javax.jcr.Session session)
Description copied from interface: SessionFactory
Returns a specific SessionHolder for the given Session. The holder provider is used internally by the framework in components such as transaction managers to provide implementation specific information such as transactional support (if it is available).

Specified by:
getSessionHolder in interface SessionFactory
Returns:
specific sessionHolder.
See Also:
SessionFactory.getSessionHolder(javax.jcr.Session)

addListeners

protected javax.jcr.Session addListeners(javax.jcr.Session session)
                                  throws javax.jcr.RepositoryException
Hook for adding listeners to the newly returned session. We have to treat exceptions manually and can't reply on the template.

Parameters:
session - JCR session
Returns:
the listened session
Throws:
javax.jcr.RepositoryException

getRepository

public javax.jcr.Repository getRepository()
Returns:
Returns the repository.

setRepository

public void setRepository(javax.jcr.Repository repository)
Parameters:
repository - The repository to set.

setWorkspaceName

public void setWorkspaceName(java.lang.String workspaceName)
Parameters:
workspaceName - The workspaceName to set.

setCredentials

public void setCredentials(javax.jcr.Credentials credentials)
Parameters:
credentials - The credentials to set.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

getEventListeners

public EventListenerDefinition[] getEventListeners()
Returns:
Returns the eventListenerDefinitions.

setEventListeners

public void setEventListeners(EventListenerDefinition[] eventListenerDefinitions)
Parameters:
eventListenerDefinitions - The eventListenerDefinitions to set.

getNamespaces

public java.util.Properties getNamespaces()
Returns:
Returns the namespaces.

setNamespaces

public void setNamespaces(java.util.Properties namespaces)
Parameters:
namespaces - The namespaces to set.

getSessionHolderProvider

protected SessionHolderProvider getSessionHolderProvider()
Used internally.

Returns:
Returns the sessionHolderProvider.

setSessionHolderProvider

protected void setSessionHolderProvider(SessionHolderProvider sessionHolderProvider)
Used internally.

Parameters:
sessionHolderProvider - The sessionHolderProvider to set.

getSessionHolderProviderManager

public SessionHolderProviderManager getSessionHolderProviderManager()
Returns:
Returns the sessionHolderProviderManager.

setSessionHolderProviderManager

public void setSessionHolderProviderManager(SessionHolderProviderManager sessionHolderProviderManager)
Parameters:
sessionHolderProviderManager - The sessionHolderProviderManager to set.

setKeepNewNamespaces

public void setKeepNewNamespaces(boolean keepNamespaces)
Indicate if the given namespace registrations will be kept (the default) when the application context closes down or if they will be unregistered. If unregistered, the namespace mappings that were overriden are registered back to the repository.

Parameters:
keepNamespaces - The keepNamespaces to set.
See Also:
forceNamespacesRegistration

setForceNamespacesRegistration

public void setForceNamespacesRegistration(boolean forceNamespacesRegistration)
Indicate if the given namespace registrations will override the namespace already registered in the repository under the same prefix. This will cause unregistration for the namespaces that will be modified.

However, depending on the setKeepNewNamespaces(boolean) setting, the old namespaces can be registered back once the application context is destroyed. False by default.

Parameters:
forceNamespacesRegistration - The forceNamespacesRegistration to set.

setSkipExistingNamespaces

public void setSkipExistingNamespaces(boolean skipRegisteredNamespace)
Indicate if the given namespace registrations will skip already registered namespaces or not. If true (default), the new namespace will not be registered and the old namespace kept in place. If not skipped, registration of new namespaces will fail if there are already namespace registered under the same prefix.

This flag is required for JCR implementations which do not support namespace unregistration which render the setForceNamespacesRegistration(boolean) method useless (as namespace registration cannot be forced).

Parameters:
skipRegisteredNamespace - The skipRegisteredNamespace to set.

isForceNamespacesRegistration

public boolean isForceNamespacesRegistration()
Returns:
Returns the forceNamespacesRegistration.

isKeepNewNamespaces

public boolean isKeepNewNamespaces()
Returns:
Returns the keepNewNamespaces.

isSkipExistingNamespaces

public boolean isSkipExistingNamespaces()
Returns:
Returns the skipExistingNamespaces.

getCredentials

public javax.jcr.Credentials getCredentials()
Returns:
Returns the credentials.

getWorkspaceName

public java.lang.String getWorkspaceName()
Returns:
Returns the workspaceName.


Copyright © 2009. All Rights Reserved.