Package org.opensaml.core.xml.persist
Class MapLoadSaveManager<T extends XMLObject>
- java.lang.Object
-
- org.opensaml.core.xml.persist.AbstractConditionalLoadXMLObjectLoadSaveManager<T>
-
- org.opensaml.core.xml.persist.MapLoadSaveManager<T>
-
- Type Parameters:
T- the specific base XML object type being managed
- All Implemented Interfaces:
ConditionalLoadXMLObjectLoadSaveManager<T>,XMLObjectLoadSaveManager<T>
@NotThreadSafe public class MapLoadSaveManager<T extends XMLObject> extends AbstractConditionalLoadXMLObjectLoadSaveManager<T>
Simple implementation ofXMLObjectLoadSaveManagerwhich uses an in-memory map.
-
-
Field Summary
Fields Modifier and Type Field Description private Map<String,T>backingMapThe backing map.private Map<String,Instant>dataLastModifiedStorage to track last modified time of data.private org.slf4j.LoggerlogLogger.
-
Constructor Summary
Constructors Modifier Constructor Description MapLoadSaveManager()Constructor.MapLoadSaveManager(boolean conditionalLoad)Constructor.MapLoadSaveManager(Map<String,T> map)Constructor.protectedMapLoadSaveManager(Map<String,T> map, Map<String,Instant> lastModifiedMap, boolean conditionalLoad)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexists(String key)Evaluate whether an object already exists indexed by the supplied key.protected booleanisUnmodifiedSinceLastLoad(String key)Check whether the data corresponding to the specified key has been modified since the last timeXMLObjectLoadSaveManager.load(String)was called for that 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.Tload(String key)Load a particular object based on the supplied key.booleanremove(String key)Remove the object indexed by the specified key.voidsave(String key, T xmlObject)Save a particular object, indexed by the supplied key.voidsave(String key, T xmlObject, boolean overwrite)Save a particular object, indexed by the supplied key.booleanupdateKey(String currentKey, String newKey)Update the key under which a particular object is stored.-
Methods inherited from class org.opensaml.core.xml.persist.AbstractConditionalLoadXMLObjectLoadSaveManager
clearAllLoadLastModified, clearLoadLastModified, getLoadLastModified, isLoadConditionally, updateLoadLastModified, updateLoadLastModified
-
-
-
-
Constructor Detail
-
MapLoadSaveManager
public MapLoadSaveManager()
Constructor.
-
MapLoadSaveManager
public MapLoadSaveManager(@ParameterName(name="conditionalLoad") boolean conditionalLoad)
Constructor.- Parameters:
conditionalLoad- whetherload(String)should behave as defined inConditionalLoadXMLObjectLoadSaveManager
-
MapLoadSaveManager
public MapLoadSaveManager(@ParameterName(name="map") @Nonnull Map<String,T> map)
Constructor.Note: conditional load is not supported with this option, because of the need to track modify times of items stored in the backing map. Use instead
MapLoadSaveManager(boolean).- Parameters:
map- the backing map
-
MapLoadSaveManager
protected MapLoadSaveManager(@ParameterName(name="map") @Nonnull Map<String,T> map, @ParameterName(name="dataLastModified") @Nonnull Map<String,Instant> lastModifiedMap, @ParameterName(name="conditionalLoad") boolean conditionalLoad)
Constructor.- Parameters:
map- the backing maplastModifiedMap- the storage for data last modified timesconditionalLoad- whetherload(String)should behave as defined inConditionalLoadXMLObjectLoadSaveManager
-
-
Method Detail
-
listKeys
public Set<String> listKeys() throws IOException
Return a set of the index keys of all objects under management.- Returns:
- a set of all indexed keys
- Throws:
IOException- if there is a fatal error obtaining the keys
-
listAll
public Iterable<Pair<String,T>> listAll() throws IOException
Return an iterable of all objects under management, along with their associated index key.- Returns:
- an iterable of all managed objects
- Throws:
IOException- if there is a fatal error loading the managed objects
-
exists
public boolean exists(String key) throws IOException
Evaluate whether an object already exists indexed by the supplied key.- Parameters:
key- the key of the desired object- Returns:
- true if object exists, false otherwise
- Throws:
IOException- if there is a fatal error evaluating object existence
-
load
public T load(String key) throws IOException
Load a particular object based on the supplied key.- Parameters:
key- the key of the desired object- Returns:
- the object saved under the specified key, or null if there is no such object
- Throws:
IOException- if there is a fatal error loading the object
-
save
public void save(String key, T xmlObject) throws IOException
Save a particular object, indexed by the supplied key.An existing object indexed by the supplied key will not be overwritten. Instead an
IOExceptionwill be thrown. For saving with the overwrite option, seeXMLObjectLoadSaveManager.save(String, XMLObject, boolean).- Parameters:
key- the key under which to index the objectxmlObject- the object to save- Throws:
IOException- if there is a fatal error saving the object, or if an object already exists indexed by the supplied key
-
save
public void save(String key, T xmlObject, boolean overwrite) throws IOException
Save a particular object, indexed by the supplied key.- Parameters:
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 key- Throws:
IOException- if there is a fatal error saving the object, or if overwrite=false, if an object already exists indexed by the supplied key
-
remove
public boolean remove(String key) throws IOException
Remove the object indexed by the specified key.- Parameters:
key- the key of the object to remove- Returns:
- true if the object was found and successfully removed, false if no such object was found
- Throws:
IOException- if there was a fatal error removing the object
-
updateKey
public boolean updateKey(String currentKey, String newKey) throws IOException
Update the key under which a particular object is stored.- Parameters:
currentKey- the current key under which the object is storednewKey- the new key under which the object should be stored- Returns:
- true if the object was found under the current key and the key successfully updated, false if no such object was found
- Throws:
IOException- if there was a fatal error updating the key
-
isUnmodifiedSinceLastLoad
protected boolean isUnmodifiedSinceLastLoad(@Nonnull String key) throws IOExceptionCheck whether the data corresponding to the specified key has been modified since the last timeXMLObjectLoadSaveManager.load(String)was called for that key.- Specified by:
isUnmodifiedSinceLastLoadin classAbstractConditionalLoadXMLObjectLoadSaveManager<T extends XMLObject>- Parameters:
key- the data key- Returns:
- true if the corresponding data has been modified since the last load, false otherwise
- Throws:
IOException- if there is a fatal error evaluating the last modified status
-
-