## gate.util.persistence
Class PersistenceManager

    java.lang.Object
      |
      +--gate.util.persistence.PersistenceManager

public class PersistenceManager
extends Object

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

Inner Class Summary
`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.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

Field Summary
`private static PersistenceManager.ClassComparator` `classComparator`
`private static Map` `existingPersitentReplacements` Stores the persistent replacements created during a transaction in order to avoid creating two different persistent copies for the same object.
`private static Map` `existingTransientValues` Stores the transient values obtained from persistent replacements during a transaction in order to avoid creating two different transient copies for the same persistent replacement.
`private static Map` `persistentReplacementTypes` A dictionary mapping from java type (Class) to the type (Class) that can be used to store persistent data for the input type.

Constructor Summary
`PersistenceManager()`

Method Summary
`(package private) static void` `<clinit>()`
`protected static Class` `getMostSpecificPersistentType(Class type)` Finds the most specific persistent replacement type for a given class.
`(package private) static Serializable` `getPersistentRepresentation(Object target)` Recursively traverses the provided object and replaces it and all its contents with the appropiate persistent equivalent classes.
`(package private) static Object` `getTransientRepresentation(Object target)`
`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
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### persistentReplacementTypes

    private static Map persistentReplacementTypes

  A dictionary mapping from java type (Class) to the type (Class) that can be used to store persistent data for the input type.

### existingPersitentReplacements

    private static Map existingPersitentReplacements

  Stores the persistent replacements created during a transaction in order to avoid creating two different persistent copies for the same object. The keys used are `PersistenceManager.ObjectHolder`s that contain the transient values being converted to persistent equivalents.

### existingTransientValues

    private static Map existingTransientValues

  Stores the transient values obtained from persistent replacements during a transaction in order to avoid creating two different transient copies for the same persistent replacement. The keys used are `PersistenceManager.ObjectHolder`s that hold persistent equivalents. The values are the transient values created by the persisten equivalents.

### classComparator

    private static PersistenceManager.ClassComparator classComparator

Constructor Detail

### PersistenceManager

    public PersistenceManager()

Method Detail

### getPersistentRepresentation

    static Serializable getPersistentRepresentation(Object target)
                                             throws PersistenceException

  Recursively traverses the provided object and replaces it and all its contents with the appropiate persistent equivalent classes.
  Parameters:
    `the` - object to be analised and translated into a persistent equivalent.
  Returns:
    the persistent equivalent value for the provided target

### getTransientRepresentation

    static Object getTransientRepresentation(Object target)
                                      throws PersistenceException,
                                             ResourceInstantiationException

### getMostSpecificPersistentType

    protected static Class getMostSpecificPersistentType(Class type)

  Finds the most specific persistent replacement type for a given class. Look for a type that has a registered persistent equivalent starting from the provided class continuing with its superclass and implemented interfaces and their superclasses and implemented interfaces and so on until a type is found. Classes are considered to be more specific than interfaces and in situations of ambiguity the most specific types are considered to be the ones that don't belong to either java or GATE followed by the ones that belong to GATE and followed by the ones that belong to java. E.g. if there are registered persitent types for `Resource` and for `LanguageResource` than such a request for a `Document` will yield the registered type for `LanguageResource`.

### saveObjectToFile

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

### loadObjectFromFile

    public static Object loadObjectFromFile(File file)
                                     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.

### <clinit>

    static void <clinit>()