org.apache.james.jcr
Class JCRMailRepository

java.lang.Object
  extended by org.apache.james.jcr.JCRMailRepository
All Implemented Interfaces:
MailRepository
Direct Known Subclasses:
AvalonJCRMailRepository

public class JCRMailRepository
extends java.lang.Object
implements MailRepository

Mail repository that is backed by a JCR content repository.


Field Summary
protected  javax.jcr.Credentials credentials
          Login credentials for accessing the repository.
protected  org.apache.commons.logging.Log logger
           
protected  java.lang.String path
          Path (relative to root) of the mail repository within the workspace.
protected  javax.jcr.Repository repository
          JCR content repository used as the mail repository.
protected  java.lang.String workspace
          Name of the workspace used as the mail repository.
 
Fields inherited from interface org.apache.james.services.MailRepository
MAIL, ROLE
 
Constructor Summary
JCRMailRepository()
          For setter injection.
JCRMailRepository(javax.jcr.Repository repository, javax.jcr.Credentials credentials, java.lang.String workspace, java.lang.String path, org.apache.commons.logging.Log logger)
          Maximal constructor for injection.
JCRMailRepository(javax.jcr.Repository repository, org.apache.commons.logging.Log logger)
          Minimal constructor for injection.
 
Method Summary
 javax.jcr.Credentials getCredentials()
          Returns the login credentials for accessing the repository.
 org.apache.commons.logging.Log getLogger()
          Gets the current logger.
 java.lang.String getPath()
          Returns the path of the mail repository within the workspace.
 javax.jcr.Repository getRepository()
          Retuns the JCR content repository used as the mail repository.
 java.lang.String getWorkspace()
          Returns the name of the workspace used as the mail repository.
 java.util.Iterator list()
          List string keys of messages in repository.
 boolean lock(java.lang.String key)
          Obtains a lock on a message identified by key
protected  javax.jcr.Session login()
          Logs into a new session.
protected  javax.jcr.NodeIterator query(javax.jcr.Session session, java.lang.String xpath)
           
 void remove(java.util.Collection mails)
          Remove an Collection of mails from the repository
 void remove(org.apache.mailet.Mail mail)
          Removes a specified message
 void remove(java.lang.String key)
          Removes a message identified by key.
 org.apache.mailet.Mail retrieve(java.lang.String key)
          Retrieves a message given a key.
 void setCredentials(javax.jcr.Credentials credentials)
          Sets the login credentials for accessing the repository.
 void setLogger(org.apache.commons.logging.Log logger)
          Sets the current logger.
 void setPath(java.lang.String path)
          Sets the path of the mail repository within the workspace.
 void setRepository(javax.jcr.Repository repository)
          Sets the JCR content repository to be used as the mail repository.
 void setWorkspace(java.lang.String workspace)
          Sets the name of the workspace used as the mail repository.
 void store(org.apache.mailet.Mail mail)
          Stores a message in this repository.
protected  java.lang.String toSafeName(java.lang.String key)
           
 boolean unlock(java.lang.String key)
          Releases a lock on a message identified the key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected org.apache.commons.logging.Log logger

repository

protected javax.jcr.Repository repository
JCR content repository used as the mail repository. Must be set before the any mail operations are performed.


credentials

protected javax.jcr.Credentials credentials
Login credentials for accessing the repository. Set to null (the default) to use default credentials.


workspace

protected java.lang.String workspace
Name of the workspace used as the mail repository. Set to null (the default) to use the default workspace.


path

protected java.lang.String path
Path (relative to root) of the mail repository within the workspace.

Constructor Detail

JCRMailRepository

public JCRMailRepository()
For setter injection.


JCRMailRepository

public JCRMailRepository(javax.jcr.Repository repository,
                         javax.jcr.Credentials credentials,
                         java.lang.String workspace,
                         java.lang.String path,
                         org.apache.commons.logging.Log logger)
Maximal constructor for injection.

Parameters:
repository - not null
credentials - login credentials for accessing the repository or null to use default credentials
workspace - name of the workspace used as the mail repository. or null to use default workspace
path - path (relative to root) of the user node within the workspace, or null to use default.

JCRMailRepository

public JCRMailRepository(javax.jcr.Repository repository,
                         org.apache.commons.logging.Log logger)
Minimal constructor for injection.

Parameters:
repository - not null
Method Detail

list

public java.util.Iterator list()
                        throws javax.mail.MessagingException
Description copied from interface: MailRepository
List string keys of messages in repository.

Specified by:
list in interface MailRepository
Returns:
an Iterator over the list of keys in the repository
Throws:
javax.mail.MessagingException

retrieve

