// Set the URI and identifier of the effigy.
effigy.uri.setURI(uri);
effigy.identifier.setExpression(uri.toString());
// Put the effigy into the directory
ModelDirectory directory = getDirectory();
effigy.setName(directory.uniqueName(entity.getName()));
effigy.setContainer(directory);
// Create a default tableau.
return createPrimaryTableau(effigy);
} else {
// If we get here, then we are looking inside a model
// that is defined within the same file as the parent,
// probably. Create a new PtolemyEffigy
// and open a tableau for it.
// Put the effigy inside the effigy of the parent,
// rather than directly into the directory.
NamedObj parent = entity.getContainer();
PtolemyEffigy parentEffigy = null;
// Find the first container above in the hierarchy that
// has an effigy.
while ((parent != null) && (parentEffigy == null)) {
parentEffigy = getEffigy(parent);
parent = parent.getContainer();
}
boolean isContainerSet = false;
if (parentEffigy != null) {
// OK, we can put it into this other effigy.
effigy.setName(parentEffigy.uniqueName(entity.getName()));
effigy.setContainer(parentEffigy);
// Set the identifier of the effigy to be that
// of the parent with the model name appended.
// Note that we add a # the first time, and
// then add . after that. So
// file:/c:/foo.xml#bar.bif is ok, but
// file:/c:/foo.xml#bar#bif is not
// If the title does not contain a legitimate
// way to reference the submodel, then the user
// is likely to look at the title and use the wrong
// value if they xml edit files by hand. (cxh-4/02)
String entityName = parentEffigy.identifier.getExpression();
String separator = "#";
if (entityName.indexOf("#") >= 0) {
separator = ".";
}
effigy.identifier.setExpression(entityName + separator
+ entity.getName());
// Set the uri of the effigy to that of
// the parent.
effigy.uri.setURI(parentEffigy.uri.getURI());
// Indicate success.
isContainerSet = true;
}
// If the above code did not find an effigy to put
// the new effigy within, then put it into the
// directory directly.
if (!isContainerSet) {
CompositeEntity directory = getDirectory();
effigy.setName(directory.uniqueName(entity.getName()));
effigy.setContainer(directory);
effigy.identifier.setExpression(entity.getFullName());
}
return createPrimaryTableau(effigy);