1   /*
2    *  AbstractLanguageResource.java
3    *
4    *  Copyright (c) 1998-2001, The University of Sheffield.
5    *
6    *  This file is part of GATE (see http://gate.ac.uk/), and is free
7    *  software, licenced under the GNU Library General Public License,
8    *  Version 2, June 1991 (in the distribution as file licence.html,
9    *  and also available at http://gate.ac.uk/gate/licence.html).
10   *
11   *  Hamish Cunningham, 24/Oct/2000
12   *
13   *  $Id: AbstractLanguageResource.java,v 1.8 2001/11/13 17:10:56 marin Exp $
14   */
15  
16  package gate.creole;
17  
18  import java.util.*;
19  
20  import gate.*;
21  import gate.util.*;
22  import gate.persist.*;
23  import gate.security.SecurityException;
24  
25  
26  /** A convenience implementation of LanguageResource with some default code.
27    */
28  abstract public class AbstractLanguageResource
29  extends AbstractResource implements LanguageResource
30  {
31    static final long serialVersionUID = 3320133313194786685L;
32  
33    /** Get the data store that this LR lives in. Null for transient LRs. */
34    public DataStore getDataStore() { return dataStore; }
35  
36    /** Set the data store that this LR lives in. */
37    public void setDataStore(DataStore dataStore) throws PersistenceException {
38      this.dataStore = dataStore;
39    } // setDataStore(DS)
40  
41    /** Returns the persistence id of this LR, if it has been stored in
42     *  a datastore. Null otherwise.
43     */
44    public Object getLRPersistenceId(){
45      return lrPersistentId;
46    }
47  
48    /** Sets the persistence id of this LR. To be used only in the
49     *  Factory and DataStore code.
50     */
51    public void setLRPersistenceId(Object lrID){
52      this.lrPersistentId = lrID;
53    }
54  
55  
56    /** The data store this LR lives in. */
57    transient protected DataStore dataStore;
58  
59    /** The persistence ID of this LR. Only set, when dataStore is.*/
60    transient protected Object lrPersistentId = null;
61  
62  
63    /** Save: synchonise the in-memory image of the LR with the persistent
64      * image.
65      */
66    public void sync()
67      throws PersistenceException,SecurityException {
68      if(dataStore == null)
69        throw new PersistenceException("LR has no DataStore");
70  
71      dataStore.sync(this);
72    } // sync()
73  
74    /** Clear the internal state of the resource
75      */
76    public void cleanup() {
77    } //clear()
78  
79  } // class AbstractLanguageResource
80