[jbpm-commits] JBoss JBPM SVN: r1862 - in jbpm4/pvm/trunk/modules/core/src/main: java/org/jbpm/pvm/internal/wire/descriptor and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 11 06:31:46 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-08-11 06:31:46 -0400 (Mon, 11 Aug 2008)
New Revision: 1862

Added:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ExpressionDescriptor.java
Modified:
   jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
   jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/hibernate.wire.hbm.xml
Log:
added script manager lookup convenience method and expression descriptor

Modified: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java	2008-08-11 09:59:19 UTC (rev 1861)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/script/ScriptManager.java	2008-08-11 10:31:46 UTC (rev 1862)
@@ -40,6 +40,8 @@
  * @author Tom Baeyens
  */
 public class ScriptManager {
+  
+  private static final ScriptManager defaultScriptManager = createDefault();
 
   protected String defaultExpressionLanguage;
   protected String defaultScriptLanguage;
@@ -47,7 +49,18 @@
   protected String[] readContextNames = null;
   protected String writeContextName;
   
-  public static ScriptManager createDefault() {
+  public static ScriptManager getScriptManager() {
+    Environment environment = Environment.getCurrent();
+    if (environment!=null) {
+      ScriptManager scriptManager = environment.get(ScriptManager.class);
+      if (scriptManager!=null) {
+        return scriptManager;
+      }
+    }
+    return defaultScriptManager;
+  }
+  
+  private static ScriptManager createDefault() {
     WireDefinition wireDefinition = (WireDefinition) new WireParser().createParse()
         .setString(
             "<objects>" +
@@ -95,6 +108,10 @@
     if (scriptEngine==null) {
       throw new PvmException("no scripting engine configured for language "+language);
     }
+    
+    if (execution==null) {
+      return evaluate(scriptEngine, script);
+    }
 
     Environment environment = Environment.getCurrent();
     if (environment==null) {
@@ -104,15 +121,14 @@
       } finally {
         environment.close();
       }
+    }
 
-    } else {
-      ExecutionContext executionContext = new ExecutionContext(execution);
-      environment.addContext(executionContext);
-      try {
-        return evaluate(scriptEngine, script);
-      } finally {
-        environment.removeContext(executionContext);
-      }
+    ExecutionContext executionContext = new ExecutionContext(execution);
+    environment.addContext(executionContext);
+    try {
+      return evaluate(scriptEngine, script);
+    } finally {
+      environment.removeContext(executionContext);
     }
   }
   

Added: jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ExpressionDescriptor.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ExpressionDescriptor.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ExpressionDescriptor.java	2008-08-11 10:31:46 UTC (rev 1862)
@@ -0,0 +1,55 @@
+/*
+ * 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.wire.descriptor;
+
+import org.jbpm.pvm.internal.script.ScriptManager;
+import org.jbpm.pvm.internal.wire.WireContext;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class ExpressionDescriptor extends AbstractDescriptor {
+  
+  private static final long serialVersionUID = 1L;
+
+  String expression;
+  String language;
+  
+  public ExpressionDescriptor() {
+  }
+
+  public ExpressionDescriptor(String expression) {
+    this.expression = expression;
+  }
+
+  public ExpressionDescriptor(String expression, String language) {
+    this.expression = expression;
+    this.language = language;
+  }
+
+  public Object construct(WireContext wireContext) {
+    ScriptManager scriptManager = ScriptManager.getScriptManager();
+    return scriptManager.evaluate(expression, null, language);
+  }
+
+}

Modified: jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/hibernate.wire.hbm.xml
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/hibernate.wire.hbm.xml	2008-08-11 09:59:19 UTC (rev 1861)
+++ jbpm4/pvm/trunk/modules/core/src/main/resources/org/jbpm/pvm/hibernate.wire.hbm.xml	2008-08-11 10:31:46 UTC (rev 1862)
@@ -12,6 +12,7 @@
 	  char   : CharacterDescriptor
 	  class  : ClassDescriptor
 	  double : DoubleDescriptor
+    expr   : ExpressionDescriptor
 	  float  : FloatDescriptor 
 	  long   : LongDescriptor
 	  int    : IntegerDescriptor
@@ -121,6 +122,12 @@
 				<one-to-many class="org.jbpm.pvm.internal.wire.operation.AbstractOperation"/>
 			</list>
 		</subclass>
+    
+    <subclass name="ExpressionDescriptor" discriminator-value="expr">
+      <property name="expression" column="TEXT_" />
+      <property name="language" column="METHOD_" />
+    </subclass>
+    
 	</class>
 
   <!-- ### OPERATIONS ##################################################### -->




More information about the jbpm-commits mailing list