[jbpm-commits] JBoss JBPM SVN: r3742 - jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/xml.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Feb 3 02:52:46 EST 2009


Author: camunda
Date: 2009-02-03 02:52:46 -0500 (Tue, 03 Feb 2009)
New Revision: 3742

Modified:
   jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java
Log:
JBPM-2008: used configured "create-timer" actions for "timer"

Modified: jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java
===================================================================
--- jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java	2009-02-02 16:14:21 UTC (rev 3741)
+++ jbpm3/trunk/modules/core/src/main/java/org/jbpm/jpdl/xml/JpdlXmlReader.java	2009-02-03 07:52:46 UTC (rev 3742)
@@ -542,17 +542,55 @@
     String name = timerElement.attributeValue("name", node.getName());
     if (name == null) name = generateTimerName();
     
-    CreateTimerAction createTimerAction = new CreateTimerAction();
+    CreateTimerAction createTimerAction = instantiateCreateTimerAction();
     createTimerAction.read(timerElement, this);
     createTimerAction.setTimerName(name);
     createTimerAction.setTimerAction(readSingleAction(timerElement));
     addAction(node, Event.EVENTTYPE_NODE_ENTER, createTimerAction);
     
-    CancelTimerAction cancelTimerAction = new CancelTimerAction();
+    CancelTimerAction cancelTimerAction = instantiateCancelTimerAction();
     cancelTimerAction.setTimerName(name);
     addAction(node, Event.EVENTTYPE_NODE_LEAVE, cancelTimerAction);
   }
 
+  /**
+   * instantiate {@link CreateTimerAction} object from configured
+   * class in action.types.xml (if configured). If not the default
+   * jbpm class is used.
+   */
+  private CreateTimerAction instantiateCreateTimerAction()
+  {
+    if (ActionTypes.hasActionName("create-timer")) {
+      Class actionType = ActionTypes.getActionType("create-timer");
+      try {
+        return (CreateTimerAction)actionType.newInstance();
+      } catch (Exception e) {
+        log.error("couldn't instantiate 'create-timer' action of type '"+actionType.getName()+"'. Using default CreateTimerAction.", e);
+      }
+    }
+    // default
+    return new CreateTimerAction();      
+  }
+
+  /**
+   * instantiate {@link CancelTimerAction} object from configured
+   * class in action.types.xml (if configured). If not the default
+   * jbpm class is used.
+   */
+  private CancelTimerAction instantiateCancelTimerAction()
+  {
+    if (ActionTypes.hasActionName("cancel-timer")) {
+      Class actionType = ActionTypes.getActionType("cancel-timer");
+      try {
+        return (CancelTimerAction)actionType.newInstance();
+      } catch (Exception e) {
+        log.error("couldn't instantiate 'cancel-timer' action of type '"+actionType.getName()+"'. Using default CancelTimerAction.", e);
+      }
+    }
+    // default
+    return new CancelTimerAction();      
+  }
+
   private String generateTimerName() {
     return "timer-" + (timerNumber++); 
   }
@@ -573,7 +611,7 @@
     String name = timerElement.attributeValue("name", task.getName());
     if (name==null) name = generateTimerName();
 
-    CreateTimerAction createTimerAction = new CreateTimerAction();
+    CreateTimerAction createTimerAction = instantiateCreateTimerAction();
     createTimerAction.read(timerElement, this);
     createTimerAction.setTimerName(name);
     Action action = null;
@@ -602,7 +640,7 @@
     }
 
     for (String cancelEventType : cancelEventTypes) {      
-      CancelTimerAction cancelTimerAction = new CancelTimerAction();
+      CancelTimerAction cancelTimerAction = instantiateCancelTimerAction();
       cancelTimerAction.setTimerName(name);
       addAction(task, cancelEventType, cancelTimerAction);
     }




More information about the jbpm-commits mailing list