"Could not create directory " + directory);
}
}
// Generate the code as a string.
CompositeActor container = (CompositeActor) getContainer();
String code = _generateCode(container);
// FIXME: test this code to make sure it works even if this
// director is embedded more deeply.
//Create file name relative to the toplevel NCCompositeActor.
NamedObj toplevel = _toplevelNC(); //container.toplevel();
String filename = _sanitizedFullName(toplevel);
if (container != toplevel) {
filename = filename + "_" + container.getName(toplevel);
filename = StringUtilities.sanitizeName(filename);
}
// Open file for the generated nesC code.
File writeFile = new File(directory, filename + ".nc");
if (_confirmOverwrite(writeFile)) {
// Write the generated code to the file.
FileWriter writer = null;
try {
writer = new FileWriter(writeFile);
writer.write(code);
} catch (IOException ex) {
throw new IllegalActionException(this, ex,
"Failed to open file for writing.");
} finally {
try {
writer.close();
} catch (Exception ex) {
throw new IllegalActionException(this, ex,
"Failed to close file.");
}
}
}
// Descend recursively into contained composites.
Iterator entities = container.entityList(CompositeActor.class)
.iterator();
while (entities.hasNext()) {
CompositeActor contained = (CompositeActor) entities.next();
contained.preinitialize();
}
// If this is the toplevel PtinyOSDirector, generate makefile
// and compile the generated code.
if (_isTopLevelNC()) {