Java Code Examples for org.camunda.bpm.model.xml.instance.ModelElementInstance#setAttributeValue()

The following examples show how to use org.camunda.bpm.model.xml.instance.ModelElementInstance#setAttributeValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnknownAnimalTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: AttributeImpl.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void setValue(ModelElementInstance modelElement, T value, boolean withReferenceUpdate) {
  String xmlValue = convertModelValueToXmlValue(value);
  if(namespaceUri == null) {
    modelElement.setAttributeValue(attributeName, xmlValue,
            isIdAttribute, withReferenceUpdate);
  } else {
    modelElement.setAttributeValueNs(namespaceUri, attributeName,
            xmlValue, isIdAttribute, withReferenceUpdate);
  }
}
 
Example 3
Source File: UnknownAnimalTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 4
Source File: UriElementReferenceImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
protected void setReferenceIdentifier(ModelElementInstance referenceSourceElement, String referenceIdentifier) {
  // TODO: implement something more robust (CAM-4028)
  referenceSourceElement.setAttributeValue("href", "#" + referenceIdentifier);
}
 
Example 5
Source File: UriElementReferenceCollectionImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
@Override
protected void setReferenceIdentifier(ModelElementInstance referenceSourceElement, String referenceIdentifier) {
  // TODO: implement something more robust (CAM-4028)
  referenceSourceElement.setAttributeValue("href", "#" + referenceIdentifier);
}