/// <summary>
        /// Finds all subset elements linked to the given message element and links those to the schema elements.
        /// If a subset element could not be matched, and it is in the same package as the given messageElement, then it is deleted
        /// </summary>
        /// <param name="messageElement">the message element to start from</param>
        void matchSubsetElements(UML.Classes.Kernel.Classifier messageElement)
        {
            HashSet <UML.Classes.Kernel.Classifier> subsetElements = this.getSubsetElementsfromMessage(messageElement);

            //match each subset element to a schema element
            foreach (UML.Classes.Kernel.Classifier subsetElement in subsetElements)
            {
                //get the corrsponding schema element
                EASchemaElement schemaElement = this.getSchemaElementForSubsetElement(subsetElement);
                //found a corresponding schema element
                if (schemaElement != null &&
                    shouldElementExistAsDatatype(subsetElement))
                {
                    schemaElement.matchSubsetElement(subsetElement);
                }
                else
                {
                    //if it doesn't correspond with a schema element we delete it?
                    //only if the subset element is located in the same folder as the message element
                    //and it doesn't have one of stereotypes to be ignored
                    if (subsetElement.owner.Equals(messageElement.owner) &&
                        !this.settings.ignoredStereotypes.Intersect(((UTF_EA.Element)subsetElement).stereotypeNames).Any())
                    {
                        subsetElement.delete();
                    }
                }
            }
        }
        /// <summary>
        /// Finds all subset elements linked to the given message element and links those to the schema elements.
        /// If a subset element could not be matched, and it is in the same package as the given messageElement, then it is deleted
        /// </summary>
        /// <param name="messageElement">the message element to start from</param>
        void matchSubsetElements(UML.Classes.Kernel.Classifier messageElement)
        {
            HashSet <UML.Classes.Kernel.Classifier> subsetElements = this.getSubsetElementsfromMessage(messageElement);

            //match each subset element to a schema element
            matchSubsetElements(messageElement.owningPackage, subsetElements);
        }
 /// <summary>
 /// adds the given class to the list of subset elements and then adds all related
 /// </summary>
 /// <param name="element">the Class to add</param>
 /// <param name="subsetElements">the list of subset elements</param>
 private void addToSubsetElements(UML.Classes.Kernel.Classifier element, HashSet <UML.Classes.Kernel.Classifier> subsetElements)
 {
     //add element is not already in the list
     if (element != null &&
         (element is Class || element is Enumeration || (element is DataType && !(element is PrimitiveType))) &&
         !subsetElements.Contains(element))
     {
         subsetElements.Add(element);
         //add related elements for this element
         this.addRelatedSubsetElements(element, subsetElements);
     }
 }
 /// <summary>
 /// adds all the related subset elements to the list recursively
 /// </summary>
 /// <param name="element">the element to start from </param>
 /// <param name="subsetElements">the HashSet of subset element to add to</param>
 private void addRelatedSubsetElements(UML.Classes.Kernel.Classifier element, HashSet <UML.Classes.Kernel.Classifier> subsetElements)
 {
     //follow the associations
     foreach (UTF_EA.Association association in element.getRelationships <UML.Classes.Kernel.Association>())
     {
         addToSubsetElements(association.target as UML.Classes.Kernel.Classifier, subsetElements);
     }
     //follow the attribute types
     foreach (UTF_EA.Attribute attribute in element.attributes)
     {
         addToSubsetElements(attribute.type as UML.Classes.Kernel.Classifier, subsetElements);
     }
 }
        /// <summary>
        /// gets all the subset elements for a given message element
        /// </summary>
        /// <param name="messageElement">the message element</param>
        /// <returns>all subset elements in the subset model for this message element</returns>
        private HashSet <UML.Classes.Kernel.Classifier> getSubsetElementsfromMessage(UML.Classes.Kernel.Classifier messageElement)
        {
            var subsetElements = new HashSet <UML.Classes.Kernel.Classifier>();

            this.addRelatedSubsetElements(messageElement, subsetElements);
            //we also add all classes in the package of the subset element
            foreach (var element in messageElement.owningPackage.ownedElements)
            {
                //we only do classes or enumerations
                var classElement = element as UML.Classes.Kernel.Classifier;

                this.addToSubsetElements(classElement, subsetElements);
            }
            return(subsetElements);
        }
        /// <summary>
        /// finds the Schema Element for which the given element could be the subset element
        /// </summary>
        /// <param name="subsetElement">the element to search a match for</param>
        /// <returns>the corresponding SchemaElement</returns>
        internal EASchemaElement getSchemaElementForSubsetElement(UML.Classes.Kernel.Classifier subsetElement)
        {
            EASchemaElement result = null;

            foreach (EASchemaElement schemaElement in this.elements)
            {
                if (schemaElement.name == subsetElement.name)
                {
                    //check if the subset element has a dependency to the source element of the schema
                    foreach (var dependency in subsetElement.clientDependencies)
                    {
                        if (schemaElement.sourceElement.Equals(dependency.supplier))
                        {
                            result = schemaElement;
                            break;
                        }
                    }
                }
            }
            return(result);
        }
 /// <summary>
 /// matches the given subset element with the schema element, matching attributes and association
 /// all attributes or associations that do not exist in the schema are deleted
 /// </summary>
 /// <param name="subsetElement">the subset element to match</param>
 public void matchSubsetElement(UML.Classes.Kernel.Classifier subsetElement)
 {
     //set the subset element
     this.subsetElement = subsetElement;
 }