1   /*
2    *  Copyright (c) 1998-2005, The University of Sheffield.
3    *
4    *  This file is part of GATE (see http://gate.ac.uk/), and is free
5    *  software, licenced under the GNU Library General Public License,
6    *  Version 2, June 1991 (in the distribution as file licence.html,
7    *  and also available at http://gate.ac.uk/gate/licence.html).
8    *
9    *  Valentin Tablan 29/10/2001
10   *
11   *  $Id: LanguageAnalyserPersistence.java,v 1.5 2005/01/11 13:51:37 ian Exp $
12   *
13   */
14  package gate.util.persistence;
15  
16  import gate.*;
17  import gate.creole.ResourceInstantiationException;
18  import gate.persist.PersistenceException;
19  /**
20   * Provides a persistent equivalent for {@link LanguageAnalyser}s.
21   * Adds handling of corpus and document members for PRPersistence.
22   */
23  public class LanguageAnalyserPersistence extends PRPersistence {
24    /**
25     * Populates this Persistence with the data that needs to be stored from the
26     * original source object.
27     */
28    public void extractDataFromSource(Object source)throws PersistenceException{
29      if(! (source instanceof LanguageAnalyser)){
30        throw new UnsupportedOperationException(
31                  getClass().getName() + " can only be used for " +
32                  LanguageAnalyser.class.getName() +
33                  " objects!\n" + source.getClass().getName() +
34                  " is not a " + LanguageAnalyser.class.getName());
35      }
36  
37      super.extractDataFromSource(source);
38  
39      LanguageAnalyser la = (LanguageAnalyser)source;
40      document = PersistenceManager.getPersistentRepresentation(la.getDocument());
41      corpus = PersistenceManager.getPersistentRepresentation(la.getCorpus());
42    }
43  
44    /**
45     * Creates a new object from the data contained. This new object is supposed
46     * to be a copy for the original object used as source for data extraction.
47     */
48    public Object createObject()throws PersistenceException,
49                                       ResourceInstantiationException{
50      LanguageAnalyser la = (LanguageAnalyser)super.createObject();
51      la.setCorpus((Corpus)PersistenceManager.getTransientRepresentation(corpus));
52      la.setDocument((Document)PersistenceManager.
53                               getTransientRepresentation(document));
54      return la;
55    }
56  
57  
58    protected Object corpus;
59    protected Object document;
60    static final long serialVersionUID = -4632241679877556163L;
61  }