/**
  * Reads an object from a {@link IMemento}. The memento's type (root) must equal the bean's {@link
  * Root} annotation name attribute.
  */
 static <T> T fromMemento(Class<T> clazz, IMemento memento) throws IOException {
   try {
     final StringWriter sw = new StringWriter();
     final XMLMemento m = XMLMemento.createWriteRoot(memento.getType());
     m.putMemento(memento);
     m.save(sw);
     return new Persister().read(clazz, new StringReader(sw.toString()));
   } catch (Exception e) {
     throw ExceptionUtils.wrapAs(IOException.class, e);
   }
 }
  /** Convert any {@link IMemento} to a string. */
  public static String toString(IMemento memento) {
    if (!(memento instanceof XMLMemento)) {
      XMLMemento m = XMLMemento.createWriteRoot(memento.getType());
      m.putMemento(memento);
      memento = m;
    }

    try {
      final StringWriter w = new StringWriter();
      ((XMLMemento) memento).save(w);
      return w.toString();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
 /**
  * Unregister a specific local redefinition
  *
  * @param paletteID the identifier of the palette to unregister
  */
 public static void unregisterLocalRedefinition(String paletteID) {
   XMLMemento rootMemento = getLocalRedefinitions();
   // no remove method...
   // so, creation of a new root memento, then, duplicate all entries
   // except the one to
   // delete...
   XMLMemento newRootMemento = XMLMemento.createWriteRoot(PALETTE_REDEFINITIONS);
   for (IMemento memento : rootMemento.getChildren(PALETTE_REDEFINITION)) {
     if (!memento.getString(ID).equals(paletteID)) {
       newRootMemento.putMemento(memento);
     }
   }
   // save new Memento
   saveLocalRedefinitions(newRootMemento);
 }