T
- the specific base XML object type being managed@NotThreadSafe public class FilesystemLoadSaveManager<T extends XMLObject> extends Object implements XMLObjectLoadSaveManager<T>
XMLObjectLoadSaveManager
which uses a local filesystem to load and store serialized XML.
The primary required configuration is a base directory path under which files of serialized XML will be located. The file name to use is simply the specified String index key, which is treated as an immediate child file name of the base directory. Callers are required to ensure that index keys are acceptable as file names on the platform(s) on which this manager is used.
Modifier and Type | Class and Description |
---|---|
static class |
FilesystemLoadSaveManager.DefaultFileFilter
Default filter used to filter data returned in
listKeys()
and listAll() . |
private class |
FilesystemLoadSaveManager.FileIterable
Iterable which provides lazy iteration over the managed files.
|
private class |
FilesystemLoadSaveManager.FileIterator
Iterator which provides lazy iteration over the managed files.
|
Modifier and Type | Field and Description |
---|---|
private File |
baseDirectory
The base directory used for storing individual serialized XML files.
|
private FileFilter |
fileFilter
File file used in filtering files in
listKeys() and listAll() . |
private org.slf4j.Logger |
log
Logger.
|
private ParserPool |
parserPool
Parser pool instance for deserializing XML from the filesystem.
|
Constructor and Description |
---|
FilesystemLoadSaveManager(File baseDir)
Constructor.
|
FilesystemLoadSaveManager(File baseDir,
ParserPool pp)
Constructor.
|
FilesystemLoadSaveManager(String baseDir)
Constructor.
|
FilesystemLoadSaveManager(String baseDir,
ParserPool pp)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected File |
buildFile(String key)
Build the target file name from the specified index key and the configured base directory.
|
boolean |
exists(String key)
Evaluate whether an object already exists indexed by the supplied key.
|
Iterable<Pair<String,T>> |
listAll()
Return an iterable of all objects under management, along with their associated index key.
|
Set<String> |
listKeys()
Return a set of the index keys of all objects under management.
|
T |
load(String key)
Load a particular object based on the supplied key.
|
boolean |
remove(String key)
Remove the object indexed by the specified key.
|
void |
save(String key,
T xmlObject)
Save a particular object, indexed by the supplied key.
|
void |
save(String key,
T xmlObject,
boolean overwrite)
Save a particular object, indexed by the supplied key.
|
boolean |
updateKey(String currentKey,
String newKey)
Update the key under which a particular object is stored.
|
private org.slf4j.Logger log
private File baseDirectory
private ParserPool parserPool
private FileFilter fileFilter
listKeys()
and listAll()
.public FilesystemLoadSaveManager(@Nonnull String baseDir)
baseDir
- the base directory, must be an absolute pathpublic FilesystemLoadSaveManager(@Nonnull File baseDir)
baseDir
- the base directory, must be an absolute pathpublic FilesystemLoadSaveManager(@Nonnull String baseDir, @Nullable ParserPool pp)
baseDir
- the base directory, must be an absolute pathpp
- the parser pool instance to usepublic FilesystemLoadSaveManager(@Nonnull File baseDir, @Nullable ParserPool pp)
baseDir
- the base directory, must be an absolute pathpp
- the parser pool instance to usepublic Set<String> listKeys() throws IOException
listKeys
in interface XMLObjectLoadSaveManager<T extends XMLObject>
IOException
- if there is a fatal error obtaining the keyspublic Iterable<Pair<String,T>> listAll() throws IOException
listAll
in interface XMLObjectLoadSaveManager<T extends XMLObject>
IOException
- if there is a fatal error loading the managed objectspublic boolean exists(String key) throws IOException
exists
in interface XMLObjectLoadSaveManager<T extends XMLObject>
key
- the key of the desired objectIOException
- if there is a fatal error evaluating object existencepublic T load(String key) throws IOException
load
in interface XMLObjectLoadSaveManager<T extends XMLObject>
key
- the key of the desired objectIOException
- if there is a fatal error loading the objectpublic void save(String key, T xmlObject) throws IOException
An existing object indexed by the supplied key will not be overwritten.
Instead an IOException
will be thrown.
For saving with the overwrite option, see XMLObjectLoadSaveManager.save(String, XMLObject, boolean)
.
save
in interface XMLObjectLoadSaveManager<T extends XMLObject>
key
- the key under which to index the objectxmlObject
- the object to saveIOException
- if there is a fatal error saving the object, or if an object already exists
indexed by the supplied keypublic void save(String key, T xmlObject, boolean overwrite) throws IOException
save
in interface XMLObjectLoadSaveManager<T extends XMLObject>
key
- the key under which to index the objectxmlObject
- the object to saveoverwrite
- whether or not to overwrite any existing object indexed by the supplied keyIOException
- if there is a fatal error saving the object, or if overwrite=false,
if an object already exists indexed by the supplied keypublic boolean remove(String key) throws IOException
remove
in interface XMLObjectLoadSaveManager<T extends XMLObject>
key
- the key of the object to removeIOException
- if there was a fatal error removing the objectpublic boolean updateKey(String currentKey, String newKey) throws IOException
updateKey
in interface XMLObjectLoadSaveManager<T extends XMLObject>
currentKey
- the current key under which the object is storednewKey
- the new key under which the object should be storedIOException
- if there was a fatal error updating the keyprotected File buildFile(String key) throws IOException
key
- the target file name index keyIOException
- if there is a fatal error constructing or evaluating the candidate target pathCopyright © 1999–2018 Shibboleth Consortium. All rights reserved.