| 483 | } // constructPersistenceId |
| 484 | |
| 485 | @Override |
| 486 | public LanguageResource getLr(String lrClassName, Object lrPersistenceId) |
| 487 | throws PersistenceException,SecurityException { |
| 488 | |
| 489 | // find the subdirectory for resources of this type |
| 490 | File resourceTypeDirectory = new File(storageDir, lrClassName); |
| 491 | if( |
| 492 | (! resourceTypeDirectory.exists()) || |
| 493 | (! resourceTypeDirectory.isDirectory()) |
| 494 | ) { |
| 495 | throw new PersistenceException("Can't find " + resourceTypeDirectory); |
| 496 | } |
| 497 | |
| 498 | // create a File to representing the resource storage file |
| 499 | File resourceFile = new File(resourceTypeDirectory, lrPersistenceId.toString()); |
| 500 | if(! resourceFile.exists() || ! resourceFile.isFile()) |
| 501 | throw new PersistenceException("Can't find file " + resourceFile); |
| 502 | |
| 503 | // try and read the file and deserialise it |
| 504 | LanguageResource lr = null; |
| 505 | try { |
| 506 | InputStream is = new FileInputStream(resourceFile); |
| 507 | |
| 508 | // after 1.1 the serialised files are compressed |
| 509 | if(! currentProtocolVersion.equals("1.0")) |
| 510 | is = new GZIPInputStream(is); |
| 511 | |
| 512 | is=new BufferedInputStream(is); |
| 513 | |
| 514 | // Use an input stream that is aware of the GATE classloader |
| 515 | ObjectInputStream ois = new GateAwareObjectInputStream(is); |
| 516 | lr = (LanguageResource) ois.readObject(); |
| 517 | ois.close(); |
| 518 | } catch(IOException e) { |
| 519 | throw |
| 520 | new PersistenceException("Couldn't read file "+resourceFile+": "+e); |
| 521 | } catch(ClassNotFoundException ee) { |
| 522 | throw |
| 523 | new PersistenceException("Couldn't find class "+lrClassName+": "+ee); |
| 524 | } |
| 525 | |
| 526 | // set the dataStore property of the LR (which is transient and therefore |
| 527 | // not serialised) |
| 528 | lr.setDataStore(this); |
| 529 | lr.setLRPersistenceId(lrPersistenceId); |
| 530 | |
| 531 | if (DEBUG) Out.prln("LR read in memory: " + lr); |
| 532 | |
| 533 | return lr; |
| 534 | } // getLr(id) |
| 535 | |
| 536 | /** Get a list of the types of LR that are present in the data store. */ |
| 537 | @Override |