/// <summary> /// Adds information about attribure <c>att</c> to <c>entity</c> /// </summary> /// <param name="entity">ProfileElement to which attribute is being added</param> /// <param name="att">CAttribute contains information about attribute</param> private void addAttributeToElement(ProfileElement entity, CAttribute att, CClass modelClass) { ProfileElement newProperty = new ProfileElement(); newProperty.URI = att.name; newProperty.DataType = att.type; if (ProfileElementStereotype.StereotypeEnumeration.Equals(modelClass.stereotype)) { newProperty.DataType = "int"; newProperty.TypeAsEnumValue = ProfileElementTypes.EnumerationElement; entity.AddToMyEnumerationMembers(newProperty); } else { newProperty.TypeAsEnumValue = ProfileElementTypes.Property; if (!newProperty.IsPropertyDataTypeSimple) { List <ProfileElement> list = new List <ProfileElement>(); list.AddRange(profile.GetAllProfileElementsOfType(ProfileElementTypes.Class)); list.AddRange(predefined); list.AddRange(newPredefined); //if it is not simple, then it is a reference in profile, or another missing one? foreach (ProfileElement type in list) { if (type.UniqueName.Equals(att.type)) { //if its from profile, add needed references newProperty.DataTypeAsComplexObject = type; break; } } if (newProperty.DataTypeAsComplexObject == null) { //not found so it has to be added in next iteration //create flawed element so that it can be found //flawed in a way that it only has URI ProfileElement newElement = new ProfileElement(); newElement.URI = att.type; newPredefined.Add(newElement); newProperty.DataTypeAsComplexObject = newElement; } } entity.AddToMyProperties(newProperty); } }
private void ProcessProfile() { if (profile.ProfileMap != null) { List <ProfileElement> moveFromUnknownToEnumElement = new List <ProfileElement>(); foreach (ProfileElementTypes type in profile.ProfileMap.Keys) { List <ProfileElement> list = profile.ProfileMap[type]; foreach (ProfileElement element in list) { switch (type) { case ProfileElementTypes.ClassCategory: { //// search for classes of class categories if ((belongingMap != null) && (belongingMap.ContainsKey(element.URI))) { Stack <ProfileElement> stack = belongingMap[element.URI]; ProfileElement classInPackage; while (stack.Count > 0) { classInPackage = stack.Pop(); element.AddToMembersOfClassCategory(classInPackage); classInPackage.BelongsToCategoryAsObject = element; } } break; } case ProfileElementTypes.Class: { if (element.SubClassOf != null) { ProfileElement uppclass = profile.FindProfileElementByUri(element.SubClassOf); element.SubClassOfAsObject = uppclass; if (uppclass != null) { uppclass.AddToMySubclasses(element); } } //// search for attributes of class and classCategory of class if ((belongingMap != null) && (belongingMap.ContainsKey(element.URI))) { Stack <ProfileElement> stack = belongingMap[element.URI]; ProfileElement property; while (stack.Count > 0) { property = stack.Pop(); element.AddToMyProperties(property); property.DomainAsObject = element; } } break; } case ProfileElementTypes.Property: { if (!element.IsPropertyDataTypeSimple) { element.DataTypeAsComplexObject = profile.FindProfileElementByUri(element.DataType); } if (!string.IsNullOrEmpty(element.Range)) { element.RangeAsObject = profile.FindProfileElementByUri(element.Range); } if (!string.IsNullOrEmpty(element.InverseRoleName)) { element.InverseRoleAsObject = profile.FindProfileElementByUri(element.InverseRoleName); } if (!string.IsNullOrEmpty(element.Name) && (Char.IsUpper(element.Name[0])) && (!element.HasStereotype(ProfileElementStereotype.StereotypeByReference))) { element.IsExpectedToContainLocalClass = true; if (element.RangeAsObject != null) { element.RangeAsObject.IsExpectedAsLocal = true; } } break; } case ProfileElementTypes.Unknown: { ProfileElement enumElement = profile.FindProfileElementByUri(element.Type); if (enumElement != null) { element.EnumerationObject = enumElement; element.TypeAsEnumValue = ProfileElementTypes.EnumerationElement; enumElement.AddToMyEnumerationMembers(element); moveFromUnknownToEnumElement.Add(element); } break; } } } } if (moveFromUnknownToEnumElement.Count > 0) { List <ProfileElement> unknownsList = null; List <ProfileElement> enumerationElementsList = null; profile.ProfileMap.TryGetValue(ProfileElementTypes.Unknown, out unknownsList); profile.ProfileMap.TryGetValue(ProfileElementTypes.EnumerationElement, out enumerationElementsList); if (unknownsList != null) { if (enumerationElementsList == null) { enumerationElementsList = new List <ProfileElement>(); } foreach (ProfileElement movingEl in moveFromUnknownToEnumElement) { unknownsList.Remove(movingEl); enumerationElementsList.Add(movingEl); } profile.ProfileMap.Remove(ProfileElementTypes.Unknown); if (unknownsList.Count > 0) { profile.ProfileMap.Add(ProfileElementTypes.Unknown, unknownsList); } profile.ProfileMap.Remove(ProfileElementTypes.EnumerationElement); if (enumerationElementsList.Count > 0) { enumerationElementsList.Sort(CIMComparer.ProfileElementComparer); profile.ProfileMap.Add(ProfileElementTypes.EnumerationElement, enumerationElementsList); } } } } }