org.jboss.dna.repository.util
Class AbstractSessionFactory

java.lang.Object
  extended by org.jboss.dna.repository.util.AbstractSessionFactory
All Implemented Interfaces:
SessionFactory
Direct Known Subclasses:
SimpleSessionFactory

public abstract class AbstractSessionFactory
extends Object
implements SessionFactory

A SessionFactory implementation that creates Session instances using Repository instances.

This factory using a naming convention where the name supplied to the createSession(String) contains both the name of the repository and the name of the workspace. Typically, this is repositoryName/workspaceName, where repositoryName is the name under which the Repository instance was bound, and workspaceName is the name of the workspace. Note that this method looks for the last delimiter in the whole name to distinguish between the repository and workspace names.

For example, if "java:comp/env/repository/dataRepository/myWorkspace" is passed to the createSession(String) method, this factory will look for a Repository instance registered with the name " java:comp/env/repository/dataRepository" and use it to create a session to the workspace named "myWorkspace".

By default, this factory creates an anonymous JCR session. To use sessions with specific Credentials, simply register credentials for the appropriate repository/workspace name. For security reasons, it is not possible to retrieve the Credentials once registered with this factory.


Constructor Summary
AbstractSessionFactory()
          Create an instance of the factory with the default delimiters.
AbstractSessionFactory(char... workspaceDelimiters)
          Create an instance of the factory by supplying naming context and the characters that may be used to delimit the workspace name from the repository name.
 
Method Summary
 javax.jcr.Session createSession(String name)
          
 boolean registerCredentials(String name, javax.jcr.Credentials credentials)
          Register the credentials to be used for the named repository and workspace.
 boolean registerCredentials(String name, String username, char[] password)
          Register the credentials for the repository and workspace given by the supplied name, username and password.
 void registerRepository(String name, javax.jcr.Repository repository)
          Convenience method to bind a repository in JNDI.
 boolean removeCredentials(String name)
          Remove any credentials associated with the named repository and workspace.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSessionFactory

public AbstractSessionFactory()
Create an instance of the factory with the default delimiters.


AbstractSessionFactory

public AbstractSessionFactory(char... workspaceDelimiters)
Create an instance of the factory by supplying naming context and the characters that may be used to delimit the workspace name from the repository name.

Parameters:
workspaceDelimiters - the delimiters, or null/empty if the default delimiter of '/' should be used.
Throws:
IllegalArgumentException - if the context parameter is null
Method Detail

registerRepository

public void registerRepository(String name,
                               javax.jcr.Repository repository)
Convenience method to bind a repository in JNDI. Repository instances can be bound into JNDI using any technique, so this method need not be used. Note that the name should not contain the workspace part.

Parameters:
name - the name of the repository, without the workspace name component.
repository - the repository to be bound, or null if an existing repository should be unbound.

registerCredentials

public boolean registerCredentials(String name,
                                   String username,
                                   char[] password)
Register the credentials for the repository and workspace given by the supplied name, username and password. This is equivalent to calling registerCredentials(name, new SimpleCredentials(username,password)), although if username is null then this is equivalent to registerCredentials(name,null).

Parameters:
name - the name of the repository and workspace
username - the username to use, or null if the existing credentials for the named workspace should be removed
password - the password, may be null or empty
Returns:
true if this overwrote existing credentials
See Also:
registerCredentials(String, Credentials), removeCredentials(String)

registerCredentials

public boolean registerCredentials(String name,
                                   javax.jcr.Credentials credentials)
Register the credentials to be used for the named repository and workspace. Use the same name as used to create sessions.

Parameters:
name - the name of the repository and workspace
credentials - the credentials to use, or null if the existing credentials for the named workspace should be removed
Returns:
true if this overwrote existing credentials
See Also:
registerCredentials(String, String, char[]), removeCredentials(String)

removeCredentials

public boolean removeCredentials(String name)
Remove any credentials associated with the named repository and workspace. This is equivalent to calling registerCredentials(name,null).

Parameters:
name - the name of the repository and workspace
Returns:
true if existing credentials were found and removed, or false if no such credentials existed
See Also:
registerCredentials(String, Credentials)

createSession

public javax.jcr.Session createSession(String name)
                                throws javax.jcr.RepositoryException

Specified by:
createSession in interface SessionFactory
Throws:
javax.jcr.RepositoryException


Copyright © 2008-2009 JBoss, a division of Red Hat. All Rights Reserved.