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 theextension elements you have to call the getExtensionElements() method and,if no such child element exists, you must create one first.

    1. HumanTask humanTask = modelInstance.newInstance(HumanTask.class);
    2. ExtensionElements extensionElements = humanTask.getExtensionElements();
    3. if (extensionElements == null) {
    4. extensionElements = modelInstance.newInstance(ExtensionElements.class);
    5. humanTask.setExtensionElements(extensionElements);
    6. }
    7. Collection<ModelElementInstance> elements = extensionElements.getElements();

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

    1. CamundaCaseExecutionListener listener = modelInstance.newInstance(CamundaCaseExecutionListener.class);
    2. extensionElements.getElements().add(listener);
    3. extensionElements.getElements().remove(listener);

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

    1. extensionElements.getElementsQuery().count();
    2. extensionElements.getElementsQuery().list();
    3. extensionElements.getElementsQuery().singleResult();
    4. extensionElements.getElementsQuery().filterByType(CamundaCaseExecutionListener.class).singleResult();

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

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

    原文: https://docs.camunda.org/manual/7.9/user-guide/model-api/cmmn-model-api/extension-elements/