[jbpm-commits] JBoss JBPM SVN: r6143 - in jbpm4/trunk/modules: jpdl/src/main/java/org/jbpm/jpdl/internal/xml and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jan 28 04:13:46 EST 2010


Author: tom.baeyens at jboss.com
Date: 2010-01-28 04:13:45 -0500 (Thu, 28 Jan 2010)
New Revision: 6143

Added:
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java
Modified:
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java
   jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
   jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
Log:
JBPM-2653 refactoring: grouped all expression related operations in Expression class.  this should also ensure there is only a library dependancy on the javax.el apis if expressions are actually used

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java	2010-01-28 08:51:56 UTC (rev 6142)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignActivity.java	2010-01-28 09:13:45 UTC (rev 6143)
@@ -25,6 +25,7 @@
 import javax.el.ValueExpression;
 
 import org.jbpm.api.model.OpenExecution;
+import org.jbpm.pvm.internal.el.Expression;
 import org.jbpm.pvm.internal.model.ExecutionImpl;
 import org.jbpm.pvm.internal.wire.Descriptor;
 import org.jbpm.pvm.internal.wire.WireContext;
@@ -37,24 +38,18 @@
 
   private static final long serialVersionUID = 1L;
 
-  protected ValueExpression fromValueExpression;
-  protected MethodExpression fromMethodExpression;
+  protected Expression fromExpression;
   protected Descriptor fromValueDescriptor;
 
   protected String toVariableName;
-  protected ValueExpression toValueExpression;
+  protected Expression toExpression;
 
   void perform(OpenExecution execution) throws Exception {
     Object value = null;
     
-    if (fromValueExpression!=null) {
-      ExecutionImpl executionImpl = (ExecutionImpl) execution;
-      value = executionImpl.resolveElValueExpressionGet(fromValueExpression);
+    if (fromExpression!=null) {
+      value = fromExpression.evaluate(execution);
       
-    } else if (fromMethodExpression!=null) {
-      ExecutionImpl executionImpl = (ExecutionImpl) execution;
-      value = executionImpl.resolveElMethodExpressionInvoke(fromMethodExpression);
-      
     } else if (fromValueDescriptor!=null) {
       value = WireContext.create(fromValueDescriptor);
     }
@@ -62,24 +57,20 @@
     if (toVariableName!=null) {
       execution.setVariable(toVariableName, value);
     } else {
-      ExecutionImpl executionImpl = (ExecutionImpl) execution;
-      executionImpl.resolveElValueExpressionSet(toValueExpression, value);
+      toExpression.setValue(execution, value);
     }
   }
 
-  public void setFromValueExpression(ValueExpression fromValueExpression) {
-    this.fromValueExpression = fromValueExpression;
-  }
-  public void setFromMethodExpression(MethodExpression methodExpression) {
-    this.fromMethodExpression = methodExpression;
-  }
   public void setToVariableName(String variableName) {
     this.toVariableName = variableName;
   }
-  public void setToValueExpression(ValueExpression toValueExpression) {
-    this.toValueExpression = toValueExpression;
-  }
   public void setFromValueDescriptor(Descriptor valueDescriptor) {
     this.fromValueDescriptor = valueDescriptor;
   }
+  public void setFromExpression(Expression fromExpression) {
+    this.fromExpression = fromExpression;
+  }
+  public void setToExpression(Expression toExpression) {
+    this.toExpression = toExpression;
+  }
 }

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java	2010-01-28 08:51:56 UTC (rev 6142)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/AssignBinding.java	2010-01-28 09:13:45 UTC (rev 6143)
@@ -24,11 +24,8 @@
 import java.util.List;
 import java.util.Set;
 
-import javax.el.ELException;
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-
 import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.el.Expression;
 import org.jbpm.pvm.internal.util.XmlUtil;
 import org.jbpm.pvm.internal.wire.Descriptor;
 import org.jbpm.pvm.internal.wire.xml.WireParser;
@@ -53,8 +50,8 @@
     if (toVar!=null) {
       assignActivity.setToVariableName(toVar);
     } else if (toExpr!=null) {
-      ValueExpression valueExpression = parser.createValueExpression(toExpr);
-      assignActivity.setToValueExpression(valueExpression);
+      Expression expression = new Expression(toExpr, Expression.TYPE_VALUE);
+      assignActivity.setToExpression(expression);
     }
 
     String exprText = XmlUtil.attribute(element, "expr");
