public virtual void setReferenceTargetElement(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement) { ModelInstanceImpl modelInstance = referenceSourceParentElement.ModelInstance; string identifier = referenceTargetAttribute.getValue(referenceTargetElement); ModelElementInstance existingElement = modelInstance.getModelElementById(identifier); if (existingElement == null || !existingElement.Equals(referenceTargetElement)) { throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first."); } else { Source referenceSourceElement = modelInstance.newInstance(ReferenceSourceElementType); setReferenceSource(referenceSourceParentElement, referenceSourceElement); setReferenceIdentifier(referenceSourceElement, identifier); } }
protected internal virtual void performAddOperation(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement) { ModelInstanceImpl modelInstance = referenceSourceParentElement.ModelInstance; string referenceTargetIdentifier = referenceTargetAttribute.getValue(referenceTargetElement); ModelElementInstance existingElement = modelInstance.getModelElementById(referenceTargetIdentifier); if (existingElement == null || !existingElement.Equals(referenceTargetElement)) { throw new ModelReferenceException("Cannot create reference to model element " + referenceTargetElement + ": element is not part of model. Please connect element to the model first."); } else { ICollection <Source> referenceSourceElements = referenceSourceCollection.get(referenceSourceParentElement); Source referenceSourceElement = modelInstance.newInstance(referenceSourceType); referenceSourceElements.Add(referenceSourceElement); setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier); } }