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