Search in sources :

Example 1 with ModelReferenceException

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);
    }
}
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)

Example 2 with ModelReferenceException

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

Example 3 with ModelReferenceException

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

Example 4 with ModelReferenceException

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);
    }
}
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

ModelReferenceException (org.camunda.bpm.model.xml.ModelReferenceException)4 ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)4 ModelInstanceImpl (org.camunda.bpm.model.xml.impl.ModelInstanceImpl)2 ModelInstance (org.camunda.bpm.model.xml.ModelInstance)1