cancel
Showing results for 
Search instead for 
Did you mean: 

Differences About Parse Listeners b/w 5.11 and 5.12

gokceng1
Champ in-the-making
Champ in-the-making
Hi,
I was using 5.11 till today and I was implementing my parse listeners that way:

public class ActivitiParseListener extends AbstractBpmnParseListener {
   private ExecutionListener executionListener;

   public ActivitiParseListener(ExecutionListener executionListener) {
      this.executionListener = executionListener;
   }

   @Override
   public void parseCallActivity(Element callActivityElement, ScopeImpl scope, ActivityImpl activity) {
      activity.addExecutionListener(ExecutionListener.EVENTNAME_START, executionListener);
   }
}

with that conf:

<bean id="unittestProcessEngineConfiguration" parent="mailDisabledProcessEngineConfiguration">
      <property name="customDefaultBpmnParseHandlers">
         <list>
            <bean class="….demo.utils.ActivitiParseListener">
               <constructor-arg name="activitiExecutionListener" ref="activitiExecutionListener"/>
            </bean>
         </list>
      </property>
   </bean>

Today I've migrated project to 5.12 and changed the code like that:

public class ActivitiParseListener implements BpmnParseHandler {
   //ActivitiExecutionListener is my class
   private ActivitiExecutionListener activitiExecutionListener;

   public ActivitiParseListener(ActivitiExecutionListener activitiExecutionListener) {
      this.activitiExecutionListener = activitiExecutionListener;
   }

   @Override
   public Collection<Class<? extends BaseElement>> getHandledTypes() {
      List<Class<? extends BaseElement>> classList = new ArrayList<Class<? extends BaseElement>>();
      classList.add(CallActivity.class);
      return classList;
   }

   @Override
   public void parse(BpmnParse bpmnParse, BaseElement element) {
      bpmnParse.setListenerFactory(new SomListenerFactory(activitiExecutionListener));
   }

where SomListenerFactory is:
public class SomListenerFactory extends DefaultListenerFactory {
   //ActivitiExecutionListener is my class
   private ActivitiExecutionListener activitiExecutionListener;

   public SomListenerFactory(ActivitiExecutionListener activitiExecutionListener) {
      this.activitiExecutionListener = activitiExecutionListener;
   }

   @Override
   public ExecutionListener createDelegateExpressionExecutionListener(ActivitiListener activitiListener) {
      return activitiExecutionListener;
   }
}

with conf :

<bean id="unittestProcessEngineConfiguration" parent="mailDisabledProcessEngineConfiguration">
      <property name="customDefaultBpmnParseHandlers">
         <list>
            <bean class="….demo.utils.ActivitiParseListener">
               <constructor-arg name="activitiExecutionListener" ref="activitiExecutionListener"/>
            </bean>
         </list>
      </property>
   </bean>

Is this correct way of doing it? Also I couldn't understand the use of classes under org.activiti.engine.impl.bpmn.listener and org.activiti.engine.impl.bpmn.parser. Are they intended to be used by us, or are they just internal classes?
3 REPLIES 3

frederikherema1
Star Contributor
Star Contributor
The listener-factory is intended to be used by activiti to create an Java-object to be used for ALL listeners. So this is not the best solution.

Have you read this piece in the user guide: http://activiti.org/userguide/index.html#advanced_parseHandlers ?

You can do something similar instead with user-tasks and add a task-listener instead.

public class CustomUserTaskBpmnParseHandler extends ServiceTaskParseHandler {
 
  protected void executeParse(BpmnParse bpmnParse, ServiceTask serviceTask) {
   
    // Do the regular stuff
    super.executeParse(bpmnParse, serviceTask);
   
    // Make always async
    ActivityImpl activity = findActivity(bpmnParse, serviceTask.getId());
    activity.setAsync(true);
  }

}        
       

gokceng1
Champ in-the-making
Champ in-the-making
Hi,
I've extended org.activiti.engine.impl.bpmn.parser.handler.CallActivityParseHandler and registered it like this:


<bean id="myProcessEngineConfiguration" parent="someProcessEngineConfiguration">
  <property name="customDefaultBpmnParseHandlers">
   <list>
    <bean class="….demo.parse.CallActivityParseHandler">
     <constructor-arg name="executionListener" ref="activitiExecutionListener"/>
    </bean>
   </list>
  </property>
</bean>

It works now, thank you.

frederikherema1
Star Contributor
Star Contributor
Great, glad it helps. The Parse-handlers approach won't be changed anymore and is far more flexible than the earlier BPMNParseListeners.