gate.persist
Class SerialDataStore

java.lang.Object
  extended by gate.util.AbstractFeatureBearer
      extended by gate.persist.SerialDataStore
All Implemented Interfaces:
DataStore, FeatureBearer, NameBearer, Serializable
Direct Known Subclasses:
LuceneDataStoreImpl

public class SerialDataStore
extends AbstractFeatureBearer
implements DataStore

A data store based on Java serialisation.

See Also:
Serialized Form

Field Summary
protected  boolean autoSaving
          Flag for autosaving behaviour.
protected  String currentProtocolVersion
          The protocol version of the currently open data store
protected  String name
          The name of the datastore
protected static String[] protocolVersionNumbers
          List of valid protocol version numbers.
protected  File storageDir
          The directory used for the serialised classes.
protected static String versionNumber
          Version number for variations in the storage protocol.
 
Fields inherited from class gate.util.AbstractFeatureBearer
features
 
Fields inherited from interface gate.DataStore
DATASTORE_FEATURE_NAME, LR_ID_FEATURE_NAME
 
Constructor Summary
SerialDataStore()
          Default construction.
SerialDataStore(String storageDirUrl)
          Construction requires a file protocol URL pointing to the storage directory used for the serialised classes.
 
Method Summary
 void addDatastoreListener(DatastoreListener l)
          Registers a new DatastoreListener with this datastore
 LanguageResource adopt(LanguageResource lr, SecurityInfo secInfo)
          Adopt a resource for persistence.
 boolean canReadLR(Object lrID)
          Checks if the user (identified by the sessionID) has read access to the LR
 boolean canWriteLR(Object lrID)
          Checks if the user (identified by the sessionID) has write access to the LR
 void close()
          Close the data store.
protected  String constructPersistenceId(String lrName)
          Create a persistent store Id from the name of a resource.
 void create()
          Create a new data store.
 void delete()
          Delete the data store.
 void delete(String lrClassName, Object lrPersistenceId)
          Delete a resource from the data store.
 boolean equals(Object other)
          Equality: based on storage dir of other.
protected  String[] filterIgnoredFileNames(String[] fileNames)
          This removes the names of all files from a list of file names for which we know that we want to ignore them.
 List findLrIds(List constraints)
          Get a list of LRs that satisfy some set or restrictions
 List findLrIds(List constraints, String lrType)
          Get a list of LRs that satisfy some set or restrictions and are of a particular type
protected  void fireResourceAdopted(DatastoreEvent e)
           
protected  void fireResourceDeleted(DatastoreEvent e)
           
protected  void fireResourceWritten(DatastoreEvent e)
           
 String getComment()
          Returns the comment displayed by the GUI for this DataStore
 String getIconName()
          Returns the name of the icon to be used when this datastore is displayed in the GUI
 LanguageResource getLr(String lrClassName, Object lrPersistenceId)
          Get a resource from the persistent store.
 List getLrIds(String lrType)
          Get a list of the IDs of LRs of a particular type that are present.
 String getLrName(Object lrId)
          Get the name of an LR from its ID.
 List getLrNames(String lrType)
          Get a list of the names of LRs of a particular type that are present.
 List getLrTypes()
          Get a list of the types of LR that are present in the data store.
 String getName()
          Returns the name of this resource
 SecurityInfo getSecurityInfo(LanguageResource lr)
          get security information for LR .
 Session getSession(Session s)
          identify user using this datastore
 File getStorageDir()
          Get method for storage URL
 String getStorageUrl()
          Get the URL for the underlying storage mechanism.
protected  File getVersionFile()
          Get a File for the protocol version file.
 int hashCode()
          Calculate a hash code based on the class and the storage dir.
 boolean isAutoSaving()
          Get the autosaving behaviour of the LR.
protected static boolean isValidProtocolVersion(String versionNumber)
          Check a version number for validity.
 boolean lockLr(LanguageResource lr)
          Try to acquire exlusive lock on a resource from the persistent store.
 void open()
          Open a connection to the data store.
protected static int random()
          Generate a random integer between 0 and 9999 for file naming.
 void removeDatastoreListener(DatastoreListener l)
          Removes a a previously registered DatastoreListener from the list listeners for this datastore
 void setAutoSaving(boolean autoSaving)
          Set method for the autosaving behaviour of the data store.
 void setName(String name)
          Sets the name of this resource
 void setSecurityInfo(LanguageResource lr, SecurityInfo si)
          set security information for LR .
 void setSession(Session s)
          identify user using this datastore
 void setStorageDir(File storageDir)
          Set method for storage URL
 void setStorageUrl(String urlString)
          Set the URL for the underlying storage mechanism.
 void sync(LanguageResource lr)
          Save: synchonise the in-memory image of the LR with the persistent image.
 String toString()
          String representation
 void unlockLr(LanguageResource lr)
          Releases the exlusive lock on a resource from the persistent store.
 
