[jbpm-commits] JBoss JBPM SVN: r2952 - in jbpm3/branches/tdiesler/modules: integration and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Nov 17 06:41:15 EST 2008


Author: thomas.diesler at jboss.com
Date: 2008-11-17 06:41:14 -0500 (Mon, 17 Nov 2008)
New Revision: 2952

Added:
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExclusiveGatewayImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExpressionImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/GatewayImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/GatewayBuilderImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/runtime/ExpressionEvaluator.java
Modified:
   jbpm3/branches/tdiesler/modules/core/src/main/java/org/jbpm/graph/node/Decision.java
   jbpm3/branches/tdiesler/modules/integration/.classpath
   jbpm3/branches/tdiesler/modules/integration/pom.xml
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/client/TokenImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/NodeImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessDefinitionImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/SequenceFlowImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/ProcessBuilderImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessDefinitionServiceImpl.java
   jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessServiceImpl.java
Log:
CTS - ok

Modified: jbpm3/branches/tdiesler/modules/core/src/main/java/org/jbpm/graph/node/Decision.java
===================================================================
--- jbpm3/branches/tdiesler/modules/core/src/main/java/org/jbpm/graph/node/Decision.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/core/src/main/java/org/jbpm/graph/node/Decision.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -81,7 +81,10 @@
 
       try {
         if (decisionDelegation != null) {
-          DecisionHandler decisionHandler = (DecisionHandler) decisionDelegation.instantiate();
+          DecisionHandler decisionHandler = (DecisionHandler)decisionDelegation.getInstance();
+          if (decisionHandler == null)
+            decisionHandler = (DecisionHandler) decisionDelegation.instantiate();
+          
           String transitionName = decisionHandler.decide(executionContext);
           transition = getLeavingTransition(transitionName);
           if (transition == null) {

Modified: jbpm3/branches/tdiesler/modules/integration/.classpath
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/.classpath	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/.classpath	2008-11-17 11:41:14 UTC (rev 2952)
@@ -1,6 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
 	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
 	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>

Modified: jbpm3/branches/tdiesler/modules/integration/pom.xml
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/pom.xml	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/pom.xml	2008-11-17 11:41:14 UTC (rev 2952)
@@ -28,6 +28,11 @@
     <relativePath>../../pom.xml</relativePath>
   </parent>
 
+  <!-- Properties -->
+  <properties>
+    <mvel.version>1.3.7-java1.5</mvel.version>
+  </properties>
+
   <!-- Dependencies -->
   <dependencies>
     <dependency>
@@ -45,6 +50,11 @@
       <classifier>config</classifier>
       <version>${version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.mvel</groupId>
+      <artifactId>mvel</artifactId>
+      <version>${mvel.version}</version>
+    </dependency>
     
     <dependency>
       <groupId>org.slf4j</groupId>

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/client/TokenImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/client/TokenImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/client/TokenImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -31,6 +31,7 @@
 import org.jbpm.api.model.SequenceFlow;
 import org.jbpm.api.model.Process.ProcessStatus;
 import org.jbpm.api.runtime.Attachments;
+import org.jbpm.api.runtime.BasicAttachments;
 import org.jbpm.integration.model.ProcessImpl;
 
 /**
@@ -45,7 +46,7 @@
 
   private org.jbpm.graph.exe.Token oldToken;
   private ProcessImpl procImpl;
-  private Attachments att;
+  private Attachments att = new BasicAttachments();
   
   public TokenImpl(ProcessImpl proc, org.jbpm.graph.exe.Token oldToken, Attachments att)
   {

Added: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExclusiveGatewayImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExclusiveGatewayImpl.java	                        (rev 0)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExclusiveGatewayImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.integration.model;
+
+// $Id$
+
+import org.jbpm.api.client.Token;
+import org.jbpm.api.model.ExclusiveGateway;
+import org.jbpm.api.model.Expression;
+import org.jbpm.api.model.ProcessDefinition;
+import org.jbpm.api.model.SequenceFlow;
+import org.jbpm.api.model.SequenceFlow.ConditionType;
+import org.jbpm.graph.exe.ExecutionContext;
+import org.jbpm.graph.node.Decision;
+import org.jbpm.graph.node.DecisionHandler;
+import org.jbpm.instantiation.Delegation;
+import org.jbpm.integration.runtime.ExpressionEvaluator;
+
+/**
+ * An integration wrapper
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 15-Nov-2008
+ */
+public class ExclusiveGatewayImpl extends GatewayImpl implements ExclusiveGateway
+{
+  private static final long serialVersionUID = 1L;
+
+  public ExclusiveGatewayImpl(ProcessDefinition procDef, Decision oldDecision)
+  {
+    super(procDef, oldDecision);
+    ExclusiveGatewayDecisionHandler decisionHandler = new ExclusiveGatewayDecisionHandler();
+    oldDecision.setDecisionDelegation(new Delegation(decisionHandler));
+  }
+
+  @Override
+  public GatewayType getGatewayType()
+  {
+    return GatewayType.Exclusive;
+  }
+  
+  @Override
+  public ExclusiveType getExclusiveType()
+  {
+    return ExclusiveType.Data;
+  }
+
+  class ExclusiveGatewayDecisionHandler implements DecisionHandler
+  {
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public String decide(ExecutionContext executionContext) throws Exception
+    {
+      ProcessImpl procImpl = (ProcessImpl)getProcess();
+      Token token = procImpl.getRootToken();
+      
+      SequenceFlow selectedGate = null;
+      for (SequenceFlow auxGate : getGates())
+      {
+        SequenceFlow seqFlow = auxGate;
+        if (seqFlow.getConditionType() == ConditionType.Expression)
+        {
+          Expression expr = seqFlow.getConditionExpression();
+          ExpressionEvaluator exprEvaluator = new ExpressionEvaluator(expr);
+          if ((Boolean)exprEvaluator.evaluateExpression(token))
+          {
+            selectedGate = auxGate;
+            break;
+          }
+        }
+      }
+
+      // Use to the default gate if there is one
+      if (selectedGate == null)
+      {
+        for (SequenceFlow auxGate : getGates())
+        {
+          SequenceFlow seqFlow = auxGate;
+          if (seqFlow.getConditionType() == ConditionType.Default)
+          {
+            selectedGate = auxGate;
+            break;
+          }
+        }
+      }
+
+      // Fallback to the single outgoing gate that is not conditional
+      if (selectedGate == null && getGates().size() == 1)
+      {
+        SequenceFlow auxGate = getGates().get(0);
+        SequenceFlow seqFlow = auxGate;
+        if (seqFlow.getConditionType() == ConditionType.None)
+        {
+          selectedGate = auxGate;
+        }
+      }
+
+      if (selectedGate == null)
+        throw new IllegalStateException("Cannot select applicable gate in: " + getOldNode());
+
+      return selectedGate.getTargetRef();
+    }
+  }
+}


Property changes on: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExclusiveGatewayImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExpressionImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExpressionImpl.java	                        (rev 0)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExpressionImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.integration.model;
+
+//$Id$
+
+import org.jbpm.api.model.Expression;
+
+/**
+ * An Expression, which is used in the definition of attributes for @{link StartEvent},
+ * 
+ * @{link IntermediateEvent}, @{link Activity}, @{link ComplexGateway}, and @{link SequenceFlow}
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 17-Nov-2008
+ */
+public class ExpressionImpl implements Expression
+{
+  // provide serial version UID
+  private static final long serialVersionUID = 1L;
+
+  private String body;
+  private ExpressionLanguage lang;
+
+  public ExpressionImpl(String body)
+  {
+    this.body = body;
+    this.lang = ExpressionLanguage.MVEL;
+  }
+
+  public ExpressionImpl(ExpressionLanguage lang, String body)
+  {
+    this.body = body;
+    this.lang = lang;
+  }
+
+  @Override
+  public ExpressionLanguage getExpressionLanguage()
+  {
+    return lang;
+  }
+
+  @Override
+  public String getExpressionBody()
+  {
+    return body;
+  }
+}


Property changes on: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ExpressionImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/GatewayImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/GatewayImpl.java	                        (rev 0)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/GatewayImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.integration.model;
+
+import java.util.List;
+
+import org.jbpm.api.NotImplementedException;
+import org.jbpm.api.model.Gateway;
+import org.jbpm.api.model.ProcessDefinition;
+import org.jbpm.api.model.SequenceFlow;
+import org.jbpm.graph.node.Decision;
+
+/**
+ * An integration wrapper
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 15-Nov-2008
+ */
+public abstract class GatewayImpl extends NodeImpl implements Gateway
+{
+  private static final long serialVersionUID = 1L;
+
+  public GatewayImpl(ProcessDefinition procDef, Decision oldDecision)
+  {
+    super(procDef, oldDecision);
+  }
+
+  @Override
+  public List<SequenceFlow> getGates()
+  {
+    return getOutFlows();
+  }
+
+  @Override
+  public SequenceFlow getGateByName(String targetName)
+  {
+    throw new NotImplementedException();
+  }
+
+  @Override
+  public SequenceFlow getDefaultGate()
+  {
+    throw new NotImplementedException();
+  }
+}


Property changes on: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/GatewayImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/NodeImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/NodeImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/NodeImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -21,14 +21,18 @@
  */
 package org.jbpm.integration.model;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import javax.management.ObjectName;
 
 import org.jbpm.api.Constants;
 import org.jbpm.api.InvalidProcessException;
-import org.jbpm.api.NotImplementedException;
 import org.jbpm.api.model.Node;
 import org.jbpm.api.model.Process;
 import org.jbpm.api.model.ProcessDefinition;
+import org.jbpm.api.model.SequenceFlow;
 import org.jbpm.api.model.builder.ObjectNameFactory;
 import org.jbpm.graph.def.Transition;
 
@@ -43,7 +47,10 @@
   private static final long serialVersionUID = 1L;
   
   private ProcessDefinition procDef;
+  private Process proc;
+  
   private org.jbpm.graph.def.Node oldNode;
+  private List<SequenceFlow> outFlows = new ArrayList<SequenceFlow>();
 
   public NodeImpl(ProcessDefinition procDef, org.jbpm.graph.def.Node oldNode)
   {
@@ -78,22 +85,32 @@
   @Override
   public Process getProcess()
   {
-    throw new NotImplementedException();
+    return proc;
   }
   
-  public void addSequenceFlow(String targetName)
+  public void setProcess(Process proc)
   {
-    NodeImpl targetNode = (NodeImpl)procDef.getNode(targetName);
+    this.proc = proc;
+  }
+  
+  public void addSequenceFlow(SequenceFlowImpl flow)
+  {
+    String targetRef = flow.getTargetRef();
+    NodeImpl targetNode = (NodeImpl)procDef.getNode(targetRef);
     if (targetNode == null)
-      throw new InvalidProcessException("Cannot obtain target node: " + targetName);
+      throw new InvalidProcessException("Cannot obtain target node: " + targetRef);
     
-    Transition trans = new Transition();
-    trans.setFrom(this.getOldNode());
-    trans.setTo(targetNode.getOldNode());
-    
+    Transition trans = flow.getOldTransition();
     oldNode.addLeavingTransition(trans);
     targetNode.getOldNode().addArrivingTransition(trans);
+    
+    outFlows.add(flow);
   }
+  
+  public List<SequenceFlow> getOutFlows()
+  {
+    return Collections.unmodifiableList(outFlows);
+  }
 
   @Override
   public String toString()

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessDefinitionImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessDefinitionImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessDefinitionImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -22,7 +22,10 @@
 package org.jbpm.integration.model;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.management.ObjectName;
 
@@ -33,9 +36,6 @@
 import org.jbpm.api.model.Process;
 import org.jbpm.api.model.ProcessDefinition;
 import org.jbpm.api.model.builder.ObjectNameFactory;
-import org.jbpm.graph.node.EndState;
-import org.jbpm.graph.node.StartState;
-import org.jbpm.graph.node.State;
 
 /**
  * An integration wrapper
@@ -49,6 +49,7 @@
 
   private org.jbpm.graph.def.ProcessDefinition oldProcDef;
   private ProcessEngine engine;
+  private Map<String, Node> nodes = new LinkedHashMap<String, Node>();
 
   public ProcessDefinitionImpl(ProcessEngine engine, String name)
   {
@@ -88,33 +89,33 @@
   @Override
   public Process newInstance()
   {
-    return new ProcessImpl(this);
+    ProcessImpl procImpl = new ProcessImpl(this);
+    for (Node node : getNodes())
+    {
+      NodeImpl nodeImpl = (NodeImpl)node;
+      nodeImpl.setProcess(procImpl);
+    }
+    return procImpl;
   }
   
   public void addNode(NodeImpl nodeImpl)
   {
     org.jbpm.graph.def.Node oldNode = nodeImpl.getOldNode();
     oldProcDef.addNode(oldNode);
+    nodes.put(oldNode.getName(), nodeImpl);
   }
 
   @Override
   public Node getNode(String name)
   {
-    org.jbpm.graph.def.Node oldNode = oldProcDef.getNode(name);
-    return adaptNode(oldNode);
+    return nodes.get(name);
   }
 
   @Override
-  @SuppressWarnings("unchecked")
   public List<Node> getNodes()
   {
-    List<Node> nodes = new ArrayList<Node>();
-    List<org.jbpm.graph.def.Node> oldNodes = oldProcDef.getNodes();
-    for (org.jbpm.graph.def.Node oldNode : oldNodes)
-    {
-      nodes.add(adaptNode(oldNode));
-    }
-    return nodes;
+    List<Node> nodeList = new ArrayList<Node>(nodes.values());
+    return Collections.unmodifiableList(nodeList);
   }
 
   @Override
@@ -141,29 +142,4 @@
     }
     return retNodes;
   }
-
-  private NodeImpl adaptNode(org.jbpm.graph.def.Node oldNode)
-  {
-    NodeImpl node = null;
-    if (oldNode != null)
-    {
-      if (oldNode instanceof StartState)
-      {
-        node = new StartEventImpl(this, (StartState)oldNode);
-      }
-      else if (oldNode instanceof State)
-      {
-        node = new WaitStateImpl(this, (State)oldNode);
-      }
-      else if (oldNode instanceof EndState)
-      {
-        node = new EndEventImpl(this, (EndState)oldNode);
-      }
-      else
-      {
-        node = new TaskImpl(this, oldNode);
-      }
-    }
-    return node;
-  }
 }

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/ProcessImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -79,9 +79,11 @@
   @Override
   public ProcessStatus getProcessStatus()
   {
-    if (rootToken.getTokenStatus() == TokenStatus.Destroyed)
-      procStatus = ProcessStatus.Completed;
-    
+    if (rootToken != null && procStatus == ProcessStatus.Active)
+    {
+      if (rootToken.getTokenStatus() == TokenStatus.Destroyed)
+        procStatus = ProcessStatus.Completed;
+    }
     return procStatus;
   }
 
@@ -91,23 +93,6 @@
   }
 
   @Override
-  public Token startProcess()
-  {
-    setProcessStatus(ProcessStatus.Ready);
-    rootToken = startProcess(null);
-    return rootToken;
-  }
-
-  @Override
-  public Token startProcess(Attachments att)
-  {
-    oldProc = new ProcessInstance(procDef.getOldProcessDefinition());
-    TokenImpl token = new TokenImpl(this, oldProc.getRootToken(), att);
-    token.signal();
-    return token;
-  }
-
-  @Override
   public String getName()
   {
     return procDef.getName();
@@ -136,4 +121,25 @@
   {
     return procDef.getNodes(clazz);
   }
+
+  @Override
+  public Token startProcess()
+  {
+    return startProcess(null);
+  }
+
+  @Override
+  public Token startProcess(Attachments att)
+  {
+    setProcessStatus(ProcessStatus.Active);
+    oldProc = new ProcessInstance(procDef.getOldProcessDefinition());
+    rootToken = new TokenImpl(this, oldProc.getRootToken(), att);
+    rootToken.signal();
+    return rootToken;
+  }
+
+  public Token getRootToken()
+  {
+    return rootToken;
+  }
 }

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/SequenceFlowImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/SequenceFlowImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/SequenceFlowImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -21,9 +21,9 @@
  */
 package org.jbpm.integration.model;
 
-import org.jbpm.api.NotImplementedException;
 import org.jbpm.api.model.Expression;
 import org.jbpm.api.model.SequenceFlow;
+import org.jbpm.api.model.Expression.ExpressionLanguage;
 import org.jbpm.graph.def.Node;
 import org.jbpm.graph.def.Transition;
 
@@ -39,16 +39,33 @@
 
   private Transition oldTrans;
   private ConditionType condType = ConditionType.None;
+  private Expression expr;
 
   public SequenceFlowImpl(Transition oldTrans)
   {
     this.oldTrans = oldTrans;
   }
 
+  public SequenceFlowImpl(Transition oldTrans, ExpressionLanguage exprLang, String exprBody)
+  {
+    this.oldTrans = oldTrans;
+    
+    if (exprLang != null && exprBody != null)
+    {
+      this.condType = ConditionType.Expression;
+      this.expr = new ExpressionImpl(exprLang, exprBody);
+    }
+  }
+
+  public Transition getOldTransition()
+  {
+    return oldTrans;
+  }
+
   @Override
   public Expression getConditionExpression()
   {
-    throw new NotImplementedException();
+    return expr;
   }
 
   @Override

Added: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/GatewayBuilderImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/GatewayBuilderImpl.java	                        (rev 0)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/GatewayBuilderImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.integration.model.builder;
+
+//$Id$
+
+import org.jbpm.api.NotImplementedException;
+import org.jbpm.api.model.Expression.ExpressionLanguage;
+import org.jbpm.api.model.builder.GatewayBuilder;
+
+/**
+ * The GatewayBuilder can be used to build a Gateway dynamically.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 15-Nov-2008
+ */
+public class GatewayBuilderImpl extends ProcessBuilderImpl implements GatewayBuilder
+{
+  protected GatewayBuilderImpl(ProcessBuilderImpl procBuilder)
+  {
+    super(procBuilder);
+  }
+
+  @Override
+  public GatewayBuilder addGate(String targetName)
+  {
+    addSequenceFlow(targetName);
+    return this;
+  }
+  
+  @Override
+  public GatewayBuilder addConditionalGate(String targetName, ExpressionLanguage exprLang, String exprBody)
+  {
+    addSequenceFlow(targetName, exprLang, exprBody);
+    return this;
+  }
+
+  @Override
+  public GatewayBuilder addDefaultGate(String targetName)
+  {
+    throw new NotImplementedException();
+  }
+}
\ No newline at end of file


Property changes on: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/GatewayBuilderImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/ProcessBuilderImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/ProcessBuilderImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/model/builder/ProcessBuilderImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -35,16 +35,21 @@
 import org.jbpm.api.model.Process;
 import org.jbpm.api.model.ProcessDefinition;
 import org.jbpm.api.model.StartEvent;
+import org.jbpm.api.model.Expression.ExpressionLanguage;
 import org.jbpm.api.model.Gateway.GatewayType;
 import org.jbpm.api.model.Task.TaskType;
 import org.jbpm.api.model.builder.GatewayBuilder;
 import org.jbpm.api.model.builder.ProcessBuilder;
+import org.jbpm.graph.def.Transition;
+import org.jbpm.graph.node.Decision;
 import org.jbpm.graph.node.EndState;
 import org.jbpm.graph.node.StartState;
 import org.jbpm.graph.node.State;
 import org.jbpm.integration.model.EndEventImpl;
+import org.jbpm.integration.model.ExclusiveGatewayImpl;
 import org.jbpm.integration.model.NodeImpl;
 import org.jbpm.integration.model.ProcessDefinitionImpl;
+import org.jbpm.integration.model.SequenceFlowImpl;
 import org.jbpm.integration.model.StartEventImpl;
 import org.jbpm.integration.model.TaskImpl;
 import org.jbpm.integration.model.WaitStateImpl;
@@ -61,7 +66,7 @@
   protected ProcessDefinitionImpl procDefImpl;
   protected NodeImpl nodeImpl;
   
-  private List<FlowTuple> flows = new ArrayList<FlowTuple>();
+  private List<FlowSpec> flows = new ArrayList<FlowSpec>();
 
   public ProcessBuilderImpl(ProcessEngine engine)
   {
@@ -86,43 +91,7 @@
   @Override
   public ProcessDefinition getProcessDefinition()
   {
-    // Initialize the flows
-    for (FlowTuple flow : flows)
-    {
-      NodeImpl srcNode = (NodeImpl)procDefImpl.getNode(flow.source);
-      if (srcNode == null)
-        throw new InvalidProcessException("Cannot obtain source node: " + flow.source);
-      
-      srcNode.addSequenceFlow(flow.target);
-    }
-    
-    // Verify that there is a start event
-    List<StartEvent> startEvents = procDefImpl.getNodes(StartEvent.class);
-    if (startEvents.size() == 0)
-      throw new InvalidProcessException("Cannot obtain a start event");
-      
-    // Verify that there is an end event
-    List<EndEvent> endEvents = procDefImpl.getNodes(EndEvent.class);
-    if (endEvents.size() == 0)
-      throw new InvalidProcessException("Cannot obtain an end event");
-      
-    // Detect unreachable nodes
-    for (Node node : procDefImpl.getNodes())
-    {
-      NodeImpl nodeImpl = (NodeImpl)node;
-      Set arriving = nodeImpl.getOldNode().getArrivingTransitions();
-      if (!(node instanceof StartEvent) && arriving == null)
-        throw new InvalidProcessException("Unreachable node: " + node);
-    }
-    
-    // Detect dead end nodes
-    for (Node node : procDefImpl.getNodes())
-    {
-      NodeImpl nodeImpl = (NodeImpl)node;
-      List leaving = nodeImpl.getOldNode().getLeavingTransitions();
-      if (!(node instanceof EndEvent) && leaving == null)
-        throw new InvalidProcessException("Dead end node: " + node);
-    }
+    initProcessDefinition();
     return procDefImpl;
   }
 
@@ -137,7 +106,16 @@
   @Override
   public GatewayBuilder addGateway(String name, GatewayType type)
   {
-    return null;
+    if (type == GatewayType.Exclusive)
+    {
+      nodeImpl = new ExclusiveGatewayImpl(procDefImpl, new Decision(name));
+      procDefImpl.addNode(nodeImpl);
+    }
+    else
+    {
+      throw new NotImplementedException("Unsupported gateway type: " + type);
+    }
+    return new GatewayBuilderImpl(this);
   }
 
   @Override
@@ -177,19 +155,78 @@
   @Override
   public ProcessBuilder addSequenceFlow(String targetName)
   {
-    flows.add(new FlowTuple(nodeImpl.getName(), targetName));
+    return addSequenceFlow(targetName, null, null);
+  }
+  
+  public ProcessBuilder addSequenceFlow(String targetName, ExpressionLanguage exprLang, String exprBody)
+  {
+    flows.add(new FlowSpec(nodeImpl.getName(), targetName, exprLang, exprBody));
     return this;
   }
   
-  private class FlowTuple
+  class FlowSpec
   {
     String source;
     String target;
+    ExpressionLanguage exprLang;
+    String exprBody;
     
-    public FlowTuple(String source, String target)
+    public FlowSpec(String source, String target, ExpressionLanguage exprLang, String exprBody)
     {
       this.source = source;
       this.target = target;
+      this.exprLang = exprLang;
+      this.exprBody = exprBody;
     }
   }
+
+  private void initProcessDefinition()
+  {
+    // Initialize the flows
+    for (FlowSpec flow : flows)
+    {
+      NodeImpl srcNode = (NodeImpl)procDefImpl.getNode(flow.source);
+      if (srcNode == null)
+        throw new InvalidProcessException("Cannot obtain source node: " + flow.source);
+      
+      NodeImpl targetNode = (NodeImpl)procDefImpl.getNode(flow.target);
+      if (targetNode == null)
+        throw new InvalidProcessException("Cannot obtain target node: " + flow.target);
+      
+      Transition trans = new Transition(flow.target);
+      trans.setFrom(srcNode.getOldNode());
+      trans.setTo(targetNode.getOldNode());
+      
+      SequenceFlowImpl seqFlow = new SequenceFlowImpl(trans, flow.exprLang, flow.exprBody);
+      srcNode.addSequenceFlow(seqFlow);
+    }
+    
+    // Verify that there is a start event
+    List<StartEvent> startEvents = procDefImpl.getNodes(StartEvent.class);
+    if (startEvents.size() == 0)
+      throw new InvalidProcessException("Cannot obtain a start event");
+      
+    // Verify that there is an end event
+    List<EndEvent> endEvents = procDefImpl.getNodes(EndEvent.class);
+    if (endEvents.size() == 0)
+      throw new InvalidProcessException("Cannot obtain an end event");
+      
+    // Detect unreachable nodes
+    for (Node node : procDefImpl.getNodes())
+    {
+      NodeImpl nodeImpl = (NodeImpl)node;
+      Set arriving = nodeImpl.getOldNode().getArrivingTransitions();
+      if (!(node instanceof StartEvent) && arriving == null)
+        throw new InvalidProcessException("Unreachable node: " + node);
+    }
+    
+    // Detect dead end nodes
+    for (Node node : procDefImpl.getNodes())
+    {
+      NodeImpl nodeImpl = (NodeImpl)node;
+      List leaving = nodeImpl.getOldNode().getLeavingTransitions();
+      if (!(node instanceof EndEvent) && leaving == null)
+        throw new InvalidProcessException("Dead end node: " + node);
+    }
+  }
 }
\ No newline at end of file

Added: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/runtime/ExpressionEvaluator.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/runtime/ExpressionEvaluator.java	                        (rev 0)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/runtime/ExpressionEvaluator.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.integration.runtime;
+
+//$Id$
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.api.client.Token;
+import org.jbpm.api.model.Expression;
+import org.jbpm.api.model.Expression.ExpressionLanguage;
+import org.jbpm.api.runtime.Attachments;
+import org.jbpm.api.runtime.Attachments.Key;
+import org.mvel.MVEL;
+
+/**
+ * Evaluates an expression for a given token
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2008
+ */
+public class ExpressionEvaluator
+{
+  private Expression expr;
+
+  public ExpressionEvaluator(Expression expr)
+  {
+    this.expr = expr;
+  }
+
+  /**
+   * Evaluate an expression for a given token. <p/> Note that <code>propName.replace(".", "_")</code> applies to
+   * property names for MVEL expressions, because the dot notation has special meaning in MVEL.
+   */
+  public Object evaluateExpression(Token token)
+  {
+    ExpressionLanguage exprLang = expr.getExpressionLanguage();
+    if (exprLang == ExpressionLanguage.MVEL)
+    {
+      String mvel = expr.getExpressionBody();
+      Attachments atts = token.getAttachments();
+      Map<String, Object> vars = new HashMap<String, Object>();
+      for (Key key : atts.getAttachmentKeys())
+      {
+        String name = key.getNamePart();
+        Object value = atts.getAttachment(name);
+        vars.put(name.replace(".", "_"), value);
+      }
+      return MVEL.eval(mvel, vars);
+    }
+    else
+    {
+      throw new IllegalStateException("Unsupported expression language: " + exprLang);
+    }
+  }
+}
\ No newline at end of file


Property changes on: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/runtime/ExpressionEvaluator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessDefinitionServiceImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessDefinitionServiceImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessDefinitionServiceImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -33,7 +33,7 @@
 import org.jbpm.api.client.ProcessEngine;
 import org.jbpm.api.model.ProcessDefinition;
 import org.jbpm.api.service.ProcessDefinitionService;
-import org.jbpm.api.service.ProcessInstanceService;
+import org.jbpm.api.service.ProcessService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -96,7 +96,7 @@
       ProcessEngine engine = getProcessEngine();
 
       // Unregister the associated process instances
-      ProcessInstanceService procService = engine.getService(ProcessInstanceService.class);
+      ProcessService procService = engine.getService(ProcessService.class);
       for (ObjectName procID : procService.getProcesses(procDef.getName(), null))
         procService.unregisterProcess(procID);
 

Modified: jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessServiceImpl.java
===================================================================
--- jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessServiceImpl.java	2008-11-17 09:57:53 UTC (rev 2951)
+++ jbpm3/branches/tdiesler/modules/integration/src/main/java/org/jbpm/integration/service/ProcessServiceImpl.java	2008-11-17 11:41:14 UTC (rev 2952)
@@ -25,10 +25,21 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
+import javax.management.ObjectName;
+
 import org.jbpm.api.client.ProcessEngine;
-import org.jbpm.api.service.ProcessInstanceService;
+import org.jbpm.api.model.Process;
+import org.jbpm.api.model.ProcessDefinition;
+import org.jbpm.api.model.Process.ProcessStatus;
+import org.jbpm.api.service.ProcessDefinitionService;
+import org.jbpm.api.service.ProcessService;
+import org.jbpm.integration.model.ProcessImpl;
 import org.jbpm.integration.runtime.NodeInterceptor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,11 +50,12 @@
  * @author thomas.diesler at jboss.com
  * @since 18-Jun-2008
  */
-public class ProcessServiceImpl extends ProcessInstanceService implements MutableService
+public class ProcessServiceImpl extends ProcessService implements MutableService
 {
   // Provide logging
   final static Logger log = LoggerFactory.getLogger(ProcessServiceImpl.class);
   
+  private Map<ObjectName, Process> registeredProcs = new HashMap<ObjectName, Process>();
   private List<NodeInterceptor> nodeInterceptors = new ArrayList<NodeInterceptor>();
   
   @Override
@@ -66,6 +78,96 @@
     return Collections.unmodifiableList(nodeInterceptors);
   }
 
+  /**
+   * Get a Process for a given id
+   */
+  @Override
+  public Process getProcess(ObjectName procID)
+  {
+    Process proc = registeredProcs.get(procID);
+    return proc;
+  }
+
+  /**
+   * Get the set of registered Processes
+   */
+  @Override
+  public Set<ObjectName> getProcesses()
+  {
+    return Collections.unmodifiableSet(registeredProcs.keySet());
+  }
+
+  /**
+   * Find the set of Processes for a given name
+   * 
+   * @param name The process name
+   * @param status The optional process status
+   * @return An empty set if the process cannot be found
+   */
+  @Override
+  public Set<ObjectName> getProcesses(String name, ProcessStatus status)
+  {
+    Set<ObjectName> procSet = new HashSet<ObjectName>();
+    for (Process auxProc : registeredProcs.values())
+    {
+      if (auxProc.getName().equals(name))
+      {
+        if (status == null || auxProc.getProcessStatus() == status)
+          procSet.add(auxProc.getKey());
+      }
+    }
+    return procSet;
+  }
+
+  /**
+   * Register a Process.
+   */
+  public ObjectName registerProcess(Process proc)
+  {
+    log.debug("registerProcess: " + proc);
+
+    ObjectName procID = proc.getKey();
+    if (getProcess(procID) != null)
+      throw new IllegalStateException("Process already registered: " + proc);
+
+    ProcessStatus procStatus = proc.getProcessStatus();
+    ProcessDefinition procDef = proc.getProcessDefinition();
+    ProcessEngine engine = getProcessEngine();
+
+    if (procStatus != ProcessStatus.None)
+      throw new IllegalStateException("Cannot register process in state: " + procStatus);
+
+    // Register the process definition if needed
+    ProcessDefinitionService procDefService = engine.getService(ProcessDefinitionService.class);
+    if (procDefService.getProcessDefinition(procDef.getKey()) == null)
+      procDefService.registerProcessDefinition(procDef);
+
+    // Register the process
+    registeredProcs.put(procID, proc);
+    
+    ProcessImpl procImpl = (ProcessImpl)proc;
+    procImpl.setProcessStatus(ProcessStatus.Ready);
+    
+    return procID;
+  }
+
+  /**
+   * Unregister a Process.
+   */
+  public boolean unregisterProcess(ObjectName procID)
+  {
+    boolean removed = false;
+    Process proc = registeredProcs.get(procID);
+    if (proc != null)
+    {
+      log.debug("unregisterProcess: " + proc);
+
+      registeredProcs.remove(procID);
+      removed = true;
+    }
+    return removed;
+  }
+
   private NodeInterceptor loadNodeInterceptor(String className)
   {
     NodeInterceptor itor = null;




More information about the jbpm-commits mailing list