> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aseeflow.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Extension Elements

[Custom extension elements](/reference/cmmn11/custom-extensions) are a standardized way to extend the CMMN model.
The [ASEE Flow extension elements](/reference/cmmn11/custom-extensions/camunda-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.

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

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

```java theme={null}
CamundaCaseExecutionListener listener = modelInstance.newInstance(CamundaCaseExecutionListener.class);
extensionElements.getElements().add(listener);
extensionElements.getElements().remove(listener);
```

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

```java theme={null}
extensionElements.getElementsQuery().count();
extensionElements.getElementsQuery().list();
extensionElements.getElementsQuery().singleResult();
extensionElements.getElementsQuery().filterByType(CamundaCaseExecutionListener.class).singleResult();
```

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 ASEE Flow
extension elements. The extension element is added to the CMMN element and returned
so that you can set attributes or add child elements.

```java theme={null}
ModelElementInstance element = extensionElements.addExtensionElement("http://example.com/cmmn", "myExtensionElement");
CamundaCaseExecutionListener listener = extensionElements.addExtensionElement(CamundaCaseExecutionListener.class);
```