public org.apache.mailet.Mail retrieve(java.lang.String key)
                                throws javax.mail.MessagingException
Description copied from interface: MailRepository
Retrieves a message given a key. At the moment, keys can be obtained from list() in superinterface Store.Repository

Specified by:
retrieve in interface MailRepository
Parameters:
key - the key of the message to retrieve
Returns:
the mail corresponding to this key, null if none exists
Throws:
javax.mail.MessagingException

store

public void store(org.apache.mailet.Mail mail)
           throws javax.mail.MessagingException
Description copied from interface: MailRepository
Stores a message in this repository. Shouldn't this return the key under which it is stored?

Specified by:
store in interface MailRepository
Parameters:
mail - the mail message to store
Throws:
javax.mail.MessagingException

remove

public void remove(java.lang.String key)
            throws javax.mail.MessagingException
Description copied from interface: MailRepository
Removes a message identified by key.

Specified by:
remove in interface MailRepository
Parameters:
key - the key of the message to be removed from the repository
Throws:
javax.mail.MessagingException

remove

public void remove(org.apache.mailet.Mail mail)
            throws javax.mail.MessagingException
Description copied from interface: MailRepository
Removes a specified message

Specified by:
remove in interface MailRepository
Parameters:
mail - the message to be removed from the repository
Throws:
javax.mail.MessagingException

remove

public void remove(java.util.Collection mails)
            throws javax.mail.MessagingException
Description copied from interface: MailRepository
Remove an Collection of mails from the repository

Specified by:
remove in interface MailRepository
Parameters:
mails - The Collection of MailImpl's to delete
Throws:
javax.mail.MessagingException

lock

public boolean lock(java.lang.String key)
             throws javax.mail.MessagingException
Description copied from interface: MailRepository
Obtains a lock on a message identified by key

Specified by:
lock in interface MailRepository
Parameters:
key - the key of the message to be locked
Returns:
true if successfully obtained the lock, false otherwise
Throws:
javax.mail.MessagingException

unlock

public boolean unlock(java.lang.String key)
               throws javax.mail.MessagingException
Description copied from interface: MailRepository
Releases a lock on a message identified the key

Specified by:
unlock in interface MailRepository
Parameters:
key - the key of the message to be unlocked
Returns:
true if successfully released the lock, false otherwise
Throws:
javax.mail.MessagingException

getLogger

public final org.apache.commons.logging.Log getLogger()
Gets the current logger.

Returns:
the logger, not null

setLogger

public final void setLogger(org.apache.commons.logging.Log logger)
Sets the current logger.

Parameters:
logger - the logger to set, not null

getRepository

public javax.jcr.Repository getRepository()
Retuns the JCR content repository used as the mail repository.

Returns:
JCR content repository

setRepository

public void setRepository(javax.jcr.Repository repository)
Sets the JCR content repository to be used as the mail repository.

Parameters:
repository - JCR content repository

getCredentials

public javax.jcr.Credentials getCredentials()
Returns the login credentials for accessing the repository.

Returns:
login credentials, or null if using the default credentials

setCredentials

public void setCredentials(javax.jcr.Credentials credentials)
Sets the login credentials for accessing the repository.

Parameters:
credentials - login credentials, or null to use the default credentials

getWorkspace

public java.lang.String getWorkspace()
Returns the name of the workspace used as the mail repository.

Returns:
workspace name, or null if using the default workspace

setWorkspace

public void setWorkspace(java.lang.String workspace)
Sets the name of the workspace used as the mail repository.

Parameters:
workspace - workspace name, or null to use the default workspace

getPath

public java.lang.String getPath()
Returns the path of the mail repository within the workspace.

Returns:
repository path

setPath

public void setPath(java.lang.String path)
Sets the path of the mail repository within the workspace.

Parameters:
path - repository path

login

protected javax.jcr.Session login()
                           throws javax.jcr.LoginException,
                                  javax.jcr.NoSuchWorkspaceException,
                                  javax.jcr.RepositoryException
Logs into a new session.

Returns:
new session, not null
Throws:
javax.jcr.LoginException - when login fails
javax.jcr.NoSuchWorkspaceException - when workspace does not exist
javax.jcr.RepositoryException - when access fails

toSafeName

protected java.lang.String toSafeName(java.lang.String key)

query

protected javax.jcr.NodeIterator query(javax.jcr.Session session,
                                       java.lang.String xpath)
                                throws javax.jcr.RepositoryException,
                                       javax.jcr.query.InvalidQueryException
Throws:
javax.jcr.RepositoryException
javax.jcr.query.InvalidQueryException


Copyright ? 2002-2009 The Apache Software Foundation. All Rights Reserved.