Methods inherited from class gate.util.AbstractFeatureBearer
getFeatures, setFeatures
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gate.util.FeatureBearer
getFeatures, setFeatures
 

Field Detail

name

protected String name
The name of the datastore


storageDir

protected File storageDir
The directory used for the serialised classes.


currentProtocolVersion

protected String currentProtocolVersion
The protocol version of the currently open data store


versionNumber

protected static final String versionNumber
Version number for variations in the storage protocol. Protocol versions: This variable stores the version of the current level of the protocol, NOT the level in use in the currently open data store.

See Also:
Constant Field Values

protocolVersionNumbers

protected static final String[] protocolVersionNumbers
List of valid protocol version numbers.


autoSaving

protected boolean autoSaving
Flag for autosaving behaviour.

Constructor Detail

SerialDataStore

public SerialDataStore(String storageDirUrl)
                throws PersistenceException
Construction requires a file protocol URL pointing to the storage directory used for the serialised classes. NOTE: should not be called except by GATE code.

Throws:
PersistenceException

SerialDataStore

public SerialDataStore()
Default construction. NOTE: should not be called except by GATE code.

Method Detail

setStorageDir

public void setStorageDir(File storageDir)
Set method for storage URL


getStorageDir

public File getStorageDir()
Get method for storage URL


setStorageUrl

public void setStorageUrl(String urlString)
                   throws PersistenceException
Set the URL for the underlying storage mechanism.

Specified by:
setStorageUrl in interface DataStore
Throws:
PersistenceException

getStorageUrl

public String getStorageUrl()
Get the URL for the underlying storage mechanism.

Specified by:
getStorageUrl in interface DataStore

create

public void create()
            throws PersistenceException
Create a new data store. This tries to create a directory in the local file system. If the directory already exists and is non-empty, or is a file, or cannot be created, PersistenceException is thrown.

Specified by:
create in interface DataStore
Throws:
PersistenceException

getVersionFile

protected File getVersionFile()
                       throws IOException
Get a File for the protocol version file.

Throws:
IOException

isValidProtocolVersion

protected static boolean isValidProtocolVersion(String versionNumber)
Check a version number for validity.


delete

public void delete()
            throws PersistenceException
Delete the data store.

Specified by:
delete in interface DataStore
Throws:
PersistenceException

delete

public void delete(String lrClassName,
                   Object lrPersistenceId)
            throws PersistenceException
Delete a resource from the data store.

Specified by:
delete in interface DataStore
Parameters:
lrClassName - class name of the type of resource
lrPersistenceId - a data-store specific unique identifier for the resource
Throws:
PersistenceException

adopt

public LanguageResource adopt(LanguageResource lr,
                              SecurityInfo secInfo)
                       throws PersistenceException,
                              SecurityException
Adopt a resource for persistence.

Specified by:
adopt in interface DataStore
Throws:
PersistenceException
SecurityException

open

public void open()
          throws PersistenceException
Open a connection to the data store.

Specified by:
open in interface DataStore
Throws:
PersistenceException

close

public void close()
           throws PersistenceException
Close the data store.

Specified by:
close in interface DataStore
Throws:
PersistenceException

sync

public void sync(LanguageResource lr)
          throws PersistenceException
Save: synchonise the in-memory image of the LR with the persistent image.

Specified by:
sync in interface DataStore
Throws:
PersistenceException

constructPersistenceId

protected String constructPersistenceId(String lrName)
Create a persistent store Id from the name of a resource.


getLr

public LanguageResource getLr(String lrClassName,
                              Object lrPersistenceId)
                       throws PersistenceException,
                              SecurityException
Get a resource from the persistent store. Don't use this method - use Factory.createResource with DataStore and DataStoreInstanceId parameters set instead. (Sometimes I wish Java had "friend" declarations...)

Specified by:
getLr in interface DataStore
Throws:
PersistenceException
SecurityException

getLrTypes

public List getLrTypes()
                throws PersistenceException
Get a list of the types of LR that are present in the data store.

Specified by:
getLrTypes in interface DataStore
Throws:
PersistenceException

getLrIds

public List getLrIds(String lrType)
              throws PersistenceException
Get a list of the IDs of LRs of a particular type that are present.

Specified by:
getLrIds in interface DataStore
Throws:
PersistenceException

getLrNames

public List getLrNames(String lrType)
                throws PersistenceException
Get a list of the names of LRs of a particular type that are present.

Specified by:
getLrNames in interface DataStore
Throws:
PersistenceException

getLrName

