/// <summary> /// Gets the <see cref="IORMExtendableElement"/> that the extension <see cref="ModelElement"/> specified /// by <paramref name="extensionElement"/> is attached to. /// </summary> public static IORMExtendableElement GetExtendedElement(ModelElement extensionElement) { if (extensionElement == null) { throw new ArgumentNullException("extensionElement"); } return((IORMExtendableElement)DomainRoleInfo.GetLinkedElement(extensionElement, ORMModelElementHasExtensionElement.ExtensionDomainRoleId)); }
/// <summary> /// Gets the <see cref="IORMExtendableElement"/> that the extension <see cref="ModelError"/> specified /// by <paramref name="extensionError"/> is attached to. /// </summary> public static IORMExtendableElement GetExtendedErrorOwnerElement(ModelError extensionError) { if (extensionError == null) { throw new ArgumentNullException("extensionError"); } return((IORMExtendableElement)DomainRoleInfo.GetLinkedElement(extensionError, ORMModelElementHasExtensionModelError.ExtensionModelErrorDomainRoleId)); }
/// <summary> /// Decides whether the element that is represented by the proto element can be pasted or not. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> /// <returns>True if the element can be pasted. False otherwise.</returns> public virtual bool ModelCanMerge(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { if (protoElement != null) { DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId); foreach (DomainRoleInfo info in elementDomainInfo.AllDomainRolesPlayed) { if (!info.IsSource) { if (info.OppositeDomainRole.RolePlayer.Id == this.GetDomainClassId()) { if (this.Store.DomainDataAdvDirectory.IsEmbeddingRelationship(info.DomainRelationship.Id) && !this.Store.DomainDataAdvDirectory.IsAbstractRelationship(info.DomainRelationship.Id)) { if (info.OppositeDomainRole.Multiplicity == Multiplicity.One || info.OppositeDomainRole.Multiplicity == Multiplicity.ZeroOne) { // Check that creating a link with this path doesn't cause multiplicity overflow if (DomainRoleInfo.GetLinkedElement(this, info.OppositeDomainRole.Id) != null) { return(false); } return(true); } else { if (protoGroup.Operation == ModelProtoGroupOperation.Move) { foreach (ElementLink link in DomainRoleInfo.GetElementLinks <ElementLink>(this, info.OppositeDomainRole.Id)) { if (DomainRoleInfo.GetTargetRolePlayer(link).Id == protoElement.ElementId) { return(false); } } } return(true); } } } } } } return(false); }
IORMExtendableElement IORMExtendableElementService.ResolveExtendedErrorOwner(ModelError extensionError) { List <Guid> errorRoles = myExtensionErrorRoles; IORMExtendableElement retVal = null; if (errorRoles != null) { for (int i = 0, count = errorRoles.Count; i < count; ++i) { if (null != (retVal = DomainRoleInfo.GetLinkedElement(extensionError, errorRoles[i]) as IORMExtendableElement)) { break; } } } return(retVal); }
/// <summary> /// Adds a proto link to the current element. /// </summary> /// <param name="protoLink">Proto link representation of the element link that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> public virtual void ModelMerge(ModelProtoLink protoLink, ModelProtoGroupMerger groupMerger) { if (protoLink.IsTargetIncludedSubmodel && !String.IsNullOrEmpty(protoLink.DomainFilePath)) { // TODO ... /* * string file = protoLink.DomainFilePath; * IParentModelElement parent = this.GetDomainModelServices().ElementParentProvider.GetParentModelElement(this); * if (parent == null) * throw new System.ArgumentNullException("Parent of element " + this.ToString() + " can not be null"); * * string path = parent.DomainFilePath; * string vModellDirectory = new System.IO.FileInfo(path).DirectoryName; * string curPath = vModellDirectory + System.IO.Path.DirectorySeparatorChar + path; * * // load model * using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Set referenced model")) * { * // TODO load. * /* * global::Tum.VModellXT.VModellXTDocumentData data = global::Tum.VModellXT.VModellXTDocumentData.Instance as global::Tum.VModellXT.VModellXTDocumentData; * global::Tum.VModellXT.VModell referenceModel = data.ModelContextVModellXT.LoadInternal(file) as global::Tum.VModellXT.VModell; * model.VModell = referenceModel; */ /* * transaction.Commit(); * } * * return; */ return; } DomainRelationshipInfo linkDomainInfo = null; if (protoLink != null) { linkDomainInfo = this.Partition.DomainDataDirectory.GetDomainRelationship(protoLink.DomainClassId); } else { // try getting the linkDomainInfo from name DomainClassInfo elementDomainInfo = this.GetDomainClass(); foreach (DomainRoleInfo info in elementDomainInfo.AllDomainRolesPlayed) { if (info.IsSource) { if (!this.Store.DomainDataAdvDirectory.IsEmbeddingRelationship(info.DomainRelationship.Id) && !this.Store.DomainDataAdvDirectory.IsAbstractRelationship(info.DomainRelationship.Id)) { if (protoLink.Name == info.DomainRelationship.Name && linkDomainInfo == null) { linkDomainInfo = this.Partition.DomainDataDirectory.GetDomainRelationship(info.DomainRelationship.Id); } } } } } if (linkDomainInfo == null) { groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergeElementLinkDomainTypeMissingId, ModelValidationViolationType.Error, "Element link can not be created as the corresponding domain type is missing.")); return; } ReferenceRelationshipAdvancedInfo advancedInfo = this.Store.DomainDataAdvDirectory.GetRelationshipInfo(linkDomainInfo.Id) as ReferenceRelationshipAdvancedInfo; if (advancedInfo == null) { throw new InvalidOperationException("Relationship advanced info not found for " + linkDomainInfo.Name); } // see if this element is taking part in this role bool bTakesPart = false; ModelProtoRolePlayer sourceRolePlayer = protoLink.GetSourceRolePlayer(this.Store.DefaultPartition); ModelProtoElement sourceProtoElement = groupMerger.GetElementById(sourceRolePlayer.RolePlayerId); System.Guid mappedSourceIdTP = System.Guid.Empty; if (sourceProtoElement != null) { mappedSourceIdTP = groupMerger.GetIdMapping(sourceRolePlayer.RolePlayerId); if (mappedSourceIdTP == this.Id) { bTakesPart = true; } } if (advancedInfo.PropagatesCopyOnDeniedElement) { if (!bTakesPart && mappedSourceIdTP == System.Guid.Empty) { if (this.Id == sourceRolePlayer.RolePlayerId) { bTakesPart = true; } } } if (bTakesPart) { bool bExists = true; if (this.Store.ElementDirectory.FindElement(protoLink.ElementId) == null) { bExists = false; } if (bExists && groupMerger.ProtoGroup.Operation == ModelProtoGroupOperation.Move) { groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergeElementLinkExistsOnMoveId, ModelValidationViolationType.Error, "Element link exists although the operation = Move.")); } #region Target // see if target element was copied ModelProtoRolePlayer targetRolePlayer = protoLink.GetTargetRolePlayer(this.Store.DefaultPartition); ModelProtoElement targetProtoElement = groupMerger.GetElementById(targetRolePlayer.RolePlayerId); Guid mappedTargetId = Guid.Empty; if (targetProtoElement != null) { mappedTargetId = groupMerger.GetIdMapping(targetRolePlayer.RolePlayerId); } if (advancedInfo.PropagatesCopyOnDeniedElement) { if (mappedTargetId == System.Guid.Empty) { // try creating relationship to existing element mappedTargetId = targetRolePlayer.RolePlayerId; } } if (mappedTargetId == System.Guid.Empty) { // log warning groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergeLinkElementNotCopiedId, ModelValidationViolationType.Error, "Referenced model element was not copied. Relationship: " + linkDomainInfo.Name)); } else { ModelElement targetElement = this.Store.ElementDirectory.FindElement(mappedTargetId); if (targetElement == null) { // log error groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergeLinkElementNotFoundId, ModelValidationViolationType.Error, "Referenced model element was not found. Relationship: " + linkDomainInfo.Name)); } else { bool bContinue = true; // check cardinalities, so we don't violate them by additing a new relationship if (advancedInfo.SourceRoleMultiplicity == Multiplicity.One || advancedInfo.SourceRoleMultiplicity == Multiplicity.ZeroOne) { if (DomainRoleInfo.GetLinkedElement(this, advancedInfo.SourceRoleId) != null) { // log warning groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergeLinkCreationViolatesMultiplicityId, ModelValidationViolationType.Error, "Can not create relationship because one already exists. Relationship: " + linkDomainInfo.Name)); bContinue = false; } } if (advancedInfo.TargetRoleMultiplicity == Multiplicity.One || advancedInfo.TargetRoleMultiplicity == Multiplicity.ZeroOne) { if (DomainRoleInfo.GetLinkedElement(this, advancedInfo.TargetRoleId) != null) { // log warning groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergeLinkCreationViolatesMultiplicityId, ModelValidationViolationType.Error, "Can not create relationship because one already exists. Relationship: " + linkDomainInfo.Name)); bContinue = false; } } if (bContinue) { // create property assignments PropertyAssignment[] propertyAssignemnts = protoLink.GetPropertyAssignments(this.Store.DefaultPartition, this.GetDomainModelServices().ElementIdProvider.GenerateNewKey()); // create role assignments RoleAssignment[] roleAssignments = new RoleAssignment[2]; roleAssignments[0] = new RoleAssignment(advancedInfo.SourceRoleId, this); roleAssignments[1] = new RoleAssignment(advancedInfo.TargetRoleId, targetElement); // create new relationship this.Store.ElementFactory.CreateElementLink(linkDomainInfo, propertyAssignemnts, roleAssignments); } } } #endregion } }