Search in sources :

Example 1 with ModelInstanceImpl

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

use of org.camunda.bpm.model.xml.impl.ModelInstanceImpl 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 3 with ModelInstanceImpl

use of org.camunda.bpm.model.xml.impl.ModelInstanceImpl in project camunda-xml-model by camunda.

the class UnknownAnimalTest method testGetUnknownAnimalByType.

@Test
public void testGetUnknownAnimalByType() {
    ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl) modelInstance;
    ModelElementType unknownAnimalType = modelInstanceImpl.registerGenericType(MODEL_NAMESPACE, "unknownAnimal");
    List<ModelElementInstance> unknownAnimals = new ArrayList<ModelElementInstance>(modelInstance.getModelElementsByType(unknownAnimalType));
    assertThat(unknownAnimals).hasSize(2);
    ModelElementInstance wanda = unknownAnimals.get(0);
    assertThat(wanda.getAttributeValue("id")).isEqualTo("wanda");
    assertThat(wanda.getAttributeValue("gender")).isEqualTo("Female");
    assertThat(wanda.getAttributeValue("species")).isEqualTo("fish");
    ModelElementInstance flipper = unknownAnimals.get(1);
    assertThat(flipper.getAttributeValue("id")).isEqualTo("flipper");
    assertThat(flipper.getAttributeValue("gender")).isEqualTo("Male");
    assertThat(flipper.getAttributeValue("species")).isEqualTo("dolphin");
}
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 4 with ModelInstanceImpl

use of org.camunda.bpm.model.xml.impl.ModelInstanceImpl in project camunda-xml-model by camunda.

the class ModelElementTypeImpl method newInstance.

public ModelElementInstance newInstance(ModelInstance modelInstance) {
    ModelInstanceImpl modelInstanceImpl = (ModelInstanceImpl) modelInstance;
    DomDocument document = modelInstanceImpl.getDocument();
    DomElement domElement = document.createElement(typeNamespace, typeName);
    return newInstance(modelInstanceImpl, domElement);
}
Also used : DomElement(org.camunda.bpm.model.xml.instance.DomElement) ModelInstanceImpl(org.camunda.bpm.model.xml.impl.ModelInstanceImpl) DomDocument(org.camunda.bpm.model.xml.instance.DomDocument)

Example 5 with ModelInstanceImpl

use of org.camunda.bpm.model.xml.impl.ModelInstanceImpl 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)

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