/// <summary> /// matches the association of the subset element with the schema associations. /// If an association cannot be matched, it is deleted. /// </summary> public void matchSubsetAssociations() { if (this.subsetElement != null) { foreach (UTF_EA.Association association in this.subsetElement.getRelationships <UML.Classes.Kernel.Association>()) { //we are only interested in the outgoing associations if (this.subsetElement.Equals(association.source)) { EASchemaAssociation matchingAssociation = this.getMatchingSchemaAssociation(association); if (matchingAssociation != null) { if (matchingAssociation.subsetAssociations == null) { matchingAssociation.subsetAssociations = new List <Association>(); } matchingAssociation.subsetAssociations.Add(association); } else { //only delete if the target does not have a stereotype in the list of ignored stereotypes or if this association does not have an ignored stereotype if (association.target.stereotypes.Count(x => this.owner.settings.ignoredStereotypes.Contains(x.name)) <= 0 && association.stereotypes.Count(x => this.owner.settings.ignoredStereotypes.Contains(x.name)) <= 0) { //no match, delete the association association.delete(); } } } } } }
/// <summary> /// returns the matching SchemaAssociation for the given Association. /// the match is made based on the tagged value sourceAssociation on the subset assocation, which references the source association fo the SchemaAssociation /// </summary> /// <param name="association">the association to match</param> /// <returns>the matching SchemaAssociation</returns> public EASchemaAssociation getMatchingSchemaAssociation(UTF_EA.Association association) { EASchemaAssociation result = null; var sourceAssociationTag = association.getTaggedValue(this.owner.settings.sourceAssociationTagName); if (sourceAssociationTag != null) { string tagReference = sourceAssociationTag.eaStringValue; foreach (EASchemaAssociation schemaAssociation in this.schemaAssociations) { //we have the same attribute if the given attribute has a tagged value //called sourceAssociation that refences the source association of the schema Association if (((UTF_EA.Association)schemaAssociation.sourceAssociation).guid == tagReference) { //if the schema association has choiceElements then the target of the association should match one of the choice elements if ((schemaAssociation.choiceElements != null && (schemaAssociation.choiceElements.Count == 0 || schemaAssociation.choiceElements.Exists(x => association.target.Equals(x.subsetElement)))) || schemaAssociation.choiceElements == null) { result = schemaAssociation; break; } } } } return(result); }
/// <summary> /// matches the association of the subset element with the schema associations. /// If an association cannot be matched, it is deleted. /// </summary> public void matchSubsetAssociations() { if (this.subsetElement != null) { foreach (UTF_EA.Association association in this.subsetElement.getRelationships <Association>()) { //tell the user what we are doing EAOutputLogger.log(this.model, this.owner.settings.outputName, "Matching relations of subset element: '" + subsetElement.name + "' to a schema element" , ((UTF_EA.ElementWrapper)subsetElement).id, LogTypeEnum.log); //we are only interested in the outgoing associations if (this.subsetElement.Equals(association.source)) { EASchemaAssociation matchingAssociation = this.getMatchingSchemaAssociation(association); if (matchingAssociation != null) { if (matchingAssociation.subsetAssociations == null) { matchingAssociation.subsetAssociations = new List <Association>(); } matchingAssociation.subsetAssociations.Add(association); } else { //only delete if the target does not have a stereotype in the list of ignored stereotypes or if this association does not have an ignored stereotype if (association.target.stereotypes.Count(x => this.owner.settings.ignoredStereotypes.Contains(x.name)) <= 0 && association.stereotypes.Count(x => this.owner.settings.ignoredStereotypes.Contains(x.name)) <= 0) { //no match, delete the association association.delete(); } } } } } }