Search in sources :

Example 6 with ModelInstanceImpl

use of org.camunda.bpm.model.xml.impl.ModelInstanceImpl 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);
    }
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ModelReferenceException(org.camunda.bpm.model.xml.ModelReferenceException) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl)

Aggregations

ModelInstanceImpl (org.camunda.bpm.model.xml.impl.ModelInstanceImpl)6 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)5 ArrayList (java.util.ArrayList)3 ModelReferenceException (org.camunda.bpm.model.xml.ModelReferenceException)2 DomDocument (org.camunda.bpm.model.xml.instance.DomDocument)2 DomElement (org.camunda.bpm.model.xml.instance.DomElement)2 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)2 Test (org.junit.Test)2