System.out.println("saveToDb");
System.out.println("saveToDb: " + getExperimentName());
  public void saveToDb() {    System.out.println("saveToDb");    try {      Set writtenNodes = new HashSet();      List components = getComponents();      NodeComponent[] nodesToWrite = getNodes();      ComponentData theSoc = new GenericComponentData();      theSoc.setType(ComponentData.SOCIETY);      theSoc.setName(getExperimentName()); // this should be experiment: trial FIXME      theSoc.setClassName(""); // leave this out? FIXME      theSoc.setOwner(this); // the experiment      theSoc.setParent(null);      PopulateDb pdb =        new PopulateDb("CMT", "CSHNA", "CSMI", getExperimentName(),                       getExperimentID(), trialID, !isCloned());      setExperimentID(pdb.getExperimentId());      trialID = pdb.getTrialId();      // For each node, create a GenericComponentData, and add it to the society      for (Iterator i = hosts.iterator(); i.hasNext(); ) {        ExperimentHost host = (ExperimentHost) i.next();        ComponentData hc = new GenericComponentData();        hc.setType(ComponentData.HOST);        hc.setName(host.getShortName());        hc.setClassName("");        hc.setOwner(this);        hc.setParent(theSoc);        theSoc.addChild(hc);        NodeComponent[] nodes = host.getNodes();        for (int j = 0; j < nodes.length; j++) {          saveNodeToDb(nodes[j], hc);          writtenNodes.add(nodes[j]);        }      }      for (int i = 0; i < nodesToWrite.length; i++) {        if (writtenNodes.contains(nodesToWrite[i])) continue;        saveNodeToDb(nodesToWrite[i], theSoc);        writtenNodes.add(nodesToWrite[i]);      }      // Some components will want access to the complete set of Nodes in the society, etc.      // To get that, they must get back to the root soc object,      // and do a getOwner and go from there. Ugly.          // Now ask each component in turn to add its stuff      for (int i = 0; i < components.size(); i++) {        ComponentProperties soc = (ComponentProperties) components.get(i);        System.out.println(soc + ".addComponentData");        soc.addComponentData(theSoc);      }      pdb.setPreexistingItems(theSoc); // Record these items so additions can be detected      // then give everyone a chance to modify what they've collectively produced      for (int i = components.size() - 1; i >= 0; i--) {        ComponentProperties soc = (ComponentProperties) components.get(i);        soc.modifyComponentData(theSoc);      }      if (pdb.populate(theSoc, 1)) {        setCloned(true);        // If not cloned before, we certainly are now      }      pdb.close();    } catch (Exception sqle) {      sqle.printStackTrace();    }  }