@@ -62,27 +59,9 @@
 
     // if there is an expr specified
     if (exprText!=null) {
-      // by default, expr is interpreted as a value expression
-      if (exprType==null || "value".equals(exprType)) {
-        try {
-          ValueExpression valueExpression = parser.createValueExpression(exprText);
-          assignActivity.setFromValueExpression(valueExpression);
-          
-        // if the expr is not a valid value expr...
-        } catch (ELException e) {
-          // ... and the expr-type was not specified 
-          if (exprType==null) {
-            // then try to parse it as a method expression
-            exprType = "method";
-          }
-        } 
-      } 
+      Expression expression = new Expression(exprText, exprType);
+      assignActivity.setFromExpression(expression);
 
-      if ("method".equals(exprType)) {
-        MethodExpression methodExpression = parser.createMethodExpression(exprText);
-        assignActivity.setFromMethodExpression(methodExpression);
-      }
-
     } else { // there is no expr specified
       Set<String> descriptorTagNames = JpdlParser.wireParser.getBindings().getTagNames(WireParser.CATEGORY_DESCRIPTOR);
       Descriptor valueDescriptor = null;

Modified: jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java
===================================================================
--- jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java	2010-01-28 08:51:56 UTC (rev 6142)
+++ jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/xml/JpdlParser.java	2010-01-28 09:13:45 UTC (rev 6143)
@@ -31,11 +31,6 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import javax.el.ELContext;
-import javax.el.ExpressionFactory;
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-
 import org.jbpm.api.JbpmException;
 import org.jbpm.api.activity.ActivityBehaviour;
 import org.jbpm.api.listener.EventListener;
@@ -44,7 +39,6 @@
 import org.jbpm.jpdl.internal.activity.JpdlBinding;
 import org.jbpm.jpdl.internal.activity.MailListener;
 import org.jbpm.jpdl.internal.model.JpdlProcessDefinition;
-import org.jbpm.pvm.internal.el.JbpmElFactory;
 import org.jbpm.pvm.internal.email.impl.MailProducerImpl;
 import org.jbpm.pvm.internal.email.impl.MailTemplate;
 import org.jbpm.pvm.internal.email.impl.MailTemplateRegistry;
@@ -119,9 +113,6 @@
   public static final String CATEGORY_ACTIVITY = "activity";
   public static final String CATEGORY_EVENT_LISTENER = "eventlistener";
 
-  protected ExpressionFactory expressionFactory;
-  protected ELContext elContext;
-
   public JpdlParser() {
     initialize(); 
     parseBindings();
@@ -741,22 +732,4 @@
   public Set<String> getActivityTagNames() {
     return getBindings().getTagNames(CATEGORY_ACTIVITY);
   }
-
-  public ValueExpression createValueExpression(String expressionText) {
-    initializeExpressionLanguageParsing();
-    return expressionFactory.createValueExpression(elContext, expressionText, Object.class);
-  }
-
-  public MethodExpression createMethodExpression(String expressionText) {
-    initializeExpressionLanguageParsing();
-    return expressionFactory.createMethodExpression(elContext, expressionText, null, new Class<?>[]{});
-  }
-
-  protected void initializeExpressionLanguageParsing() {
-    if (elContext==null) {
-      JbpmElFactory jbpmElFactory = JbpmElFactory.getJbpmElFactory();
-      expressionFactory = jbpmElFactory.createExpressionFactory();
-      elContext = jbpmElFactory.createElContext();
-    }
-  }
 }

Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java	2010-01-28 09:13:45 UTC (rev 6143)
@@ -0,0 +1,142 @@
+/*
+ * 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.el;
+
+import java.io.Serializable;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+
+import org.jbpm.api.Execution;
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.task.Task;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class Expression implements Serializable {
+
+  private static final long serialVersionUID = 1L;
+
+  public static final String TYPE_METHOD = "method";
+  public static final String TYPE_VALUE = "value";
+
+  private static ExpressionFactory expressionFactory = null;
+  private static ELContext elContext = null;
+
+  protected ValueExpression valueExpression;
+  protected MethodExpression methodExpression;
+
+  // paring ///////////////////////////////////////////////////////////////////
+  
+  public Expression(String expressionText, String exprType) {
+    // if there is an expr specified
+    if (expressionText==null) {
+      throw new JbpmException("expressionText is null");
+    }
+
+    initExpressionObjects();
+
+    // by default, expr is interpreted as a value expression
+    if (exprType==null || TYPE_VALUE.equals(exprType)) {
+      try {
+        valueExpression = expressionFactory.createValueExpression(elContext, expressionText, Object.class);
+        
+      // if the expr is not a valid value expr...
+      } catch (ELException e) {
+        // ... and the expr-type was not specified 
+        if (exprType==null) {
+          // then try to parse it as a method expression
+          exprType = TYPE_METHOD;
+        }
+      } 
+    } 
+
+    if (TYPE_METHOD.equals(exprType)) {
+      methodExpression = expressionFactory.createMethodExpression(elContext, expressionText, null, new Class<?>[]{});
+    }
+  }
+
+  protected synchronized void initExpressionObjects() {
+    if (elContext==null) {
+      JbpmElFactory jbpmElFactory = JbpmElFactory.getJbpmElFactory();
+      expressionFactory = jbpmElFactory.createExpressionFactory();
+      elContext = jbpmElFactory.createElContext();
+    }
+  }
+
+  // runtime evaluation ///////////////////////////////////////////////////////
+  
+  public Object evaluate(Execution execution) {
+    ELContext elContext = getElContext((ExecutionImpl) execution);
+    return getResult(elContext);
+  }
+
+  public Object evaluate(Task task) {
+    ELContext elContext = getElContext((ExecutionImpl) task);
+    return getResult(elContext);
+  }
+
+  public void setValue(Task task, Object value) {
+    setValue((ScopeInstanceImpl)task, value);
+  }
+  
+  public void setValue(Execution execution, Object value) {
+    setValue((ScopeInstanceImpl)execution, value);
+  }
+  
+  public void setValue(ScopeInstanceImpl scopeInstance, Object value) {
+    if (valueExpression==null) {
+      throw new JbpmException("no value expression configured");
+    }
+    ELContext elContext = getElContext(scopeInstance);
+    valueExpression.setValue(elContext, value);
+  }
+
+  protected ELContext getElContext(ScopeInstanceImpl scopeInstance) {
+    ELContext elContext = (ELContext) scopeInstance.getElContext();
+    if (elContext==null) {
+      JbpmElFactory contextFactory = JbpmElFactory.getJbpmElFactory();
+      elContext = contextFactory.createElContext(scopeInstance);
+      scopeInstance.setElContext(elContext);
+    }
+    return elContext;
+  }
+
+  protected Object getResult(ELContext elContext) {
+    Object result = null;
+    if (valueExpression!=null) {
+      result = valueExpression.getValue(elContext);
+      
+    } else if (methodExpression!=null) {
+      result = methodExpression.invoke((ELContext) elContext, null);
+    }
+
+    return result;
+  }
+}


Property changes on: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2010-01-28 08:51:56 UTC (rev 6142)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java	2010-01-28 09:13:45 UTC (rev 6143)
@@ -21,7 +21,6 @@
  */
 package org.jbpm.pvm.internal.model;
 
-import java.io.PrintWriter;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -35,11 +34,6 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import javax.el.ELContext;
-import javax.el.ExpressionFactory;
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-
 import org.jbpm.api.Execution;
 import org.jbpm.api.JbpmException;
 import org.jbpm.api.activity.ActivityExecution;
@@ -55,8 +49,6 @@
 import org.jbpm.internal.log.Log;
 import org.jbpm.pvm.internal.client.ClientProcessDefinition;
 import org.jbpm.pvm.internal.client.ClientProcessInstance;
-import org.jbpm.pvm.internal.el.JbpmElFactory;
-import org.jbpm.pvm.internal.el.JbpmElFactoryImpl;
 import org.jbpm.pvm.internal.env.Context;
 import org.jbpm.pvm.internal.env.EnvironmentImpl;
 import org.jbpm.pvm.internal.env.ExecutionContext;
@@ -87,8 +79,6 @@
 import org.jbpm.pvm.internal.util.Priority;
 import org.jbpm.pvm.internal.wire.usercode.UserCodeReference;
 
-import de.odysseus.el.TreeValueExpression;
-
 /**
  * @author Tom Baeyens
  */
@@ -167,8 +157,6 @@
   protected int eventListenerIndex;
 
   protected ObservableElementImpl eventSource;
-  
-  protected Object cachedElContext = null;
 
   // cached named executions //////////////////////////////////////////////////
   
@@ -685,31 +673,6 @@
     }
   }
 
