Search in sources :

Example 11 with ModelElementInstance

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

the class AlternativeNsTest method getChildElementsByTypeForAlternativeNs.

@Test
public void getChildElementsByTypeForAlternativeNs() {
    ModelElementInstance birdo = modelInstance.getModelElementById("birdo");
    assertThat(birdo, is(notNullValue()));
    Collection<Wings> elements = birdo.getChildElementsByType(Wings.class);
    assertThat(elements.size(), is(1));
    assertThat(elements.iterator().next().getTextContent(), is("zisch"));
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) TestModelTest(org.camunda.bpm.model.xml.testmodel.TestModelTest) Test(org.junit.Test)

Example 12 with ModelElementInstance

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

the class UnknownAnimalTest method testAddUnknownAnimal.

@Test
public void testAddUnknownAnimal() {
    ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl) modelInstance;
    ModelElementType unknownAnimalType = modelInstanceImpl.registerGenericType(MODEL_NAMESPACE, "unknownAnimal");
    ModelElementType animalsType = modelInstance.getModel().getType(Animals.class);
    ModelElementType animalType = modelInstance.getModel().getType(Animal.class);
    ModelElementInstance unknownAnimal = modelInstance.newInstance(unknownAnimalType);
    assertThat(unknownAnimal).isNotNull();
    unknownAnimal.setAttributeValue("id", "new-animal", true);
    unknownAnimal.setAttributeValue("gender", "Unknown");
    unknownAnimal.setAttributeValue("species", "unknown");
    ModelElementInstance animals = modelInstance.getModelElementsByType(animalsType).iterator().next();
    List<ModelElementInstance> childElementsByType = new ArrayList<ModelElementInstance>(animals.getChildElementsByType(animalType));
    animals.insertElementAfter(unknownAnimal, childElementsByType.get(2));
    assertThat(animals.getChildElementsByType(unknownAnimalType)).hasSize(3);
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) ArrayList(java.util.ArrayList) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl) Test(org.junit.Test)

Example 13 with ModelElementInstance

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

the class UnknownAnimalTest method testReplaceChildOfUnknownAnimal.

@Test
public void testReplaceChildOfUnknownAnimal() {
    ModelElementInstance yogi = modelInstance.newInstance(flipper.getElementType());
    yogi.setAttributeValue("id", "yogi-bear", true);
    yogi.setAttributeValue("gender", "Male");
    yogi.setAttributeValue("species", "bear");
    assertThat(wanda.getChildElementsByType(flipper.getElementType())).isEmpty();
    wanda.insertElementAfter(flipper, null);
    assertThat(wanda.getChildElementsByType(flipper.getElementType())).hasSize(1);
    wanda.replaceChildElement(flipper, yogi);
    assertThat(wanda.getChildElementsByType(flipper.getElementType())).hasSize(1);
    assertThat(wanda.getChildElementsByType(flipper.getElementType()).iterator().next()).isEqualTo(yogi);
}
Also used : ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance) Test(org.junit.Test)

Example 14 with ModelElementInstance

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

the class ModelElementInstanceImpl method setUniqueChildElementByNameNs.

public void setUniqueChildElementByNameNs(ModelElementInstance newChild) {
    ModelUtil.ensureInstanceOf(newChild, ModelElementInstanceImpl.class);
    ModelElementInstanceImpl newChildElement = (ModelElementInstanceImpl) newChild;
    DomElement childElement = newChildElement.getDomElement();
    ModelElementInstance existingChild = getUniqueChildElementByNameNs(childElement.getNamespaceURI(), childElement.getLocalName());
    if (existingChild == null) {
        addChildElement(newChild);
    } else {
        replaceChildElement(existingChild, newChildElement);
    }
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

Example 15 with ModelElementInstance

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

the class ModelElementInstanceImpl method findElementToInsertAfter.

/**
 * Returns the element after which the new element should be inserted in the DOM document.
 *
 * @param elementToInsert  the new element to insert
 * @return the element to insert after or null
 */
private ModelElementInstance findElementToInsertAfter(ModelElementInstance elementToInsert) {
    List<ModelElementType> childElementTypes = elementType.getAllChildElementTypes();
    List<DomElement> childDomElements = domElement.getChildElements();
    Collection<ModelElementInstance> childElements = ModelUtil.getModelElementCollection(childDomElements, modelInstance);
    ModelElementInstance insertAfterElement = null;
    int newElementTypeIndex = ModelUtil.getIndexOfElementType(elementToInsert, childElementTypes);
    for (ModelElementInstance childElement : childElements) {
        int childElementTypeIndex = ModelUtil.getIndexOfElementType(childElement, childElementTypes);
        if (newElementTypeIndex >= childElementTypeIndex) {
            insertAfterElement = childElement;
        } else {
            break;
        }
    }
    return insertAfterElement;
}
Also used : ModelElementType(org.camunda.bpm.model.xml.type.ModelElementType) DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelElementInstance(org.camunda.bpm.model.xml.instance.ModelElementInstance)

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