ConditionalControllerPersistence.java
01 package gate.util.persistence;
02 
03 import gate.creole.ConditionalController;
04 import gate.creole.ResourceInstantiationException;
05 import gate.creole.RunningStrategy;
06 import gate.persist.PersistenceException;
07 
08 import java.io.Serializable;
09 import java.util.ArrayList;
10 import java.util.Collection;
11 /**
12  * Persistence handler for {@link gate.creole.ConditionalController}s
13  */
14 
15 public class ConditionalControllerPersistence extends ControllerPersistence {
16   /**
17    * Populates this Persistence with the data that needs to be stored from the
18    * original source object.
19    */
20   @Override
21   public void extractDataFromSource(Object source)throws PersistenceException{
22     if((source instanceof ConditionalController)){
23       throw new UnsupportedOperationException(
24                 getClass().getName() " can only be used for " +
25                 ConditionalController.class.getName() +
26                 " objects!\n" + source.getClass().getName() +
27                 " is not a " + ConditionalController.class.getName());
28     }
29     super.extractDataFromSource(source);
30 
31     ConditionalController controller = (ConditionalController)source;
32 
33     /*strategiesList = new ArrayList<RunningStrategy>(controller.getRunningStrategies().size());
34 
35     Iterator<RunningStrategy> stratIter = controller.getRunningStrategies().iterator();
36     while(stratIter.hasNext()) ((List)strategiesList).add(stratIter.next());*/
37     strategiesList = new ArrayList<RunningStrategy>(controller.getRunningStrategies());
38 
39     strategiesList = PersistenceManager.
40                      getPersistentRepresentation(strategiesList);
41   }
42 
43   /**
44    * Creates a new object from the data contained. This new object is supposed
45    * to be a copy for the original object used as source for data extraction.
46    */
47   @SuppressWarnings("unchecked")
48   @Override
49   public Object createObject()throws PersistenceException,
50                                      ResourceInstantiationException{
51     ConditionalController controller =
52       (ConditionalController)super.createObject();
53     controller.setRunningStrategies(
54       (Collection<RunningStrategy>)PersistenceManager.getTransientRepresentation(
55             strategiesList,resourceName,initParamOverrides));
56     return controller;
57   }
58   protected Serializable strategiesList;
59 
60   /**
61    * Serialisation ID
62    */
63   static final long serialVersionUID = -746291109981304574L;
64 }