/// <summary>
/// creates a subset of the source model with only the properties and associations used in this schema
/// </summary>
/// <param name="destinationPackage">the package to create the subset in</param>
/// <param name="copyDatatype"></param>
public void createSubsetModel(UML.Classes.Kernel.Package destinationPackage)
{
//loop the elements to create the subSetElements
foreach (EASchemaElement schemaElement in this.elements)
{
//only create subset elements for classes, not for datatypes
if (schemaElement.sourceElement is UML.Classes.Kernel.Class ||
schemaElement.sourceElement is UML.Classes.Kernel.Enumeration)
{
schemaElement.createSubsetElement(destinationPackage);
//Logger.log("after EASchema::creating single subset element");
}
else if (schemaElement.sourceElement is UML.Classes.Kernel.DataType && this.settings.copyDataTypes)
{
//if the datatypes are limited then only the ones in the list should be copied
if (!this.settings.limitDataTypes ||
this.settings.dataTypesToCopy.Contains(schemaElement.sourceElement.name))
{
schemaElement.createSubsetElement(destinationPackage);
}
}
}
//Logger.log("after EASchema::creating subsetelements");
// then loop them again to create the associations
foreach (EASchemaElement schemaElement in this.elements)
{
//only create subset elements for classes and enumerations and datatypes
if (schemaElement.sourceElement is UML.Classes.Kernel.Class ||
schemaElement.sourceElement is UML.Classes.Kernel.Enumeration ||
schemaElement.sourceElement is UML.Classes.Kernel.DataType)
{
schemaElement.createSubsetAssociations();
//Logger.log("after EASchema::creating single subset association");
// and to resolve the attributes types to subset types if required
schemaElement.createSubsetAttributes();
//Logger.log("after EASchema::createSubsetAttributes ");
schemaElement.createSubsetLiterals();
//and add a dependency from the schemaElement to the type of the attributes
schemaElement.addAttributeTypeDependencies();
//Logger.log("after EASchema::addAttributeTypeDependencies");
}
}
//then loop them the last time to remove those subset elements that don't have any attributes or associations
foreach (EASchemaElement schemaElement in this.elements)
{
if (schemaElement.subsetElement != null)
{
//reload the element because otherwise the API does not return any attributes or associations
var reloadedElement = model.getElementByGUID(schemaElement.subsetElement.uniqueID) as Classifier;
if (reloadedElement != null &&
reloadedElement.attributes.Count == 0 &&
reloadedElement.getRelationships <UML.Classes.Kernel.Association>().Count == 0 &&
reloadedElement.getDependentTypedElements <UML.Classes.Kernel.TypedElement>().Count == 0)
{
schemaElement.subsetElement.delete();
}
}
}
}