if (recipes.size() != 0) { Iterator metIter = recipes.iterator(); while (metIter.hasNext()) { DbRecipe dbRecipe = (DbRecipe) metIter.next(); RecipeComponent mc = createRecipeComponent(dbRecipe.name, dbRecipe.cls); setRecipeComponentProperties(dbRecipe, mc); AgentComponent[] recagents = mc.getAgents(); if (recagents != null && recagents.length > 0) { agents.addAll(Arrays.asList(recagents)); } experiment.addRecipe(mc); if (!recipeNames.contains(mc.getRecipeName())) { addRecipeToWorkspace(mc, node); } } }
  private void createCMTExperiment(DefaultMutableTreeNode node,                                   String originalExperimentName,                                   String experimentName,                                   String experimentId,                                   String trialId) {//    private void createCMTExperiment(DefaultMutableTreeNode node,//                                     String originalExperimentName,//                                     String experimentName,//                                     String experimentId,//                                     String trialId,//                                     boolean isCloned) {    //    System.out.println("Creating society");    // get assembly ids for trial    ArrayList assemblyIds = getTrialAssemblyIds(experimentId, trialId);    String assemblyMatch = getAssemblyMatch(assemblyIds);    // get nodes for trial    ArrayList nodes = getNodes(trialId, assemblyMatch);    ArrayList hosts = getHosts(trialId, assemblyMatch);    CMTSociety soc = null;    if (assemblyIds.size() != 0) {      soc = new CMTSociety(assemblyIds);            soc.initProperties();    } else { // We need to create a new trial.      // Need to have the experiment id, trial id, and multiplicity      // for the call that will generate the assembly here.      System.out.println("No assemblies for: " + experimentId + " " + trialId);      return; // creating an experiment from scratch not implemented yet    }    Experiment experiment = new Experiment((String)experimentName,                                            experimentId, trialId);    // The following is ugly        setDefaultNodeArguments(experiment, assemblyMatch,                            ComponentData.SOCIETY                            + "|"                            + originalExperimentName);    //    experiment.setCloned(isCloned);    //to hold all potential agents    List agents = new ArrayList();      List recipes = checkForRecipes(trialId, experimentId);        AgentComponent[] socagents = soc.getAgents();    if (socagents!= null && socagents.length > 0) {      for (int i = 0; i < socagents.length; i++) {        AgentComponent ac = socagents[i];        setComponentProperties((ConfigurableComponent) ac, ac.getShortName(), assemblyMatch);      }      agents.addAll(Arrays.asList(socagents));    }    if (recipes.size() != 0) {      Iterator metIter = recipes.iterator();      while (metIter.hasNext()) {        DbRecipe dbRecipe = (DbRecipe) metIter.next();        RecipeComponent mc = createRecipeComponent(dbRecipe.name, dbRecipe.cls);        setRecipeComponentProperties(dbRecipe, mc);        AgentComponent[] recagents = mc.getAgents();         if (recagents != null && recagents.length > 0) {	  // Only add in agents that aren't already there	  for (int i = 0; i < recagents.length; i++) {	    if (! agents.contains(recagents[i]) )	      agents.add(recagents[i]);	  }	  //          agents.addAll(Arrays.asList(recagents));        }              experiment.addRecipe(mc);        if (!recipeNames.contains(mc.getRecipeName())) {          addRecipeToWorkspace(mc, node);        }      }    }    AgentComponent[] allagents = (AgentComponent[])agents.toArray(new AgentComponent[agents.size()]);     experiment.addSocietyComponent((SocietyComponent)soc);    // Add all Nodes.    addAgents(experiment, nodes, allagents, trialId, assemblyMatch);    // Add all Hosts.    Iterator hostIter = hosts.iterator();    while (hostIter.hasNext()) {      String hostName = (String) hostIter.next();      HostComponent hc = experiment.addHost(hostName);      setComponentProperties((ConfigurableComponent) hc, hostName, assemblyMatch);    }    mapNodesToHosts(experiment, assemblyMatch);    workspace.setSelection(addExperimentToWorkspace(experiment, node));    // if the experiment hasn't been cloned, then save it so it's runnable//     if (!isCloned) {//       experiment.saveToDb(saveToDbConflictHandler);//     }    // if the experiment is not in the database, then save it so its runnable    try {      if (!ExperimentDB.isExperimentNameInDatabase(experimentName))	experiment.saveToDb(saveToDbConflictHandler);    } catch (RuntimeException e) {      System.err.println(e);    }  }