@Override public boolean persistItem(Item item, boolean overwrite) throws PersistenceException { // Caveat - this method uses the *provided* uuid as an indicator of file location. This // abstracts the item contents from the target storage indicator which could be an overhead, // but it allows the system to persist vanilla items (non-qualified items) as well as fully // qualified. // // Also for sake of simplicity the persister just uses String objects from the aspects - the // non-String // objects are discarded **BAD UTH** // // For fully qualified items simply call the item name utils to get the uuid and use that as // the provided parameter to the object. // First check parameters have been setup correctly if (_uuid == null && _targetDirectory == null) { throw new PersistenceException("Persister not initialised (missing parameters)."); } // Prepare the target file String filename = this.getTargetLocation(); // If overwrite then remove the file if it exists if (overwrite) { @SuppressWarnings("unused") boolean success = this.removeItem(item); } else { if (this.itemExists(item)) { throw new PersistenceException("Overwrite disabled and item is already persisted."); } } // Debatable behaviour model - open file now, write aspects as extracted try { PrintWriter out = new PrintWriter(new FileOutputStream(filename)); // Manually map the created date as a separate field out.print("CREATED:::" + Long.toString(item.getCreationUTC()) + "\n"); // Manually store the comparitors for re-constituting the item List<String> comparitors = item.getComparitors(); StringBuffer compBuffer = null; for (String comparitor : comparitors) { if (compBuffer == null) { compBuffer = new StringBuffer("COMPARITORS:::" + comparitor); } else { compBuffer.append("," + comparitor); } } out.print(compBuffer.toString() + "\n"); // Now split the aspects and discard the non-java.util.String ones (for now, **BAD UTH**) Map<String, Object> contents = item.getContents(); for (String key : contents.keySet()) { Object value = contents.get(key); if (value.getClass().getCanonicalName().equals("java.lang.String")) { String payload = (String) value; // Convert the data to store-able String output = key + ":::" + payload + "\n"; out.print(output); } } out.close(); } catch (Exception exc) { throw new PersistenceException("File output failure due to " + exc.toString()); } return false; }