IDEMPIERE-598 Different errors when running Groovy scripts from Swing or Webui. Peer review.

This commit is contained in:
Heng Sin Low 2013-03-09 08:47:01 +08:00
parent f073540046
commit ba8cc7463f
3 changed files with 8 additions and 52 deletions

View File

@ -24,7 +24,6 @@ import java.math.BigDecimal;
import java.sql.CallableStatement; import java.sql.CallableStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.util.Properties; import java.util.Properties;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
@ -156,57 +155,13 @@ public final class ProcessUtil {
} }
ProcessCall process = null; ProcessCall process = null;
//always query equinox extension first //invoke process factory
process = Core.getProcess(className); process = Core.getProcess(className);
if (process == null) { if (process == null) {
//Get Class pi.setSummary("Failed to create new process instance for " + className, true);
Class<?> processClass = null;
//use context classloader if available
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader != null)
{
try
{
processClass = classLoader.loadClass(className);
}
catch (ClassNotFoundException ex)
{
log.log(Level.FINE, className, ex);
}
}
if (processClass == null)
{
classLoader = ProcessUtil.class.getClassLoader();
try
{
processClass = classLoader.loadClass(className);
}
catch (ClassNotFoundException ex)
{
log.log(Level.WARNING, className, ex);
pi.setSummary ("ClassNotFound", true);
return false; return false;
} }
}
if (processClass == null) {
pi.setSummary("No Instance for " + pi.getClassName(), true);
return false;
}
//Get Process
try
{
process = (ProcessCall)processClass.newInstance();
}
catch (Exception ex)
{
log.log(Level.WARNING, "Instance for " + className, ex);
pi.setSummary ("InstanceError", true);
return false;
}
}
boolean success = false; boolean success = false;
try try
@ -268,7 +223,7 @@ public final class ProcessUtil {
// now add the method arguments to the engine // now add the method arguments to the engine
engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", ctx); engine.put(MRule.ARGUMENTS_PREFIX + "Ctx", ctx);
if (trx == null) if (trx == null)
trx = Trx.get(pi.getTitle()+"_"+pi.getAD_PInstance_ID() + "_" + UUID.randomUUID(), true); trx = Trx.get(Trx.createTrxName(pi.getTitle()+"_"+pi.getAD_PInstance_ID()), true);
engine.put(MRule.ARGUMENTS_PREFIX + "Trx", trx); engine.put(MRule.ARGUMENTS_PREFIX + "Trx", trx);
engine.put(MRule.ARGUMENTS_PREFIX + "TrxName", trx.getTrxName()); engine.put(MRule.ARGUMENTS_PREFIX + "TrxName", trx.getTrxName());
engine.put(MRule.ARGUMENTS_PREFIX + "Record_ID", pi.getRecord_ID()); engine.put(MRule.ARGUMENTS_PREFIX + "Record_ID", pi.getRecord_ID());

View File

@ -26,7 +26,6 @@ import java.util.Properties;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import org.compiere.Adempiere;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -196,7 +195,7 @@ public class MRule extends X_AD_Rule
* @return ScriptEngine * @return ScriptEngine
*/ */
public ScriptEngine getScriptEngine() { public ScriptEngine getScriptEngine() {
factory = new ScriptEngineManager(Adempiere.class.getClassLoader()); factory = new ScriptEngineManager(getClass().getClassLoader());
String engineName = getEngineName(); String engineName = getEngineName();
if (engineName != null) if (engineName != null)
engine = factory.getEngineByName(getEngineName()); engine = factory.getEngineByName(getEngineName());

View File

@ -118,8 +118,10 @@ public class WProcessInfo extends ProcessInfo {
{ {
try { try {
int lastdot = className.lastIndexOf("."); int lastdot = className.lastIndexOf(".");
if (lastdot > 0) {
zkName = className.substring(0, lastdot) + ".W" + className.substring(lastdot+1); zkName = className.substring(0, lastdot) + ".W" + className.substring(lastdot+1);
this.getClass().getClassLoader().loadClass(zkName); this.getClass().getClassLoader().loadClass(zkName);
}
} catch (Exception e) { } catch (Exception e) {
zkName = null; zkName = null;
} }