public class PersistenceManager extends Object
Modifier and Type | Class and Description |
---|---|
static class |
PersistenceManager.ClassComparator |
static class |
PersistenceManager.NotComparableException
Thrown by a comparator when the values provided for comparison are
not comparable.
|
protected static class |
PersistenceManager.ObjectHolder
A reference to an object; it uses the identity hashcode and the
equals defined by object identity.
|
static class |
PersistenceManager.RRPersistence |
static class |
PersistenceManager.SlashDevSlashNull
This class is used as a marker for types that should NOT be
serialised when saving the state of a gate object.
|
static class |
PersistenceManager.URLHolder
URLs get upset when serialised and deserialised so we need to
convert them to strings for storage.
|
Constructor and Description |
---|
PersistenceManager() |
Modifier and Type | Method and Description |
---|---|
static File |
currentPersistenceFile()
Get the file currently being saved by this thread.
|
static List<File> |
currentPersistenceFileStack() |
static ResourceReference |
currentPersistenceURL()
Get the URL currently being loaded by this thread.
|
static List<ResourceReference> |
currentPersistenceURLStack() |
protected static Class<?> |
getMostSpecificPersistentType(Class<?> type)
Finds the most specific persistent replacement type for a given
class.
|
static Serializable |
getPersistentRepresentation(Object target)
Recursively traverses the provided object and replaces it and all
its contents with the appropriate persistent equivalent classes.
|
static String |
getRelativePath(URL context,
URL target)
Calculates the relative path for a file: URL starting from a given
context which is also a file: URL.
|
static Object |
getTransientRepresentation(Object target) |
static Object |
getTransientRepresentation(Object target,
String containingControllerName,
Map<String,Map<String,Object>> initParamOverrides) |
static boolean |
isContainedWithin(File file,
File directory)
This method can be used to determine if a specified file (or directory) is
contained within a given directory.
|
static Object |
loadObjectFromFile(File file) |
static Object |
loadObjectFromUri(URI uri) |
static Object |
loadObjectFromUrl(URL url) |
static Class<?> |
registerPersistentEquivalent(Class<?> transientType,
Class<?> persistentType)
Sets the persistent equivalent type to be used to (re)store a given
type of transient objects.
|
static void |
saveObjectToFile(Object obj,
File file)
Save the given object to the file, without using $gatehome$.
|
static void |
saveObjectToFile(Object obj,
File file,
boolean usegatehome,
boolean warnaboutgatehome)
Save the given object to the given file.
|
public static Serializable getPersistentRepresentation(Object target) throws PersistenceException
target
- the object to be analysed and translated into a
persistent equivalent.PersistenceException
public static Object getTransientRepresentation(Object target) throws PersistenceException, ResourceInstantiationException
public static Object getTransientRepresentation(Object target, String containingControllerName, Map<String,Map<String,Object>> initParamOverrides) throws PersistenceException, ResourceInstantiationException
protected static Class<?> getMostSpecificPersistentType(Class<?> type)
Resource
and for LanguageResource
than
such a request for a Document
will yield the
registered type for LanguageResource
.public static boolean isContainedWithin(File file, File directory)
NOTE: this accesses the file system to find the real locations for file and directory. However, if there is a problem accessing the file system, the method will fall back to using the literal path names for checking and NOT produce an error. This is done so that any saving operation during which this method is invoked is not aborted and proceeds, creating a file that may be correct apart from one or more serialized URLs.
file
- is this file contained withindirectory
- this directorypublic static String getRelativePath(URL context, URL target)
context
- the URL to be used as context.target
- the URL for which the relative path is computed.public static void saveObjectToFile(Object obj, File file) throws PersistenceException, IOException
saveObjectToFile(Object,File,boolean,boolean)
with the
third and fourth parameter set to false.
This method exists with this definition to stay backwards compatible with
code that was using this method before paths relative to $gatehome$ were supported.obj
- The object to persistfile
- The file where to persists toPersistenceException
IOException
public static void saveObjectToFile(Object obj, File file, boolean usegatehome, boolean warnaboutgatehome) throws PersistenceException, IOException
obj
- The object to persist.file
- The file where to persist tousegatehome
- if true (recommended) use $gatehome$ and $resourceshome$ instead of
$relpath$ in any saved path URLs if the location of that URL is inside GATE home or
inside the resources home directory (if set).warnaboutgatehome
- if true, issue a warning message when a saved URL uses $gatehome$
or $resourceshome$.PersistenceException
IOException
public static File currentPersistenceFile()
public static Object loadObjectFromFile(File file) throws PersistenceException, IOException, ResourceInstantiationException
public static Object loadObjectFromUrl(URL url) throws PersistenceException, IOException, ResourceInstantiationException
public static Object loadObjectFromUri(URI uri) throws PersistenceException, IOException, ResourceInstantiationException, URISyntaxException
public static ResourceReference currentPersistenceURL()
public static List<ResourceReference> currentPersistenceURLStack()
public static Class<?> registerPersistentEquivalent(Class<?> transientType, Class<?> persistentType) throws PersistenceException
transientType
- the type that will be replaced during
serialisation operationspersistentType
- the type used to replace objects of transient
type when serialising; this type needs to extend
Persistence
.PersistenceException
Copyright © 2024 GATE. All rights reserved.