@Override public synchronized void storeEntry(String storeName, String name, Object toStore) throws IOException { establishStoreHome(); Map<String, File> store = m_stores.get(storeName); if (store == null) { createStore(storeName); store = new LinkedHashMap<String, File>(); m_stores.put(storeName, store); } File loc = new File(m_storeHome.toString() + File.separator + storeName, name); store.put(name, loc); try { lockStore(); XMLBasicSerialization serializer = new XMLBasicSerialization(); serializer.write(loc, toStore); } catch (Exception ex) { throw new IOException(ex); } finally { unlockStore(); } }
@Override public Object getEntry(String storeName, String name, Class<?> clazz) throws IOException { establishStoreHome(); Map<String, File> store = m_stores.get(storeName); if (store != null) { if (store.containsKey(name)) { File toLoad = store.get(name); try { lockStore(); XMLBasicSerialization deserializer = new XMLBasicSerialization(); Object loaded = deserializer.read(toLoad); if (loaded.getClass().equals(clazz)) { throw new IOException("Deserialized entry (" + loaded.getClass().getName() + ") was not " + "the expected class: " + clazz.getName()); } return loaded; } catch (Exception ex) { throw new IOException(ex); } finally { unlockStore(); } } } return null; }