| LRPersistence |

    1   /*
    2    *  Copyright (c) 1998-2001, 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 26/10/2001
    10   *
    11   *  $Id: LRPersistence.java,v 1.2 2001/10/29 17:11:26 valyt Exp $
    12   *
    13   */
    14  package gate.util.persistence;
    15
    16  import gate.*;
    17  import gate.creole.*;
    18  import gate.util.*;
    19  import gate.persist.PersistenceException;
    20
    21  import java.util.*;
    22  import java.io.*;
    23
    24  public class LRPersistence extends ResourcePersistence {
    25
    26    /**
    27     * Populates this Persistence with the data that needs to be stored from the
    28     * original source object.
    29     */
    30    public void extractDataFromSource(Object source)throws PersistenceException{
    31      //check input
    32      if(! (source instanceof LanguageResource)){
    33        throw new UnsupportedOperationException(
    34                  getClass().getName() + " can only be used for " +
    35                  LanguageResource.class.getName() +
    36                  " objects!\n" + source.getClass().getName() +
    37                  " is not a " + LanguageResource.class.getName());
    38      }
    39
    40      super.extractDataFromSource(source);
    41
    42      LanguageResource lr = (LanguageResource)source;
    43      if(lr.getDataStore() == null){
    44        dsData = null;
    45      }else{
    46        dsData = PersistenceManager.
    47                 getPersistentRepresentation(lr.getDataStore());
    48        persistenceID = lr.getLRPersistenceId();
    49      }
    50    }
    51
    52    /**
    53     * Creates a new object from the data contained. This new object is supposed
    54     * to be a copy for the original object used as source for data extraction.
    55     */
    56    public Object createObject()throws PersistenceException,
    57                                       ResourceInstantiationException{
    58      if(dsData == null) return super.createObject();
    59      else{
    60        //persistent doc
    61        initParams = PersistenceManager.getTransientRepresentation(initParams);
    62
    63        DataStore ds = (DataStore)PersistenceManager.
    64                       getTransientRepresentation(dsData);
    65        ((Map)initParams).put(DataStore.DATASTORE_FEATURE_NAME, ds);
    66        ((Map)initParams).put(DataStore.LR_ID_FEATURE_NAME, persistenceID);
    67        return super.createObject();
    68      }
    69    }
    70
    71    protected Serializable dsData;
    72    protected Object persistenceID;
    73    static final long serialVersionUID = 3541034274225534363L;
    74  }

| LRPersistence |