Example #1
0
 /**
  * Update the model with MoML that was presumably generated by generateMoML().
  *
  * @param updatedMoML The moml from generateMoML()
  * @param context The context for the change. One way to get the context is by calling
  *     basicGraphFrame.getModel().
  * @return The name of the state machine that was created.
  * @exception Exception If thrown while synthesizing.
  */
 public static String updateModel(String updatedMoML, NamedObj context) throws Exception {
   // FIXME: instantiating a new parser each time could be a
   // mistake. What about leaks?  What about initialization of
   // the filters?
   MoMLParser parser = new MoMLParser();
   NamedObj model = parser.parse(updatedMoML);
   String moml = "";
   String updatedName = "";
   if (model != null) {
     // Change the name of the output module to an unused name.
     moml = model.exportMoMLPlain();
     String moduleName = "model";
     int i = 1;
     Iterator<NamedObj> containedObjects = context.containedObjectsIterator();
     while (containedObjects.hasNext()) {
       if (containedObjects.next().getName().equals(moduleName + String.valueOf(i))) {
         containedObjects = context.containedObjectsIterator();
         i++;
       }
     }
     // Change the module to the updated name, and commit changes
     updatedName = moduleName + String.valueOf(i);
     moml = moml.replaceFirst(moduleName, updatedName);
     MoMLChangeRequest request = new MoMLChangeRequest(context, context, moml);
     context.requestChange(request);
   }
   return updatedName;
 }