package com.mossle.bpm.delegate;

import org.activiti.bpmn.model.ActivitiListener;
import org.activiti.bpmn.model.ImplementationType;
import org.activiti.bpmn.model.UserTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.bpmn.parser.BpmnParse;
import org.activiti.engine.impl.bpmn.parser.handler.UserTaskParseHandler;
import org.activiti.engine.impl.task.TaskDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DelegateBPMNParserHandler extends UserTaskParseHandler {
    private static Logger logger = LoggerFactory
            .getLogger(DelegateBPMNParserHandler.class);

    
    protected void executeParse(BpmnParse bpmnParse, UserTask userTask) {
    	 logger.info("bpmnParse : {}, userTask : {}", bpmnParse, userTask);
		super.executeParse(bpmnParse, userTask);
		TaskDefinition taskDefinition = (TaskDefinition) bpmnParse.getCurrentActivity().getProperty(PROPERTY_TASK_DEFINITION);
		ActivitiListener activitiListener = new ActivitiListener();
		activitiListener.setEvent(TaskListener.EVENTNAME_CREATE);
		activitiListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
		activitiListener.setImplementation("#{delegateTaskListener}");
		taskDefinition.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, bpmnParse.getListenerFactory().createDelegateExpressionTaskListener(activitiListener));
	}
    
}

@@ -25,17 +25,19 @@
 elegate;
-%0A
+%0D%0A%0D
 %0Aimport 
@@ -69,32 +69,33 @@
 ctivitiListener;
+%0D
 %0Aimport org.acti
@@ -129,16 +129,17 @@
 ionType;
+%0D
 %0Aimport 
@@ -171,16 +171,17 @@
 serTask;
+%0D
 %0Aimport 
@@ -222,16 +222,17 @@
 istener;
+%0D
 %0Aimport 
@@ -278,16 +278,17 @@
 mnParse;
+%0D
 %0Aimport 
@@ -353,16 +353,17 @@
 Handler;
+%0D
 %0Aimport 
@@ -407,16 +407,17 @@
 inition;
+%0D
 %0Aimport 
@@ -433,16 +433,17 @@
 .Logger;
+%0D
 %0Aimport 
@@ -466,17 +466,19 @@
 Factory;
-%0A
+%0D%0A%0D
 %0Apublic 
@@ -539,16 +539,17 @@
 andler %7B
+%0D
 %0A    pri
@@ -589,16 +589,17 @@
 rFactory
+%0D
 %0A       
@@ -651,14 +651,17 @@
 ss);
-%0A
+%0D%0A%0D
 %0A    
+%0D
 %0A   
@@ -730,16 +730,17 @@
 rTask) %7B
+%0D
 %0A    %09 l
@@ -804,16 +804,17 @@
 erTask);
+%0D
 %0A%09%09super
@@ -848,16 +848,17 @@
 erTask);
+%0D
 %0A%09%09TaskD
@@ -970,16 +970,17 @@
 NITION);
+%0D
 %0A%09%09Activ
@@ -1033,16 +1033,17 @@
 tener();
+%0D
 %0A%09%09activ
@@ -1090,16 +1090,21 @@
 AME_
-CREATE
+ASSIGNMENT
 );
+%0D
 %0A%09%09a
@@ -1200,16 +1200,17 @@
 ESSION);
+%0D
 %0A%09%09activ
@@ -1266,16 +1266,17 @@
 ener%7D%22);
+%0D
 %0A%09%09taskD
@@ -1427,15 +1427,19 @@
 r));
+%0D
 %0A%09%7D
+%0D
 %0A    
+%0D
 %0A%7D
+%0D
 %0A

set event type unanimous