SerialAnalyserControllerPersistence.java
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: SerialAnalyserControllerPersistence.java 12006 2009-12-01 17:24:28Z thomas_heitz $
13  *
14  */
15 package gate.util.persistence;
16 
17 import gate.Corpus;
18 import gate.creole.ResourceInstantiationException;
19 import gate.creole.SerialAnalyserController;
20 import gate.persist.PersistenceException;
21 /**
22  * Persistence handler for {@link SerialAnalyserController}.
23  * Adds handling of the corpus memeber to the {@link ControllerPersistence}
24  * class
25  */
26 
27 public class SerialAnalyserControllerPersistence extends ControllerPersistence {
28   /**
29    * Populates this Persistence with the data that needs to be stored from the
30    * original source object.
31    */
32   public void extractDataFromSource(Object source)throws PersistenceException{
33     if((source instanceof SerialAnalyserController)){
34       throw new UnsupportedOperationException(
35                 getClass().getName() " can only be used for " +
36                 SerialAnalyserController.class.getName() +
37                 " objects!\n" + source.getClass().getName() +
38                 " is not a " + SerialAnalyserController.class.getName());
39     }
40 
41     super.extractDataFromSource(source);
42 
43     SerialAnalyserController sac = (SerialAnalyserController)source;
44     corpus = PersistenceManager.getPersistentRepresentation(sac.getCorpus());
45   }
46 
47   /**
48    * Creates a new object from the data contained. This new object is supposed
49    * to be a copy for the original object used as source for data extraction.
50    */
51   public Object createObject()throws PersistenceException,
52                                      ResourceInstantiationException{
53     SerialAnalyserController sac = (SerialAnalyserController)
54                                   super.createObject();
55     sac.setCorpus((Corpus)PersistenceManager.getTransientRepresentation(corpus));
56     return sac;
57   }
58   protected Object corpus;
59   static final long serialVersionUID = -4116973147963269225L;
60 }