Search in sources :

Example 51 with ModelElementInstance

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

the class ModelInstanceImpl method getModelElementsByType.

public Collection<ModelElementInstance> getModelElementsByType(ModelElementType type) {
    Collection<ModelElementType> extendingTypes = type.getAllExtendingTypes();
    List<ModelElementInstance> instances = new ArrayList<ModelElementInstance>();
    for (ModelElementType modelElementType : extendingTypes) {
        if (!modelElementType.isAbstract()) {
            instances.addAll(modelElementType.getInstances(this));
        }
    }
    return instances;
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList)

Example 52 with ModelElementInstance

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

the class ModelElementTypeImpl method getInstances.

public Collection<ModelElementInstance> getInstances(ModelInstance modelInstance) {
    ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl) modelInstance;
    DomDocument document = modelInstanceImpl.getDocument();
    List<DomElement> elements = getElementsByNameNs(document, typeNamespace);
    List<ModelElementInstance> resultList = new ArrayList<ModelElementInstance>();
    for (DomElement element : elements) {
        resultList.add(ModelUtil.getModelElement(element, modelInstanceImpl, this));
    }
    return resultList;
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl) DomDocument(org.camunda.bpm.model.xml.instance.DomDocument)

Example 53 with ModelElementInstance

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

the class ChildElementImpl method getChild.

@SuppressWarnings("unchecked")
public T getChild(ModelElementInstance element) {
    ModelElementInstanceImpl elementInstanceImpl = (ModelElementInstanceImpl) element;
    ModelElementInstance childElement = elementInstanceImpl.getUniqueChildElementByType(childElementTypeClass);
    if (childElement != null) {
        ModelUtil.ensureInstanceOf(childElement, childElementTypeClass);
        return (T) childElement;
    } else {
        return null;
    }
}
Also used : ModelElementInstanceImpl(org.camunda.bpm.model.xml.impl.instance.ModelElementInstanceImpl) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 54 with ModelElementInstance

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

the class ElementReferenceCollectionImpl method removeReference.

@Override
protected void removeReference(ModelElementInstance referenceSourceElement, ModelElementInstance referenceTargetElement) {
    ModelElementInstance parentElement = referenceSourceElement.getParentElement();
    Collection<Source> childElementCollection = referenceSourceCollection.get(parentElement);
    childElementCollection.remove(referenceSourceElement);
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 55 with ModelElementInstance

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

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