Adopt a resource for persistence.
(LanguageResource lr)
| 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 |