How to read custom elements in delegates

I’ve added a custom modelExtension to my processes along with Camunda’s. How can I access to my custom elements inside from my ExecutionListeners? I’ve been trying the methods from ExtensionElements but I only get null as a result every time…

Cheers, Gonzalo.

Hi,

could you provide a XML example of your custom elements and the code you tried to access them.

Cheers,
Sebastian

My model:

{
“name”: “Isyc”,
“uri”: “http://core.oncustomer.com/schema/bpmn”,
“prefix”: “isyc”,
“xml”: {
“tagAlias”: “lowerCase”
},
“associations”: [],
“types”: [
{
“name”: “AttachedCondition”,
“superClass”: [
“Element”
],
“properties”: [
{
“name”: “name”,
“type”: “String”,
“isAttr”: true
},
{
“name”: “description”,
“type”: “String”,
“isAttr”: true
}
]
},
{
“name”: “AttachedConditions”,
“superClass”: [
“Element”
],
“properties”: [
{
“name”: “values”,
“type”: “AttachedCondition”,
“isMany”: true
}
]
}
],
“enumerations”: []
}

In the execution listener I managed to access the atacchedConditions element like this:

@Override
public void notify(DelegateExecution env) throws Exception {

    ModelElementInstance conditions = ModelElementInstance conditions = env.getBpmnModelElementInstance().getExtensionElements().getUniqueChildElementByNameNs("http://core.oncustomer.com/schema/bpmn", "attachedConditions");
    ModelElementInstance condition = conditions.getUniqueChildElementByNameNs("http://core.oncustomer.com/schema/bpmn", "attachedCondition");
    String name = condition.getAttributeValueNs("http://core.oncustomer.com/schema/bpmn", "name");
    String description = condition.getAttributeValueNs("http://core.oncustomer.com/schema/bpmn", "description");


}

With that, I can access to the first condition, but I don’t know how to access to all the conditions as an array or a collection.

Hi,

I assume your XML looks something like this:

<extensionElements>
  <custom:attachedConditions>
    <custom:attachedCondition name="one" description="foo"/>
    <custom:attachedCondition name="two" description="bar"/>
  </custom:attachedConditions>
</extensionElements>

You can then use the XML Model API to access the child elements for your attachedConditions element:

String namespace = "http://core.oncustomer.com/schema/bpmn";
ExtensionElements extensionElements = flowElement.getExtensionElements();

ModelElementInstance attachedConditions = 
    extensionElements
      .getUniqueChildElementByNameNs(namespace, "attachedConditions");

List<DomElement> childElements = 
    attachedConditions
      .getDomElement()
      .getChildElements();

for (DomElement childElement : childElements) {
  String name = childElement.getAttribute("name");
  String description = childElement.getAttribute("description");
}

Or if the attachedConditions element can also have other child elements you could use internal API to register a generic type to filter by it.

String namespace = "http://core.oncustomer.com/schema/bpmn";
ExtensionElements extensionElements = flowElement.getExtensionElements();

ModelElementInstance attachedConditions = 
    extensionElements
      .getUniqueChildElementByNameNs(namespace, "attachedConditions");

ModelInstanceImpl modelInstance = 
    (ModelInstanceImpl) flowElement.getModelInstance();

ModelElementType attachedConditionType = 
    modelInstance
      .registerGenericType(namespace, "attachedCondition");

Collection<ModelElementInstance> attachedConditionList =  
    attachedConditions
     .getChildElementsByType(attachedConditionType);

for (ModelElementInstance attachedCondition : attachedConditionList) {
  String name = attachedCondition.getAttributeValue("name");
  String description = childElement.getAttribute("description");
}

Cheers,
Sebastian

Thank you so much!!

My XML looks just like that and the generic types is exactly what I was looking for.

Thanks again, that is really helpful for my project.

hellow,How do I get getflowelement and then get the name of flowelement.