@Override
  public void run() {
    Session session = this.getSession();
    session.setConvertMIME(false);
    session.setFixEnable(Fixes.APPEND_ITEM_VALUE, true);
    session.setFixEnable(Fixes.FORCE_JAVA_DATES, true);
    session.setFixEnable(Fixes.CREATE_DB, true);
    Database db = session.getDatabase("", "log.nsf");
    Document doc = db.createDocument();
    doc.replaceItemValue("form", "Events");
    doc.replaceItemValue("Server", "Test");
    Map<String, String> map = new HashMap<String, String>();
    map.put("me", "us");
    map.put("myself", "ourselves");
    map.put("I", "we");
    doc.replaceItemValue("map", map);
    doc.save();
    String unid = doc.getUniversalID();
    doc = null;
    Document docJunk = db.createDocument();
    doc = db.getDocumentByUNID(unid);
    System.out.println(doc.getNoteID());
    Object o = doc.getItemValue("map", Map.class);
    System.out.println(o.getClass().getName());
    Map<String, String> remap = (Map<String, String>) o;

    for (String key : remap.keySet()) {
      System.out.println(key + ":" + remap.get(key));
    }
    session.setConvertMIME(true);
    doc = null;
    docJunk = db.createDocument();
    doc = db.getDocumentByUNID(unid);
    Vector<Item> items = doc.getItems();
    for (Item item : items) {
      if (item.getName().equalsIgnoreCase("map")) {
        System.out.println("map: " + item.getType());
        System.out.println("map value: " + item.getText());
      }
    }
    doc.replaceItemValue("foo", "bar");
    doc.save();
    session.setConvertMIME(false);
    o = null;
    doc = null;
    docJunk = db.createDocument();
    doc = db.getDocumentByUNID(unid);
    o = doc.getItemValue("map", Map.class);
    System.out.println(o.getClass().getName());
    remap = (Map<String, String>) o;

    for (String key : remap.keySet()) {
      System.out.println(key + ":" + remap.get(key));
    }

    System.out.println("Complete");
  }
 private Document createDocument() {
   if (db == null) db = Factory.getSession().getDatabase("", "log.nsf");
   try {
     Document doc = db.createDocument();
     return doc;
   } catch (NullPointerException npe) {
     System.err.println("Cannot create demo doc. Is your server running?");
     return null;
   }
 }
  @SuppressWarnings("unused")
  @Override
  public Document createDocument(final Database db, final String doctype) {
    IDocumentDefinition def = getDocumentDefinitions().get(doctype);
    if (def == null) return null;
    Document result = db.createDocument();
    result.replaceItemValue("$$SchemaType", doctype);
    result.replaceItemValue("form", def.getName());
    Map<String, IItemDefinition> itemDefs = def.getItemDefinitions();
    for (String key : itemDefs.keySet()) {
      IItemDefinition itemDef = itemDefs.get(key);
      Item item = itemDef.createDefaultItem(result, def);
    }

    return result;
  }