public String getLrName(Object lrId)
Get the name of an LR from its ID.

Specified by:
getLrName in interface DataStore

setAutoSaving

public void setAutoSaving(boolean autoSaving)
                   throws UnsupportedOperationException
Set method for the autosaving behaviour of the data store. NOTE: this type of datastore has no auto-save function, therefore this method throws an UnsupportedOperationException.

Specified by:
setAutoSaving in interface DataStore
Throws:
UnsupportedOperationException

isAutoSaving

public boolean isAutoSaving()
Get the autosaving behaviour of the LR.

Specified by:
isAutoSaving in interface DataStore

random

protected static int random()
Generate a random integer between 0 and 9999 for file naming.


toString

public String toString()
String representation

Overrides:
toString in class Object

hashCode

public int hashCode()
Calculate a hash code based on the class and the storage dir.

Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Equality: based on storage dir of other.

Overrides:
equals in class Object

removeDatastoreListener

public void removeDatastoreListener(DatastoreListener l)
Description copied from interface: DataStore
Removes a a previously registered DatastoreListener from the list listeners for this datastore

Specified by:
removeDatastoreListener in interface DataStore

addDatastoreListener

public void addDatastoreListener(DatastoreListener l)
Description copied from interface: DataStore
Registers a new DatastoreListener with this datastore

Specified by:
addDatastoreListener in interface DataStore

fireResourceAdopted

protected void fireResourceAdopted(DatastoreEvent e)

fireResourceDeleted

protected void fireResourceDeleted(DatastoreEvent e)

fireResourceWritten

protected void fireResourceWritten(DatastoreEvent e)

getIconName

public String getIconName()
Returns the name of the icon to be used when this datastore is displayed in the GUI

Specified by:
getIconName in interface DataStore

getComment

public String getComment()
Returns the comment displayed by the GUI for this DataStore

Specified by:
getComment in interface DataStore

canReadLR

public boolean canReadLR(Object lrID)
                  throws PersistenceException,
                         SecurityException
Checks if the user (identified by the sessionID) has read access to the LR

Specified by:
canReadLR in interface DataStore
Throws:
PersistenceException
SecurityException

canWriteLR

public boolean canWriteLR(Object lrID)
                   throws PersistenceException,
                          SecurityException
Checks if the user (identified by the sessionID) has write access to the LR

Specified by:
canWriteLR in interface DataStore
Throws:
PersistenceException
SecurityException

setName

public void setName(String name)
Sets the name of this resource

Specified by:
setName in interface NameBearer

getName

public String getName()
Returns the name of this resource

Specified by:
getName in interface NameBearer

getSecurityInfo

public SecurityInfo getSecurityInfo(LanguageResource lr)
                             throws PersistenceException
get security information for LR .

Specified by:
getSecurityInfo in interface DataStore
Throws:
PersistenceException

setSecurityInfo

public void setSecurityInfo(LanguageResource lr,
                            SecurityInfo si)
                     throws PersistenceException,
                            SecurityException
set security information for LR .

Specified by:
setSecurityInfo in interface DataStore
Throws:
PersistenceException
SecurityException

setSession

public void setSession(Session s)
                throws SecurityException
identify user using this datastore

Specified by:
setSession in interface DataStore
Throws:
SecurityException

getSession

public Session getSession(Session s)
                   throws SecurityException
identify user using this datastore

Specified by:
getSession in interface DataStore
Throws:
SecurityException

lockLr

public boolean lockLr(LanguageResource lr)
               throws PersistenceException,
                      SecurityException
Try to acquire exlusive lock on a resource from the persistent store. Always call unlockLR() when the lock is no longer needed

Specified by:
lockLr in interface DataStore
Throws:
PersistenceException
SecurityException

unlockLr

public void unlockLr(LanguageResource lr)
              throws PersistenceException,
                     SecurityException
Releases the exlusive lock on a resource from the persistent store.

Specified by:
unlockLr in interface DataStore
Throws:
PersistenceException
SecurityException

findLrIds

public List findLrIds(List constraints)
               throws PersistenceException
Get a list of LRs that satisfy some set or restrictions

Specified by:
findLrIds in interface DataStore
Throws:
PersistenceException

findLrIds

public List findLrIds(List constraints,
                      String lrType)
               throws PersistenceException
Get a list of LRs that satisfy some set or restrictions and are of a particular type

Specified by:
findLrIds in interface DataStore
Throws:
PersistenceException

filterIgnoredFileNames

protected String[] filterIgnoredFileNames(String[] fileNames)
This removes the names of all files from a list of file names for which we know that we want to ignore them. Currently, all names starting with a dot are ignored.

Parameters:
fileNames -
Returns:
the list of file names with the ignored names removed