Extension Elements

Custom extension elements are a standardized way to extend the CMMN model. The Camunda extension elements are fully implemented in the CMMN model API but unknown extension elements can also easily be accessed and added.

Every CMMN CmmnElement can have a child element of the type extensionElements. This element can contain all sorts of extension elements. To access the extension elements you have to call the getExtensionElements() method and, if no such child element exists, you must create one first.

HumanTask humanTask = modelInstance.newInstance(HumanTask.class);
ExtensionElements extensionElements = humanTask.getExtensionElements();
if (extensionElements == null) {
  extensionElements = modelInstance.newInstance(ExtensionElements.class);
Collection<ModelElementInstance> elements = extensionElements.getElements();

After that you can add or remove extension elements to the collection.

CamundaCaseExecutionListener listener = modelInstance.newInstance(CamundaCaseExecutionListener.class);

You can also access a query-like interface to filter the extension elements.


Additionally, there are some shortcuts to add new extension elements. You can use the namespaceUri and the elementName to add your own extension elements. Or you can use the class of a known extension element type, e.g., the Camunda extension elements. The extension element is added to the CMMN element and returned so that you can set attributes or add child elements.

ModelElementInstance element = extensionElements.addExtensionElement("http://example.com/cmmn", "myExtensionElement");
CamundaCaseExecutionListener listener = extensionElements.addExtensionElement(CamundaCaseExecutionListener.class);

On this Page: