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