/// <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();
             }
         }
     }
 }
        public UML.Classes.Kernel.Classifier createSubsetElement(UML.Classes.Kernel.Package destinationPackage)
        {
            //first create the element in the destination Package
            if (this.subsetElement == null)
            {
                if (this.sourceElement is UML.Classes.Kernel.Enumeration)
                {
                    this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.Enumeration>(destinationPackage, this.wrappedSchemaType.TypeName);
                }
                else if (this.sourceElement is UML.Classes.Kernel.Class)
                {
                    this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.Class>(destinationPackage, this.wrappedSchemaType.TypeName);
                }
                else if (this.sourceElement is UML.Classes.Kernel.DataType)
                {
                    this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.DataType>(destinationPackage, this.wrappedSchemaType.TypeName);
                }
            }
            //stereotypes
            this.subsetElement.stereotypes = this.sourceElement.stereotypes;
            //notes only update them if they are empty
            if (this.subsetElement.ownedComments.Count == 0 || !this.subsetElement.ownedComments.Any(x => x.body.Length > 0))
            {
                this.subsetElement.ownedComments = this.sourceElement.ownedComments;
            }
            //save the new subset element
            ((UTF_EA.Element) this.subsetElement).save();
            //copy tagged values
            ((EASchema)this.owner).copyTaggedValues((UTF_EA.Element) this.sourceElement, (UTF_EA.Element) this.subsetElement);
            //add a trace relation from the subset element to the source element
            // check if trace already exists?
            var trace = this.subsetElement.getRelationships <UML.Classes.Dependencies.Abstraction>()
                        .FirstOrDefault(x => this.sourceElement.Equals(x.supplier)) as UML.Classes.Dependencies.Abstraction;

            if (trace == null)
            {
                trace = this.model.factory.createNewElement <UML.Classes.Dependencies.Abstraction>(this.subsetElement, string.Empty);
                trace.addStereotype(this.model.factory.createStereotype(trace, "trace"));
                trace.target = this.sourceElement;
                trace.save();
            }
            //copy the generatlizations for enumerations and for datatypes if that setting is set
            if (this.sourceElement is UML.Classes.Kernel.Enumeration ||
                this.sourceElement is UML.Classes.Kernel.DataType && this.owner.settings.copyDataTypeGeneralizations)
            {
                this.copyGeneralizations();
            }
            //return the new element
            return(this.subsetElement);
        }
