gate.util.persistence
Class PersistenceManager

java.lang.Object
  extended bygate.util.persistence.PersistenceManager

public class PersistenceManager
extends Object

This class provides utility methods for saving resources through serialisation via static methods.


Nested Class Summary
static class PersistenceManager.ClassComparator
           
static class PersistenceManager.NotComparableException
          Thrown by a comparator when the values provided for comparison are not comparable.
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 Summary
PersistenceManager()
           
 
Method Summary
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 loadObjectFromFile(File file)
           
static Class registerPersitentEquivalent(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)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceManager

public PersistenceManager()
Method Detail

getRelativePath

public 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.

Parameters:
context - the URL to be used as context.
target - the URL for which the relative path is computed.
Returns:
a String value representing the relative path. Constructing a URL from the context URL and the relative path should result in the target URL.

saveObjectToFile

public static void saveObjectToFile(Object obj,
                                    File file)
                             throws PersistenceException,
                                    IOException
Throws:
PersistenceException
IOException

loadObjectFromFile

public static Object loadObjectFromFile(File file)
                                 throws PersistenceException,
                                        IOException,
                                        ResourceInstantiationException
Throws:
PersistenceException
IOException
ResourceInstantiationException

registerPersitentEquivalent

public static Class registerPersitentEquivalent(Class transientType,
                                                Class persistentType)
                                         throws PersistenceException
Sets the persistent equivalent type to be used to (re)store a given type of transient objects.

Parameters:
transientType - the type that will be replaced during serialisation operations
persistentType - the type used to replace objects of transient type when serialising; this type needs to extend Persistence.
Returns:
the persitent type that was used before this mapping if such existed.
Throws:
PersistenceException