|
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.3 2002/02/19 13:59:27 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 //LR's will have the features saved by their respective persistence 42 //mechanism 43 features = null; 44 45 LanguageResource lr = (LanguageResource)source; 46 if(lr.getDataStore() == null){ 47 dsData = null; 48 }else{ 49 dsData = PersistenceManager. 50 getPersistentRepresentation(lr.getDataStore()); 51 persistenceID = lr.getLRPersistenceId(); 52 } 53 } 54 55 /** 56 * Creates a new object from the data contained. This new object is supposed 57 * to be a copy for the original object used as source for data extraction. 58 */ 59 public Object createObject()throws PersistenceException, 60 ResourceInstantiationException{ 61 if(dsData == null) return super.createObject(); 62 else{ 63 //persistent doc 64 initParams = PersistenceManager.getTransientRepresentation(initParams); 65 66 DataStore ds = (DataStore)PersistenceManager. 67 getTransientRepresentation(dsData); 68 ((Map)initParams).put(DataStore.DATASTORE_FEATURE_NAME, ds); 69 ((Map)initParams).put(DataStore.LR_ID_FEATURE_NAME, persistenceID); 70 return super.createObject(); 71 } 72 } 73 74 protected Serializable dsData; 75 protected Object persistenceID; 76 static final long serialVersionUID = 3541034274225534363L; 77 }
|
LRPersistence |
|