Adding ModdleExtension after initialization

Hi,

I was wondering if there was a way to add moddle extensions after initializing the Modeler.

Any help is appreciated, thank you :slight_smile:

Unfortunately, this is not possible. What is your use case? Maybe it can be solved in another way.

Hi Barmac,

Thank you for your reply.

I am reading classes to get their methods and the method parameters. With this information, I would like to create an element that would display this information and would allow the user to enter their own parameters. So, if I were to do it as a ModdleExtension then the moddle would be:

{
    "name": "ExampleClass",
    "uri": "http://ExampleClass",
     "associations": [],
     "types": [
         {
              "name": "ExampleMethod",
              "extends": [
                    "bpmn:ServiceTask"
               ],
               "properties": [
                       {
                           "name": "exampleParameter1",
                           "isAttr": true,
                           "type": "Float"
                       },
                       {
                           "name": "exampleParameter2",
                           "isAttr": true,
                           "type": "String"
                        }
                ]
             }
         ],
         "prefix": "exampleClass",
         "xml": {
                "tagAlias": "lowerCase"
           }
}

I’ve already implemented the properties panel so the ModdleExtension seems the best way to go about this.

I would like to allow the user to add more classes that the program would read from and then reload. But, as you mentioned, this isn’t possible using the ModdleExtension.

Apologies for the format, I had so issues with it.

And what would you do with these dynamically created classes?

Let’s say you extend schema dynamically, e.g. add a new XML property example:parameter="eg". So the XML within your project could look like

<bpmn:serviceTask id="id" example:parameter="eg" />

However, when you save it, there will be a problem. To open the file correctly, you need the dynamically created schema. Basically, each time you add the methods as you described, you would have to share the new schema with all your users who can open the file.
Is this really what you need?

Alternative solution

How about if you implement the methods via bpmn:extensionElements? XML could look like:

<bpmn:serviceTask id="id">
  <bpmn:extensionElements>
    <example:parameter name="exampleParameter1" type="Float" />
    <example:parameter name="exampleParameter2" type="String" />
  </bpmn:extensionElements>
</bpmn:serviceTask>

This would be similar to what Camunda implements via camunda:property: camunda-bpmn-moddle/camunda.json at master · camunda/camunda-bpmn-moddle · GitHub

3 Likes

Your alternative solution looks perfect to what I want to achieve. Especially after looking at the model extension example. I am going to give this a test today and then confirm this as the best answer.

Thank you for replying so quickly to my questions :slight_smile:

1 Like