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(getReferenceSourceElementType());
setReferenceSource(referenceSourceParentElement, referenceSourceElement);
setReferenceIdentifier(referenceSourceElement, identifier);
}
}