MCPcopy Create free account
hub / github.com/GateNLP/gate-core / adopt

Method adopt

src/main/java/gate/persist/SerialDataStore.java:268–313  ·  view source on GitHub ↗

Adopt a resource for persistence.

(LanguageResource lr)

Source from the content-addressed store, hash-verified

266
267 /** Adopt a resource for persistence. */
268 @Override
269 public LanguageResource adopt(LanguageResource lr)
270 throws PersistenceException {
271
272 //ignore security info
273
274 // check the LR's current DS
275 DataStore currentDS = lr.getDataStore();
276 if(currentDS == null) { // an orphan - do the adoption
277 LanguageResource res = lr;
278
279 if (lr instanceof Corpus) {
280 FeatureMap features1 = Factory.newFeatureMap();
281 features1.put("transientSource", lr);
282 try {
283 //here we create the persistent LR via Factory, so it's registered
284 //in GATE
285 res = (LanguageResource)
286 Factory.createResource("gate.corpora.SerialCorpusImpl", features1);
287 //Here the transient corpus is not deleted from the CRI, because
288 //this might not always be the desired behaviour
289 //since we chose that it is for the GUI, this functionality is
290 //now move to the 'Save to' action code in NameBearerHandle
291 } catch (gate.creole.ResourceInstantiationException ex) {
292 throw new GateRuntimeException(ex.getMessage());
293 }
294
295 }
296
297 res.setDataStore(this);
298
299 // let the world know
300 fireResourceAdopted(
301 new DatastoreEvent(this, DatastoreEvent.RESOURCE_ADOPTED, lr, null)
302 );
303 return res;
304 } else if(currentDS.equals(this)) // adopted already here
305 return lr;
306 else { // someone else's child
307 throw new PersistenceException(
308 "Can't adopt a resource which is already in a different datastore"
309 );
310 }
311
312
313 } // adopt(LR)
314
315 /** Open a connection to the data store. */
316 @Override

Callers 5

testSaveRestoreMethod · 0.95
testMultipleLrsMethod · 0.95
testDeleteMethod · 0.95
syncMethod · 0.95
generateCorpusMethod · 0.95

Calls 8

newFeatureMapMethod · 0.95
createResourceMethod · 0.95
setDataStoreMethod · 0.95
fireResourceAdoptedMethod · 0.95
getDataStoreMethod · 0.65
equalsMethod · 0.65
putMethod · 0.45
getMessageMethod · 0.45

Tested by 3

testSaveRestoreMethod · 0.76
testMultipleLrsMethod · 0.76
testDeleteMethod · 0.76