Search in sources :

Example 41 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-cmmn-model by camunda.

the class ExtensionElementsImpl method addExtensionElement.

public ModelElementInstance addExtensionElement(String namespaceUri, String localName) {
    ModelElementType extensionElementType = modelInstance.registerGenericType(namespaceUri, localName);
    ModelElementInstance extensionElement = extensionElementType.newInstance(modelInstance);
    addChildElement(extensionElement);
    return extensionElement;
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 42 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-cmmn-model by camunda.

the class ExtensionElementsImpl method addExtensionElement.

public <T extends ModelElementInstance> T addExtensionElement(Class<T> extensionElementClass) {
    ModelElementInstance extensionElement = modelInstance.newInstance(extensionElementClass);
    addChildElement(extensionElement);
    return extensionElementClass.cast(extensionElement);
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 43 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.

the class ElementReferenceImpl method getReferenceTargetElement.

@SuppressWarnings("unchecked")
public Target getReferenceTargetElement(ModelElementInstanceImpl referenceSourceParentElement) {
    Source referenceSource = getReferenceSource(referenceSourceParentElement);
    if (referenceSource != null) {
        String identifier = getReferenceIdentifier(referenceSource);
        ModelElementInstance referenceTargetElement = referenceSourceParentElement.getModelInstance().getModelElementById(identifier);
        if (referenceTargetElement != null) {
            return (Target) referenceTargetElement;
        } else {
            throw new ModelException("Unable to find a model element instance for id " + identifier);
        }
    } else {
        return null;
    }
}
Also used : ModelException(org.camunda.bpm.model.xml.ModelException) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 44 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance 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 45 with ModelElementInstance

use of org.camunda.bpm.model.xml.instance.ModelElementInstance in project camunda-xml-model by camunda.

the class ModelUtil method getModelElement.

/**
 * Returns the {@link ModelElementInstanceImpl ModelElement} for a DOM element.
 * If the model element does not yet exist, it is created and linked to the DOM.
 *
 * @param domElement the child element to create a new {@link ModelElementInstanceImpl ModelElement} for
 * @return the child model element
 */
public static ModelElementInstance getModelElement(DomElement domElement, ModelInstanceImpl modelInstance) {
    ModelElementInstance modelElement = domElement.getModelElementInstance();
    if (modelElement == null) {
        ModelElementTypeImpl modelType = getModelElement(domElement, modelInstance, domElement.getNamespaceURI());
        modelElement = modelType.newInstance(modelInstance, domElement);
        domElement.setModelElementInstance(modelElement);
    }
    return modelElement;
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ModelElementTypeImpl(org.camunda.bpm.model.xml.impl.type.ModelElementTypeImpl)

Aggregations

ModelElementInstance (org.camunda.bpm.model.xml.instance.ModelElementInstance)55 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)8 ModelElementType (org.camunda.bpm.model.xml.type.ModelElementType)8 Process (org.camunda.bpm.model.bpmn.instance.Process)5 ModelInstanceImpl (org.camunda.bpm.model.xml.impl.ModelInstanceImpl)5 ModelReferenceException (org.camunda.bpm.model.xml.ModelReferenceException)4 DomElement (org.camunda.bpm.model.xml.instance.DomElement)4 List (java.util.List)3 Model (org.camunda.bpm.model.xml.Model)3 Deployment (org.camunda.bpm.engine.test.Deployment)2 Event (org.camunda.bpm.model.bpmn.instance.Event)2 SequenceFlow (org.camunda.bpm.model.bpmn.instance.SequenceFlow)2 BpmnShape (org.camunda.bpm.model.bpmn.instance.bpmndi.BpmnShape)2 Case (org.camunda.bpm.model.cmmn.instance.Case)2 PlanItem (org.camunda.bpm.model.cmmn.instance.PlanItem)2 TestModelTest (org.camunda.bpm.model.xml.testmodel.TestModelTest)2 ModelElementValidator (org.camunda.bpm.model.xml.validation.ModelElementValidator)2 ValidationResult (org.camunda.bpm.model.xml.validation.ValidationResult)2