|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.GenericService SK.gnome.dwarf.mail.store.GenericFileStore
This class provides a generic filesystem-based store.
This kind of store may be used to hold and manage a user-specific data, like mail messages, security permissions, application configuration files, etc. There is a separate space reserved for each user, represented by a directory in the filesystem.
All user files are kept within the specified userBaseDir
directory.
For each user ther will be a special subdirectory created in it, with the name equal
to the user's name. It may be then obtained via the getUserDirectory(String)
method.
If letterSubdirs
feature is enabled, the user subdirectories will be
grouped according to the first letter of the user name. Thus a user named "joe"
would reside in the "<userBaseDir>/j/joe" subdirectory instead
of the default "<userBaseDir>/joe".
If autoCreate
feature is enabled, the getUserDirectory(String)
method will automatically create a store for the given user if it does not yet exists.
The storeObject(String, String, Object)
and readObject(String, String)
methods may be used for reading and storing arbitrary serializable objects to the store.
If backupObjects
feature is enabled, the storing method will automatically create
a backup of the existing file before it stores the serialized object to it. This option
is enabled by default.
Field Summary | |
protected boolean |
autoCreate
Whether a store will be created automatically for the given user by the getUserDirectory(String) method.
|
protected boolean |
backupObjects
Whether a backup file will be create when storing the serialized object by the storeObject(String, String, Object) method.
|
protected boolean |
letterSubdirs
Whether a subdirectories will be created according to the first letter of a user identification. |
protected java.io.File |
userBaseDir
The base directory of the store. |
Fields inherited from class SK.gnome.dwarf.GenericService |
initParameters, parent |
Fields inherited from interface SK.gnome.dwarf.Service |
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED |
Constructor Summary | |
GenericFileStore(java.lang.String name)
Creates a new GenericFileStore. |
Method Summary | |
void |
create(java.lang.String user)
Creates a store for the given user. |
boolean |
exists(java.lang.String user)
Whether the given user's store exists. |
protected java.io.File |
getUserDirectory(java.lang.String user)
Returns a subdirectory associated with the given user. |
void |
init(SK.gnome.dwarf.Server parent)
|
java.lang.String[] |
listUsers()
Returns a list of all users present in this store. |
protected boolean |
lock(java.lang.String user,
java.lang.String filename)
Locks the given file within the user subdirectory. |
protected java.lang.Object |
readObject(java.lang.String user,
java.lang.String filename)
Reads an object from the given user store. |
void |
remove(java.lang.String user)
Removes the given user's store. |
void |
setAutoCreate(boolean enable)
Enables or disables the store auto-creation feature. |
void |
setBackupObjects(boolean enable)
Enables or disables backup files when storing the serialized objects. |
void |
setLetterSubdirs(boolean enable)
Enables or disables the first-letter subdirectories. |
void |
setUserBaseDir(java.io.File dir)
Sets the base directory of the store. |
protected void |
storeObject(java.lang.String user,
java.lang.String filename,
java.lang.Object object)
Stores the object to the given user store. |
protected void |
unlock(java.lang.String user,
java.lang.String filename)
Unlocks the given file within the user subdirectory. |
Methods inherited from class SK.gnome.dwarf.GenericService |
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, shutdown, start, stop, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected boolean autoCreate
getUserDirectory(String)
method.
Default value: MailConstants.MAIL_DEFAULT_AUTO_CREATE_STORE
protected boolean letterSubdirs
Default value: false
protected boolean backupObjects
storeObject(String, String, Object)
method.
Default value: true
protected java.io.File userBaseDir
Constructor Detail |
public GenericFileStore(java.lang.String name)
Method Detail |
public void setAutoCreate(boolean enable)
enable
- true to enable the feature, false to disableautoCreate
public void setLetterSubdirs(boolean enable)
enable
- true to enable the feature, false to disableletterSubdirs
public void setBackupObjects(boolean enable)
enable
- true to enable the feature, false to disablebackupObjects
public void setUserBaseDir(java.io.File dir)
dir
- the directorypublic void init(SK.gnome.dwarf.Server parent) throws SK.gnome.dwarf.ServiceException
SK.gnome.dwarf.ServiceException
public void create(java.lang.String user) throws MailException
user
- the user identification
MailException
- if an error occuredpublic boolean exists(java.lang.String user) throws MailException
user
- the user identification
MailException
- if an error occuredpublic void remove(java.lang.String user) throws MailException
user
- the user identification
MailException
- if an error occuredpublic java.lang.String[] listUsers() throws MailException
MailException
- if an error occuredprotected java.io.File getUserDirectory(java.lang.String user) throws MailException
user
- the user identification
MailException
- if an error occuredprotected java.lang.Object readObject(java.lang.String user, java.lang.String filename) throws MailException
The returned object is read from a file input stream denoted by the filename argument. If the input file does not exists, a null value is returned.
The object must be stored via the storeObject(String, String, Object)
first
to be made available for reading.
user
- the user identificationfilename
- the name of file to read the object from
MailException
- if an error occuredprotected void storeObject(java.lang.String user, java.lang.String filename, java.lang.Object object) throws MailException
The object is stored to a file output stream denoted by the filename argument. Only serializable objects may be stored by this method, and only one object instance per file is permitted.
The stored object can be read via the readObject(String, String)
method.
user
- the user udentificationfilename
- the name of file to store the object toobject
- the object to be stored
MailException
- if an error occuredprotected boolean lock(java.lang.String user, java.lang.String filename) throws MailException
If the filename argument is null, the whole user subdirectory will be locked instead of a single file.
user
- the user identificationfilename
- the name of file
MailException
- if an error occuredprotected void unlock(java.lang.String user, java.lang.String filename) throws MailException
If the filename argument is null, the whole user subdirectory will be unlocked instead of a single file.
user
- the user identificationfilename
- the name of file
MailException
- if an error occured
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |