AbstractLanguageResource.java
001 /*
002  *  AbstractLanguageResource.java
003  *
004  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
005  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006  *
007  *  This file is part of GATE (see http://gate.ac.uk/), and is free
008  *  software, licenced under the GNU Library General Public License,
009  *  Version 2, June 1991 (in the distribution as file licence.html,
010  *  and also available at http://gate.ac.uk/gate/licence.html).
011  *
012  *  Hamish Cunningham, 24/Oct/2000
013  *
014  *  $Id: AbstractLanguageResource.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015  */
016 
017 package gate.creole;
018 
019 import gate.DataStore;
020 import gate.LanguageResource;
021 import gate.persist.PersistenceException;
022 import gate.security.SecurityException;
023 
024 
025 /** A convenience implementation of LanguageResource with some default code.
026   */
027 abstract public class AbstractLanguageResource
028 extends AbstractResource implements LanguageResource
029 {
030   static final long serialVersionUID = 3320133313194786685L;
031 
032   /** Get the data store that this LR lives in. Null for transient LRs. */
033   public DataStore getDataStore() { return dataStore; }
034 
035   /** Set the data store that this LR lives in. */
036   public void setDataStore(DataStore dataStorethrows PersistenceException {
037     this.dataStore = dataStore;
038   // setDataStore(DS)
039 
040   /** Returns the persistence id of this LR, if it has been stored in
041    *  a datastore. Null otherwise.
042    */
043   public Object getLRPersistenceId(){
044     return lrPersistentId;
045   }
046 
047   /** Sets the persistence id of this LR. To be used only in the
048    *  Factory and DataStore code.
049    */
050   public void setLRPersistenceId(Object lrID){
051     this.lrPersistentId = lrID;
052   }
053 
054 
055   /** The data store this LR lives in. */
056   transient protected DataStore dataStore;
057 
058   /** The persistence ID of this LR. Only set, when dataStore is.*/
059   transient protected Object lrPersistentId = null;
060 
061 
062   /** Save: synchonise the in-memory image of the LR with the persistent
063     * image.
064     */
065   public void sync()
066     throws PersistenceException,SecurityException {
067     if(dataStore == null)
068       throw new PersistenceException("LR has no DataStore");
069 
070     dataStore.sync(this);
071   // sync()
072 
073   /** Clear the internal state of the resource
074     */
075   public void cleanup() {
076   //clear()
077 
078   /**
079    * Returns true of an LR has been modified since the last sync.
080    * Always returns false for transient LRs.
081    */
082   public boolean isModified() {return false;}
083 
084   /**
085    * Returns the parent LR of this LR.
086    * Only relevant for LRs that support shadowing. Most do not by default.
087    */
088   public LanguageResource getParent()
089     throws PersistenceException,SecurityException {
090     if(dataStore == null)
091       throw new PersistenceException("LR has no DataStore");
092     throw new UnsupportedOperationException("getParent method not " +
093                                             "supported by this LR");
094   }//getParent
095 
096   /**
097    * Sets the parent LR of this LR.
098    * Only relevant for LRs that support shadowing. Most do not by default.
099    */
100   public void setParent(LanguageResource parentLR)
101     throws PersistenceException,SecurityException {
102     if(dataStore == null)
103       throw new PersistenceException("LR has no DataStore");
104     throw new UnsupportedOperationException("setParent method not " +
105                                             "supported by this LR");
106   }//setParent
107 
108 
109 
110 // class AbstractLanguageResource