-  public Object resolveElValueExpressionGet(ValueExpression valueExpression) {
-    initCachedElContext();
-    return valueExpression.getValue((ELContext) cachedElContext);
-  }
-
-  public void resolveElValueExpressionSet(ValueExpression valueExpression, Object value) {
-    initCachedElContext();
-    
-    log.debug("expression: "+valueExpression);
-    
-    valueExpression.setValue((ELContext) cachedElContext, value);
-  }
-
-  public Object resolveElMethodExpressionInvoke(MethodExpression methodExpression) {
-    initCachedElContext();
-    return methodExpression.invoke((ELContext) cachedElContext, null);
-  }
-
-  protected void initCachedElContext() {
-    if (cachedElContext==null) {
-      JbpmElFactory contextFactory = JbpmElFactory.getJbpmElFactory();
-      cachedElContext = contextFactory.createElContext(this);
-    }
-  }
-
   /** 
    * Important: Only use this if resolving an expression on another execution then the current execution
    * 

Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java	2010-01-28 08:51:56 UTC (rev 6142)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java	2010-01-28 09:13:45 UTC (rev 6143)
@@ -65,7 +65,10 @@
   
   protected String state;
   protected String suspendHistoryState;
-  
+
+  /** {@link Expression}s can cache the elContext for this execution here */
+  transient protected Object elContext = null;
+
   // variables ////////////////////////////////////////////////////////////////
 
   protected void initializeVariables(ScopeElementImpl scope, ExecutionImpl outerExecution) {
@@ -404,4 +407,10 @@
   public long getDbid() {
     return dbid;
   }
+  public Object getElContext() {
+    return elContext;
+  }
+  public void setElContext(Object elContext) {
+    this.elContext = elContext;
+  }
 }



More information about the jbpm-commits mailing list