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