cancel
Showing results for 
Search instead for 
Did you mean: 

how to map java class with activit diagram

chetan1
Champ in-the-making
Champ in-the-making
hi someone please give me the solution for mapping the java class
11 REPLIES 11

frederikherema1
Star Contributor
Star Contributor
Can you elaborate on your question? Not really clear what you're trying to do here…

chetan1
Champ in-the-making
Champ in-the-making
I have assigned a class to UserTask, and while starting a process i am getting an Exception "Couldn't Instantiate class com.demo.TestListener". I have implemented TaskListener on my class TestListener.

jbarrez
Star Contributor
Star Contributor
Is that class on the classpath?

chetan1
Champ in-the-making
Champ in-the-making
yes it is in the lib of activiti explorer war  D:\apache 7\webapps\activiti-explorer\WEB-INF\lib still gives warning class could not instantiate

jbarrez
Star Contributor
Star Contributor
mm that should do it.

Can you post your listener here? And the part of the process where you want to use it?

chetan1
Champ in-the-making
Champ in-the-making
package demo.action;

import java.util.List;

import org.activiti.engine.ActivitiException;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.bpmn.parser.FieldDeclaration;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.delegate.TaskListenerInvocation;
import org.activiti.engine.impl.util.ReflectUtil;

public class DemoClass implements TaskListener {
protected ExecutionListener executionListenerInstance;
protected TaskListener taskListenerInstance;
protected String className;
protected List<FieldDeclaration> fieldDeclarations;
/**
  *
  */
private static final long serialVersionUID = 1L;

/**
  * @see org.activiti.engine.delegate.TaskListener#notify(org.activiti.engine.delegate.DelegateTask)
  */
public DemoClass(String className, List<FieldDeclaration> fieldDeclarations) {
  this.className = className;
  this.fieldDeclarations = fieldDeclarations;
}

public DemoClass(Class<?> clazz, List<FieldDeclaration> fieldDeclarations) {
  this(clazz.getName(), fieldDeclarations);
}

@Override
public void notify(DelegateTask delegateTask) {
  System.out.println("in notify");
  delegateTask.setVariable("input", 0);
  if (taskListenerInstance == null) {
   taskListenerInstance = getTaskListenerInstance();
  }
  try {
   Context.getProcessEngineConfiguration()
     .getDelegateInterceptor()
     .handleInvocation(
       new TaskListenerInvocation(taskListenerInstance,
         delegateTask));
  } catch (Exception e) {
   throw new ActivitiException(
     "Exception while invoking TaskListener: " + e.getMessage(),
     e);
  }
}

private TaskListener getTaskListenerInstance() {
  Object delegateInstance = instantiateDelegate(className,
    fieldDeclarations);
  if (delegateInstance instanceof TaskListener) {
   return (TaskListener) delegateInstance;
  } else {
   throw new ActivitiException(delegateInstance.getClass().getName()
     + " doesn't implement " + TaskListener.class);
  }
}

public static Object instantiateDelegate(String className,
   List<FieldDeclaration> fieldDeclarations) {
  Object object = ReflectUtil.instantiate(className);
  System.out.println("object");
  // applyFieldDeclaration(fieldDeclarations, object);
  return object;
}

public void setLookupField(String str) {
  System.out.println("in lookup");
  // str.getVariable("input");
  String.valueOf(0);
}

}

jbarrez
Star Contributor
Star Contributor
THat is  not your process but the task listener. Im assuming that one is good, and it's the engine who cant find the class.

hence, can you post the process XML you use to reference this task listener?

chetan1
Champ in-the-making
Champ in-the-making
HI,
       This is my xml file attach with is post please check and reply ASAP
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
 
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" />
    <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUsername" value="root" />
    <property name="jdbcPassword" value="root" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jobExecutorActivate" value="false" />
  </bean>
</beans>

jbarrez
Star Contributor
Star Contributor
Sigh … your PROCESS XML … not your config.