Doc - update create model api sample code

XMLWordPrintable

      In https://docs.camunda.org/manual/latest/user-guide/model-api/bpmn-model-api/create-a-model/, the createElement() is using modelInstance object which is not visible inside this method. Instead it should use passed parameter i.e. parentElement to retrieve the Model Instance.

      Existing Sample code to create an element:

      protected <T extends BpmnModelElementInstance> T createElement(BpmnModelElementInstance parentElement, String id, Class<T> elementClass) {
      		T element = modelInstance.newInstance(elementClass);
      		element.setAttributeValue("id", id, true);
      		parentElement.addChildElement(element);
      		return element;
      	}
       

      Updated code should look like:

      protected static <T extends BpmnModelElementInstance> T createElement(BpmnModelElementInstance parentElement, String id, Class<T> elementClass) {
      		T element = parentElement.getModelInstance().newInstance(elementClass);
      		element.setAttributeValue("id", id, true);
      		parentElement.addChildElement(element);
      		return element;
      	}
       

            Assignee:
            Unassigned
            Reporter:
            Garima Yadav
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: