A data store based on Java serialisation.
| 62 | * A data store based on Java serialisation. |
| 63 | */ |
| 64 | public class SerialDataStore |
| 65 | extends AbstractFeatureBearer implements DataStore { |
| 66 | |
| 67 | private static final long serialVersionUID = -2109852254191554517L; |
| 68 | |
| 69 | /** Debug flag */ |
| 70 | private static final boolean DEBUG = false; |
| 71 | |
| 72 | /** The name of the datastore */ |
| 73 | protected String name; |
| 74 | |
| 75 | /** |
| 76 | * Construction requires a file protocol URL |
| 77 | * pointing to the storage directory used for |
| 78 | * the serialised classes. <B>NOTE:</B> should not be called except by |
| 79 | * GATE code. |
| 80 | */ |
| 81 | public SerialDataStore(String storageDirUrl) throws PersistenceException { |
| 82 | setStorageUrl(storageDirUrl); |
| 83 | } // construction from URL |
| 84 | |
| 85 | /** |
| 86 | * Default construction. <B>NOTE:</B> should not be called except by |
| 87 | * GATE code. |
| 88 | */ |
| 89 | public SerialDataStore() { }; |
| 90 | |
| 91 | /** |
| 92 | * The directory used for the serialised classes. |
| 93 | */ |
| 94 | protected File storageDir; |
| 95 | |
| 96 | /** Set method for storage URL */ |
| 97 | public void setStorageDir(File storageDir) { this.storageDir = storageDir; } |
| 98 | |
| 99 | /** Get method for storage URL */ |
| 100 | public File getStorageDir() { return storageDir; } |
| 101 | |
| 102 | /** Set the URL for the underlying storage mechanism. */ |
| 103 | @Override |
| 104 | public void setStorageUrl(String urlString) throws PersistenceException { |
| 105 | URL storageUrl = null; |
| 106 | try { |
| 107 | storageUrl = new URL(urlString); |
| 108 | } catch (java.net.MalformedURLException ex) { |
| 109 | throw new PersistenceException( |
| 110 | "The URL passed is not correct: " + urlString |
| 111 | ); |
| 112 | } |
| 113 | if(! storageUrl.getProtocol().equalsIgnoreCase("file")) |
| 114 | throw new PersistenceException( |
| 115 | "A serial data store needs a file URL, not " + storageUrl |
| 116 | ); |
| 117 | try { |
| 118 | this.storageDir = new File(storageUrl.toURI()); |
| 119 | } catch(URISyntaxException use){ |
| 120 | this.storageDir = Files.fileFromURL(storageUrl); |
| 121 | } |
nothing calls this directly
no outgoing calls
no test coverage detected