1   /*
2    *  AbstractLanguageResource.java
3    *
4    *  Copyright (c) 1998-2005, 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.12 2005/01/11 13:51:31 ian Exp $
14   */
15  
16  package gate.creole;
17  
18  import gate.DataStore;
19  import gate.LanguageResource;
20  import gate.persist.PersistenceException;
21  import gate.security.SecurityException;
22  
23  
24  /** A convenience implementation of LanguageResource with some default code.
25    */
26  abstract public class AbstractLanguageResource
27  extends AbstractResource implements LanguageResource
28  {
29    static final long serialVersionUID = 3320133313194786685L;
30  
31    /** Get the data store that this LR lives in. Null for transient LRs. */
32    public DataStore getDataStore() { return dataStore; }
33  
34    /** Set the data store that this LR lives in. */
35    public void setDataStore(DataStore dataStore) throws PersistenceException {
36      this.dataStore = dataStore;
37    } // setDataStore(DS)
38  
39    /** Returns the persistence id of this LR, if it has been stored in
40     *  a datastore. Null otherwise.
41     */
42    public Object getLRPersistenceId(){
43      return lrPersistentId;
44    }
45  
46    /** Sets the persistence id of this LR. To be used only in the
47     *  Factory and DataStore code.
48     */
49    public void setLRPersistenceId(Object lrID){
50      this.lrPersistentId = lrID;
51    }
52  
53  
54    /** The data store this LR lives in. */
55    transient protected DataStore dataStore;
56  
57    /** The persistence ID of this LR. Only set, when dataStore is.*/
58    transient protected Object lrPersistentId = null;
59  
60  
61    /** Save: synchonise the in-memory image of the LR with the persistent
62      * image.
63      */
64    public void sync()
65      throws PersistenceException,SecurityException {
66      if(dataStore == null)
67        throw new PersistenceException("LR has no DataStore");
68  
69      dataStore.sync(this);
70    } // sync()
71  
72    /** Clear the internal state of the resource
73      */
74    public void cleanup() {
75    } //clear()
76  
77    /**
78     * Returns true of an LR has been modified since the last sync.
79     * Always returns false for transient LRs.
80     */
81    public boolean isModified() {return false;}
82  
83    /**
84     * Returns the parent LR of this LR.
85     * Only relevant for LRs that support shadowing. Most do not by default.
86     */
87    public LanguageResource getParent()
88      throws PersistenceException,SecurityException {
89      if(dataStore == null)
90        throw new PersistenceException("LR has no DataStore");
91      throw new UnsupportedOperationException("getParent method not " +
92                                              "supported by this LR");
93    }//getParent
94  
95    /**
96     * Sets the parent LR of this LR.
97     * Only relevant for LRs that support shadowing. Most do not by default.
98     */
99    public void setParent(LanguageResource parentLR)
100     throws PersistenceException,SecurityException {
101     if(dataStore == null)
102       throw new PersistenceException("LR has no DataStore");
103     throw new UnsupportedOperationException("setParent method not " +
104                                             "supported by this LR");
105   }//setParent
106 
107 
108 
109 } // class AbstractLanguageResource
110