use of org.camunda.bpm.model.xml.ModelReferenceException in project camunda-xml-model by camunda.
the class ElementReferenceImpl method setReferenceTargetElement.
public void setReferenceTargetElement(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement) {
ModelInstanceImpl modelInstance = referenceSourceParentElement.getModelInstance();
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(getReferenceSourceElementType());
setReferenceSource(referenceSourceParentElement, referenceSourceElement);
setReferenceIdentifier(referenceSourceElement, identifier);
}
}
use of org.camunda.bpm.model.xml.ModelReferenceException in project camunda-xml-model by camunda.
the class ReferenceImpl method setReferenceTargetElement.
/**
* Set the reference target model element instance
*
* @param referenceSourceElement the reference source model element instance
* @param referenceTargetElement the reference target model element instance
* @throws ModelReferenceException if element is not already added to the model
*/
public void setReferenceTargetElement(ModelElementInstance referenceSourceElement, T referenceTargetElement) {
ModelInstance modelInstance = referenceSourceElement.getModelInstance();
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 {
setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier);
}
}
use of org.camunda.bpm.model.xml.ModelReferenceException in project camunda-xml-model by camunda.
the class ReferenceImpl method getReferenceTargetElement.
/**
* Get the reference target model element instance
*
* @param referenceSourceElement the reference source model element instance
* @return the reference target model element instance or null if not set
*/
@SuppressWarnings("unchecked")
public T getReferenceTargetElement(ModelElementInstance referenceSourceElement) {
String identifier = getReferenceIdentifier(referenceSourceElement);
ModelElementInstance referenceTargetElement = referenceSourceElement.getModelInstance().getModelElementById(identifier);
if (referenceTargetElement != null) {
try {
return (T) referenceTargetElement;
} catch (ClassCastException e) {
throw new ModelReferenceException("Element " + referenceSourceElement + " references element " + referenceTargetElement + " of wrong type. " + "Expecting " + referenceTargetAttribute.getOwningElementType() + " got " + referenceTargetElement.getElementType());
}
} else {
return null;
}
}
use of org.camunda.bpm.model.xml.ModelReferenceException in project camunda-xml-model by camunda.
the class ElementReferenceCollectionImpl method performAddOperation.
protected void performAddOperation(ModelElementInstanceImpl referenceSourceParentElement, Target referenceTargetElement) {
ModelInstanceImpl modelInstance = referenceSourceParentElement.getModelInstance();
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 {
Collection<Source> referenceSourceElements = referenceSourceCollection.get(referenceSourceParentElement);
Source referenceSourceElement = modelInstance.newInstance(referenceSourceType);
referenceSourceElements.add(referenceSourceElement);
setReferenceIdentifier(referenceSourceElement, referenceTargetIdentifier);
}
}
Aggregations