| DSPersistence.java |
1 /*
2 * Copyright (c) 1998-2004, 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: DSPersistence.java,v 1.5 2004/07/21 17:10:09 akshay Exp $
12 *
13 */
14 package gate.util.persistence;
15
16 import gate.DataStore;
17 import gate.Factory;
18 import gate.creole.ResourceInstantiationException;
19 import gate.persist.PersistenceException;
20
21 public class DSPersistence implements Persistence{
22
23
24 /**
25 * Populates this Persistence with the data that needs to be stored from the
26 * original source object.
27 */
28 public void extractDataFromSource(Object source)throws PersistenceException{
29 //check input
30 if(! (source instanceof DataStore)){
31 throw new UnsupportedOperationException(
32 getClass().getName() + " can only be used for " +
33 DataStore.class.getName() +
34 " objects!\n" + source.getClass().getName() +
35 " is not a " + DataStore.class.getName());
36 }
37
38 DataStore ds = (DataStore)source;
39 className = ds.getClass().getName();
40 storageUrlString = ds.getStorageUrl();
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 public Object createObject()throws PersistenceException,
48 ResourceInstantiationException{
49 return Factory.openDataStore(className, storageUrlString);
50 }
51
52 protected String className;
53 protected String storageUrlString;
54 static final long serialVersionUID = 5952924943977701708L;
55 }
56