[jbpm-commits] JBoss JBPM SVN: r6341 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/env and 3 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu May 13 22:41:49 EDT 2010


Author: rebody
Date: 2010-05-13 22:41:49 -0400 (Thu, 13 May 2010)
New Revision: 6341

Added:
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/UelExpressionTest.java
Modified:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/EnvironmentImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java
   jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/VariableExpressionTest.java
Log:
JBPM-2777 use Maciej' patch to solve this issue

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java	2010-05-14 02:23:28 UTC (rev 6340)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmEnvironmentElResolver.java	2010-05-14 02:41:49 UTC (rev 6341)
@@ -27,32 +27,36 @@
 import javax.el.ELContext;
 import javax.el.ELResolver;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 
-
 /**
  * @author Tom Baeyens
  */
 public class JbpmEnvironmentElResolver extends ELResolver {
-  
+
   EnvironmentImpl environment;
-  
+
   public JbpmEnvironmentElResolver(EnvironmentImpl environment) {
     this.environment = environment;
   }
 
   public Object getValue(ELContext context, Object base, Object property) {
-    // this resolver only resolves top level variable names to execution variable names.
+    // this resolver only resolves top level variable names to execution
+    // variable names.
     // only handle if this is a top level variable
-    if (base==null) {
+    if (base == null) {
       // we assume a NPE-check for property is not needed
-      // i don't think the next cast can go wrong.  can it?
+      // i don't think the next cast can go wrong. can it?
       String name = (String) property;
 
-      Object object = environment.get(name);
-      if (object!=null) {
+      try {
+        Object object = environment.get(name, false);
         context.setPropertyResolved(true);
         return object;
+      } catch (JbpmException je) {
+        // Property not found... ignore in this case and return null below...
+        // Will be interpreted as property not found
       }
     }
 

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java	2010-05-14 02:23:28 UTC (rev 6340)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/BasicEnvironment.java	2010-05-14 02:41:49 UTC (rev 6341)
@@ -93,16 +93,30 @@
   public Object get(String name) {
     return get(name, null);
   }
-  
+
   public Object get(String name, String[] searchOrder) {
-    if (searchOrder==null) {
-      searchOrder = getDefaultSearchOrder();
+    return get(name, searchOrder, true);
+  }
+
+  public Object get(String name, boolean nullIfNotFound) {
+    return get(name, null, nullIfNotFound);
+  }
+
+  public Object get(String name, String[] searchOrder, boolean nullIfNotFound) {
+    if (searchOrder == null) {
+	  searchOrder = getDefaultSearchOrder();
+	}
+	for (String contextName : searchOrder) {
+	  Context context = contexts.get(contextName);
+	  if (context.has(name)) {
+		return context.get(name);
+	  }
+	}
+    if (nullIfNotFound) {
+      return null;
+    } else {
+      throw new JbpmException("Null value found for " + name + " but null is not allowed");
     }
-    for (String contextName : searchOrder) {
-      Context context = contexts.get(contextName);
-      if (context.has(name)) return context.get(name);
-    }
-    return null;
   }
 
   public <T> T get(Class<T> type) {

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/EnvironmentImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/EnvironmentImpl.java	2010-05-14 02:23:28 UTC (rev 6340)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/env/EnvironmentImpl.java	2010-05-14 02:41:49 UTC (rev 6341)
@@ -141,6 +141,10 @@
    * @return the object if it exists in the environment, <code>null</code> if there is no object with the given name in the specified searchOrder contexts.
    */
   public abstract Object get(String name, String[] searchOrder);
+  
+  public abstract Object get(String name,String[] searchOrder, boolean nullAllowed) throws JbpmException;
+  
+  public abstract Object get(String name, boolean nullAllowed) throws JbpmException;
 
   /** searches an object based on type.  The search doesn take superclasses of the context elements 
    * into account.

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java	2010-05-14 02:23:28 UTC (rev 6340)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/script/JuelScriptEngine.java	2010-05-14 02:41:49 UTC (rev 6341)
@@ -21,15 +21,39 @@
  */
 package org.jbpm.pvm.internal.script;
 
-import de.odysseus.el.util.SimpleResolver;
-
-import javax.el.*;
-import javax.script.*;
 import java.io.IOException;
 import java.io.Reader;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Properties;
 
+import javax.el.ArrayELResolver;
+import javax.el.BeanELResolver;
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+import javax.el.FunctionMapper;
+import javax.el.ListELResolver;
+import javax.el.MapELResolver;
+import javax.el.ResourceBundleELResolver;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.script.AbstractScriptEngine;
+import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+
+import org.jbpm.pvm.internal.env.ExecutionContext;
+
+import de.odysseus.el.util.SimpleResolver;
+
 class JuelScriptEngine extends AbstractScriptEngine
     implements Compilable
 {
@@ -369,8 +393,16 @@
 
         return exprFactory.createValueExpression(
             value, Object.class);
+      } else {
+        // to support null value for existing variables
+        Bindings b = this.ctx.getBindings(ScriptContext.ENGINE_SCOPE);
+        ExecutionContext execContext = (ExecutionContext) ((EnvironmentBindings) b).environment.getContext("execution");
+        // if variable name exist then set value expression as null 
+        // since it was not discovered by attribute scope method
+        if (execContext.getExecution().getVariables().containsKey(variable)) {
+          return exprFactory.createValueExpression(null, Object.class);
+        }
       }
-
       return null;
     }
 

Added: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/UelExpressionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/UelExpressionTest.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/expr/UelExpressionTest.java	2010-05-14 02:41:49 UTC (rev 6341)
@@ -0,0 +1,54 @@
+/*
+ * 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.pvm.internal.expr;
+
+import org.jbpm.pvm.activities.WaitState;
+import org.jbpm.pvm.internal.builder.ProcessDefinitionBuilder;
+
+import org.jbpm.pvm.internal.el.Expression;
+import org.jbpm.pvm.internal.el.UelValueExpression;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class UelExpressionTest extends JbpmTestCase {
+  
+  public void testUelExpression() {
+    ExecutionImpl execution = (ExecutionImpl) ProcessDefinitionBuilder
+    .startProcess()
+      .startActivity("initial", new WaitState())
+        .initial()
+      .endActivity()
+    .endProcess()
+    .startProcessInstance();
+    
+    Expression expression = Expression.create("#{pv}", Expression.LANGUAGE_UEL_VALUE);
+    UelValueExpression uve = ((UelValueExpression) expression);
+    
+    execution.setVariable("pv", null);       
+    
+    assertEquals(null, uve.evaluate(execution));
+  }  
+}

Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/VariableExpressionTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/VariableExpressionTest.java	2010-05-14 02:23:28 UTC (rev 6340)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/VariableExpressionTest.java	2010-05-14 02:41:49 UTC (rev 6341)
@@ -27,6 +27,7 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.jbpm.api.JbpmException;
 import org.jbpm.api.ProcessInstance;
 import org.jbpm.api.activity.ActivityBehaviour;
 import org.jbpm.api.activity.ActivityExecution;
@@ -35,6 +36,7 @@
 
 /**
  * @author Joram Barrez
+ * @author Maciej Swiderski
  */
 public class VariableExpressionTest extends JbpmTestCase {
   
@@ -72,7 +74,77 @@
     assertEquals(new Integer(10), counter);
   }
   
+  public void testNullValueExpression() {
+    deployJpdlXmlString(
+            "<process name='theProcess'>" +
+            "  <start name='theStart'>" +
+            "    <transition to='decideToGoFurther' />" +
+            "  </start>" +
+            "  <custom name='incrementCounter' class='" + MyJavaActivity.class.getName() + "'>" +
+            "   <transition to='decideToGoFurther' />" +
+            "  </custom>" +
+            "  <decision name='decideToGoFurther'>" +
+            "    <transition to='waitHere'>" +
+            "      <condition expr='#{counter==null}' />" + 
+            "    </transition>" +
+            "    <transition to='incrementCounter'>" +
+            "      <condition expr='#{counter &lt; 10}' />" +
+            "    </transition>" +
+            "  </decision>" +
+            "  <state name='waitHere'>" +
+            "    <transition to='theEnd' />" +
+            "  </state>" +
+            "  <end name='theEnd' />" +
+            "</process>"
+          );
+    
+    Map<String, Object> vars = new HashMap<String, Object>();
+    vars.put("counter", null);
+    
+    ProcessInstance processInstance = executionService.startProcessInstanceByKey("theProcess", vars);
+    assertActivityActive(processInstance.getId(), "waitHere");
+    
+    Object value = executionService.getVariable(processInstance.getId(), "counter");
+    assertEquals(null, value);
+  }
   
+  public void testMissingVariableExpression() {
+    deployJpdlXmlString(
+            "<process name='theProcess'>" +
+            "  <start name='theStart'>" +
+            "    <transition to='decideToGoFurther' />" +
+            "  </start>" +
+            "  <custom name='incrementCounter' class='" + MyJavaActivity.class.getName() + "'>" +
+            "   <transition to='decideToGoFurther' />" +
+            "  </custom>" +
+            "  <decision name='decideToGoFurther'>" +
+            "    <transition to='waitHere'>" +
+            "      <condition expr='#{counter==null}' />" + 
+            "    </transition>" +
+            "    <transition to='incrementCounter'>" +
+            "      <condition expr='#{counter &lt; 10}' />" +
+            "    </transition>" +
+            "  </decision>" +
+            "  <state name='waitHere'>" +
+            "    <transition to='theEnd' />" +
+            "  </state>" +
+            "  <end name='theEnd' />" +
+            "</process>"
+          );
+    
+    Map<String, Object> vars = new HashMap<String, Object>();
+    try {
+      ProcessInstance processInstance = executionService.startProcessInstanceByKey("theProcess", vars);
+
+      fail("Variable counter is not set, should fail");
+    } catch (JbpmException e) {
+
+      assertTrue(e.getMessage().indexOf("Cannot find property counter") != -1);
+    }
+
+  }
+  
+  
   public static class MyJavaActivity implements ActivityBehaviour {
 
     private static final long serialVersionUID = 1L;



More information about the jbpm-commits mailing list