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.9 2001/12/05 17:51:21 kalina 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    /**
80     * Returns true of an LR has been modified since the last sync.
81     * Always returns false for transient LRs.
82     */
83    public boolean isModified() {return false;}
84  
85    /**
86     * Returns the parent LR of this LR.
87     * Only relevant for LRs that support shadowing. Most do not by default.
88     */
89    public LanguageResource getParent()
90      throws PersistenceException,SecurityException {
91      if(dataStore == null)
92        throw new PersistenceException("LR has no DataStore");
93      throw new UnsupportedOperationException("getParent method not " +
94                                              "supported by this LR");
95    }//getParent
96  
97    /**
98     * Sets the parent LR of this LR.
99     * Only relevant for LRs that support shadowing. Most do not by default.
100    */
101   public void setParent(LanguageResource parentLR)
102     throws PersistenceException,SecurityException {
103     if(dataStore == null)
104       throw new PersistenceException("LR has no DataStore");
105     throw new UnsupportedOperationException("setParent method not " +
106                                             "supported by this LR");
107   }//setParent
108 
109 
110 
111 } // class AbstractLanguageResource
112