示例#3
0
 public UML.Classes.Kernel.Classifier createSubsetElement(UML.Classes.Kernel.Package destinationPackage)
 {
     //first create the element in the destination Package
     if (this.subsetElement == null)
     {
         if (this.sourceElement is UML.Classes.Kernel.Enumeration)
         {
             this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.Enumeration>(destinationPackage, this.wrappedSchemaType.TypeName);
         }
         else if (this.sourceElement is UML.Classes.AssociationClasses.AssociationClass)
         {
             this.subsetElement = this.model.factory.createNewElement <UML.Classes.AssociationClasses.AssociationClass>(destinationPackage, this.wrappedSchemaType.TypeName);
         }
         else if (this.sourceElement is UML.Classes.Kernel.Class)
         {
             this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.Class>(destinationPackage, this.wrappedSchemaType.TypeName);
         }
         else if (this.sourceElement is UML.Classes.Kernel.DataType)
         {
             this.subsetElement = this.model.factory.createNewElement <UML.Classes.Kernel.DataType>(destinationPackage, this.wrappedSchemaType.TypeName);
         }
     }
     else
     {
         //report change of name of the element
         if (this.sourceElement.name != this.subsetElement.name)
         {
             EAOutputLogger.log(this.model, this.owner.settings.outputName
                                , string.Format("Element '{0}' has changed name from '{1}' since the last schema generation"
                                                , this.sourceElement.name
                                                , this.subsetElement.name)
                                , ((UTF_EA.ElementWrapper)sourceElement).id
                                , LogTypeEnum.warning);
         }
     }
     //stereotypes
     this.subsetElement.stereotypes = this.sourceElement.stereotypes;
     //alias
     //only copy alias is the alias in the subset is empty
     if (string.IsNullOrEmpty(((UTF_EA.ElementWrapper)subsetElement).alias))
     {
         ((UTF_EA.ElementWrapper)subsetElement).alias = ((UTF_EA.ElementWrapper)sourceElement).alias;
     }
     //Check if the subset alias is different from the source alias and issue warning if that is the case
     if (!string.Equals(((UTF_EA.ElementWrapper)subsetElement).alias, ((UTF_EA.ElementWrapper)sourceElement).alias))
     {
         EAOutputLogger.log(this.model, this.owner.settings.outputName
                            , string.Format("Property '{0}' has alias '{1}' in the model and a different alias '{2}' in the subset"
                                            , this.sourceElement.name
                                            , ((UTF_EA.ElementWrapper)subsetElement).alias
                                            , ((UTF_EA.ElementWrapper)sourceElement).alias)
                            , ((UTF_EA.ElementWrapper)sourceElement).id
                            , LogTypeEnum.warning);
     }
     //genlinks
     ((UTF_EA.ElementWrapper)subsetElement).genLinks = ((UTF_EA.ElementWrapper)sourceElement).genLinks;
     //notes only update them if they are empty
     if (this.subsetElement.ownedComments.Count == 0 || !this.subsetElement.ownedComments.Any(x => x.body.Length > 0))
     {
         this.subsetElement.ownedComments = this.sourceElement.ownedComments;
         if (this.owner.settings.prefixNotes &&
             this.owner.settings.prefixNotesText.Length > 0 &&
             this.subsetElement.ownedComments.Any(x => x.body.Length > 0))
         {
             foreach (var comment in subsetElement.ownedComments)
             {
                 comment.body = this.owner.settings.prefixNotesText + Environment.NewLine + comment.body;
             }
         }
     }
     //save the new subset element
     ((UTF_EA.Element) this.subsetElement).save();
     //copy tagged values
     ((EASchema)this.owner).copyTaggedValues((UTF_EA.Element) this.sourceElement, (UTF_EA.Element) this.subsetElement);
     //set reference to source element
     if (this.owner.settings.tvInsteadOfTrace)
     {
         //add a tagged value from the subset element to the source element
         ((UTF_EA.ElementWrapper) this.subsetElement).addTaggedValue(this.owner.settings.elementTagName, this.sourceElement.uniqueID);
     }
     else
     {
         //add a trace relation from the subset element to the source element
         // check if trace already exists?
         var trace = this.subsetElement.getRelationships <UML.Classes.Dependencies.Abstraction>()
                     .FirstOrDefault(x => this.sourceElement.Equals(x.supplier)) as UML.Classes.Dependencies.Abstraction;
         if (trace == null)
         {
             trace = this.model.factory.createNewElement <UML.Classes.Dependencies.Abstraction>(this.subsetElement, string.Empty);
             trace.addStereotype(this.model.factory.createStereotype(trace, "trace"));
             trace.target = this.sourceElement;
             trace.save();
         }
     }
     //return the new element
     return(this.subsetElement);
 }
 /// <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, HashSet <SBF.SchemaElement> elements)
 {
     //loop the elements to create the subSetElements
     foreach (EASchemaElement schemaElement in elements)
     {
         //tell the user what we are doing
         EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset element for : '" + schemaElement.name + "'"
                            , 0, LogTypeEnum.log);
         //do not copy elements that are shared
         if (!schemaElement.isShared)
         {
             //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 elements)
     {
         if (!schemaElement.isShared)
         {
             //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)
             {
                 //tell the user what we are doing
                 EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset associations for: '" + schemaElement.name + "'"
                                    , 0, LogTypeEnum.log);
                 schemaElement.createSubsetAssociations();
                 //Logger.log("after EASchema::creating single subset association");
                 //tell the user what we are doing
                 EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset attributes for: '" + schemaElement.name + "'"
                                    , 0, LogTypeEnum.log);
                 // and to resolve the attributes types to subset types if required
                 schemaElement.createSubsetAttributes();
                 //tell the user what we are doing
                 EAOutputLogger.log(this.model, this.settings.outputName, "Creating subset literals for: '" + schemaElement.name + "'"
                                    , 0, LogTypeEnum.log);
                 //Logger.log("after EASchema::createSubsetAttributes ");
                 schemaElement.createSubsetLiterals();
                 //clean up attribute type dependencies we don't need anymore
                 schemaElement.cleanupAttributeDependencies();
                 if (!this.settings.dontCreateAttributeDependencies)
                 {
                     //tell the user what we are doing
                     EAOutputLogger.log(this.model, this.settings.outputName, "Creating attribute depencendies for: '" + schemaElement.name + "'"
                                        , 0, LogTypeEnum.log);
                     //and add a dependency from the schemaElement to the type of the attributes
                     schemaElement.addAttributeTypeDependencies();
                 }
                 //order the attributes
                 if (!this.settings.keepOriginalAttributeOrder &&
                     !this.settings.setAttributeOrderZero &&
                     !(this.settings.orderAssociationsAlphabetically && this.settings.orderAssociationsAmongstAttributes))
                 {
                     schemaElement.orderAttributes();
                 }
                 //order the associations
                 if (this.settings.orderAssociationsAlphabetically)
                 {
                     //tell the user what we are doing
                     EAOutputLogger.log(this.model, this.settings.outputName, "Ordering associations for: '" + schemaElement.name + "'"
                                        , 0, LogTypeEnum.log);
                     //and add a dependency from the schemaElement to the type of the attributes
                     schemaElement.orderAssociationsAlphabetically();
                 }
                 //Logger.log("after EASchema::addAttributeTypeDependencies");
                 //tell the user what we are doing
                 EAOutputLogger.log(this.model, this.settings.outputName, "Creating generalizations for: '" + schemaElement.name + "'"
                                    , 0, LogTypeEnum.log);
                 //add generalizations if both elements are in the subset
                 schemaElement.addGeneralizations();
             }
         }
     }
     //then loop them againe to remove those subset elements that don't have any attributes or associations
     // or generalizations, or are used as type
     if (this.settings.deleteUnusedSchemaElements)
     {
         foreach (EASchemaElement schemaElement in elements)
         {
             if (schemaElement.subsetElement != null)
             {
                 //remove those subset elements that don't have any attributes or associations
                 //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.Any() &&
                     !reloadedElement.getRelationships <UML.Classes.Kernel.Association>().Any() &&
                     !reloadedElement.getRelationships <UML.Classes.Kernel.Generalization>().Any() &&
                     !reloadedElement.getDependentTypedElements <UML.Classes.Kernel.TypedElement>().Any() &&
                     (reloadedElement is TSF_EA.ElementWrapper && !((TSF_EA.ElementWrapper)reloadedElement).primitiveParentNames.Any()))
                 {
                     //tell the user what we are doing
                     EAOutputLogger.log(this.model, this.settings.outputName, "Deleting subset element for: '" + schemaElement.name + "'"
                                        , 0, LogTypeEnum.log);
                     schemaElement.subsetElement.delete();
                 }
             }
         }
     }
     //then synchronize the tagged values where needed
     synchronizeTaggedValues();
     //save the new schema contents to the destination package
     this.saveSchemaContent(destinationPackage);
 }