Author: adrianc
Date: Thu Jun 14 18:11:18 2012
New Revision: 1350354

URL: http://svn.apache.org/viewvc?rev=1350354&view=rev
Log:
Mini-language API cleanup - removed ContextAccessor.java that is no longer 
used, and simplified the MethodContext.java API. With this commit all script 
behavior has been moved to the model classes, and all script state is contained 
in MethodContext.java.

Removed:
    
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/ContextAccessor.java
Modified:
    
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java
    
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallBsh.java
    
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
    
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java
    
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java

Modified: 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java?rev=1350354&r1=1350353&r2=1350354&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java 
(original)
+++ 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/MethodContext.java 
Thu Jun 14 18:11:18 2012
@@ -18,7 +18,6 @@
  
*******************************************************************************/
 package org.ofbiz.minilang.method;
 
-import java.util.Iterator;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TimeZone;
@@ -35,37 +34,35 @@ import org.ofbiz.base.util.collections.F
 import org.ofbiz.base.util.string.FlexibleStringExpander;
 import org.ofbiz.entity.Delegator;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.security.Security;
 import org.ofbiz.security.authz.Authorization;
 import org.ofbiz.service.DispatchContext;
 import org.ofbiz.service.LocalDispatcher;
 
 /**
- * A single operation, does the specified operation on the given field
+ * A container for the Mini-language script engine state.
  */
-public class MethodContext implements Iterable<Map.Entry<String, Object>> {
+public final class MethodContext {
 
     public static final int EVENT = 1;
     public static final int SERVICE = 2;
 
-    protected Authorization authz;
-    protected DispatchContext ctx;
-    protected Delegator delegator;
-    protected LocalDispatcher dispatcher;
-    protected Map<String, Object> env = FastMap.newInstance();
-    protected ClassLoader loader;
-    protected Locale locale;
-    protected int methodType;
-    protected Map<String, Object> parameters;
-    protected HttpServletRequest request = null;
-    protected HttpServletResponse response = null;
-    protected Map<String, Object> results = null;
-    protected Security security;
-    protected TimeZone timeZone;
+    private Authorization authz;
+    private Delegator delegator;
+    private LocalDispatcher dispatcher;
+    private Map<String, Object> env = FastMap.newInstance();
+    private ClassLoader loader;
+    private Locale locale;
+    private int methodType;
+    private Map<String, Object> parameters;
+    private HttpServletRequest request = null;
+    private HttpServletResponse response = null;
+    private Map<String, Object> results = FastMap.newInstance();
+    private Security security;
+    private TimeZone timeZone;
     private int traceCount = 0;
     private int traceLogLevel = Debug.INFO;
-    protected GenericValue userLogin;
+    private GenericValue userLogin;
 
     public MethodContext(DispatchContext ctx, Map<String, ? extends Object> 
context, ClassLoader loader) {
         this.methodType = MethodContext.SERVICE;
@@ -77,7 +74,6 @@ public class MethodContext implements It
         this.delegator = ctx.getDelegator();
         this.authz = ctx.getAuthorization();
         this.security = ctx.getSecurity();
-        this.results = FastMap.newInstance();
         this.userLogin = (GenericValue) context.get("userLogin");
         if (this.loader == null) {
             try {
@@ -147,8 +143,6 @@ public class MethodContext implements It
                 if (this.userLogin == null)
                     this.userLogin = (GenericValue) 
this.request.getSession().getAttribute("userLogin");
             }
-        } else if (methodType == MethodContext.SERVICE) {
-            this.results = FastMap.newInstance();
         }
         if (this.loader == null) {
             try {
@@ -159,15 +153,6 @@ public class MethodContext implements It
         }
     }
 
-    public String expandString(FlexibleStringExpander originalExdr) {
-        return originalExdr.expandString(this.env);
-    }
-
-    /** Expands environment variables delimited with ${} */
-    public String expandString(String original) {
-        return FlexibleStringExpander.expandString(original, this.env);
-    }
-
     public Authorization getAuthz() {
         return this.authz;
     }
@@ -193,15 +178,11 @@ public class MethodContext implements It
      * @return The environment value if found, otherwise null.
      */
     public <T> T getEnv(String key) {
-        String ekey = this.expandString(key);
+        String ekey = FlexibleStringExpander.expandString(key, this.env);
         FlexibleMapAccessor<T> fma = FlexibleMapAccessor.getInstance(ekey);
         return this.getEnv(fma);
     }
 
-    public Iterator<Map.Entry<String, Object>> getEnvEntryIterator() {
-        return this.env.entrySet().iterator();
-    }
-
     public Map<String, Object> getEnvMap() {
         return this.env;
     }
@@ -262,10 +243,6 @@ public class MethodContext implements It
         return this.traceCount > 0;
     }
 
-    public Iterator<Map.Entry<String, Object>> iterator() {
-        return this.env.entrySet().iterator();
-    }
-
     /**
      * Calls putEnv for each entry in the Map, thus allowing for the 
additional flexibility in naming supported in that method.
      */
@@ -290,7 +267,7 @@ public class MethodContext implements It
      *            The value to set in the named environment location.
      */
     public <T> void putEnv(String key, T value) {
-        String ekey = this.expandString(key);
+        String ekey = FlexibleStringExpander.expandString(key, this.env);
         FlexibleMapAccessor<T> fma = FlexibleMapAccessor.getInstance(ekey);
         this.putEnv(fma, value);
     }
@@ -315,21 +292,11 @@ public class MethodContext implements It
      *            The name of the environment value to get. Can contain "." 
syntax elements as described above.
      */
     public <T> T removeEnv(String key) {
-        String ekey = this.expandString(key);
+        String ekey = FlexibleStringExpander.expandString(key, this.env);
         FlexibleMapAccessor<T> fma = FlexibleMapAccessor.getInstance(ekey);
         return this.removeEnv(fma);
     }
 
-    public void setErrorReturn(String errMsg, SimpleMethod simpleMethod) {
-        if (getMethodType() == MethodContext.EVENT) {
-            putEnv(simpleMethod.getEventErrorMessageName(), errMsg);
-            putEnv(simpleMethod.getEventResponseCodeName(), 
simpleMethod.getDefaultErrorCode());
-        } else if (getMethodType() == MethodContext.SERVICE) {
-            putEnv(simpleMethod.getServiceErrorMessageName(), errMsg);
-            putEnv(simpleMethod.getServiceResponseMessageName(), 
simpleMethod.getDefaultErrorCode());
-        }
-    }
-
     public void setTraceOff() {
         if (this.traceCount > 0) {
             this.traceCount--;

Modified: 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallBsh.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallBsh.java?rev=1350354&r1=1350353&r2=1350354&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallBsh.java
 (original)
+++ 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallBsh.java
 Thu Jun 14 18:11:18 2012
@@ -84,7 +84,7 @@ public final class CallBsh extends Metho
         bsh.setClassLoader(methodContext.getLoader());
         try {
             // setup environment
-            for (Map.Entry<String, Object> entry : methodContext) {
+            for (Map.Entry<String, Object> entry : 
methodContext.getEnvMap().entrySet()) {
                 bsh.set(entry.getKey(), entry.getValue());
             }
             // run external, from resource, first if resource specified

Modified: 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java?rev=1350354&r1=1350353&r2=1350354&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
 (original)
+++ 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
 Thu Jun 14 18:11:18 2012
@@ -70,7 +70,7 @@ public final class CallService extends M
     private final List<ResultToRequest> resultToRequestList;
     private final List<ResultToResult> resultToResultList;
     private final List<ResultToSession> resultToSessionList;
-    private final String serviceName;
+    private final FlexibleStringExpander serviceNameFse;
     private final String successCode;
     private final FlexibleMessage successPrefix;
     private final FlexibleMessage successSuffix;
@@ -85,7 +85,7 @@ public final class CallService extends M
             MiniLangValidate.requiredAttributes(simpleMethod, element, 
"service-name");
             MiniLangValidate.childElements(simpleMethod, element, 
"error-prefix", "error-suffix", "success-prefix", "success-suffix", 
"message-prefix", "message-suffix", "default-message", "results-to-map", 
"result-to-field", "result-to-request", "result-to-session", 
"result-to-result");
         }
-        serviceName = element.getAttribute("service-name");
+        serviceNameFse = 
FlexibleStringExpander.getInstance(element.getAttribute("service-name"));
         inMapFma = 
FlexibleMapAccessor.getInstance(element.getAttribute("in-map-name"));
         includeUserLogin = 
!"false".equals(element.getAttribute("include-user-login"));
         breakOnError = !"false".equals(element.getAttribute("break-on-error"));
@@ -167,7 +167,7 @@ public final class CallService extends M
         if (methodContext.isTraceOn()) {
             outputTraceMessage(methodContext, "Begin call-service.");
         }
-        String serviceName = methodContext.expandString(this.serviceName);
+        String serviceName = 
serviceNameFse.expandString(methodContext.getEnvMap());
         String errorCode = this.errorCode;
         if (errorCode.isEmpty()) {
             errorCode = simpleMethod.getDefaultErrorCode();
@@ -370,7 +370,7 @@ public final class CallService extends M
 
     @Override
     public void gatherArtifactInfo(ArtifactInfoContext aic) {
-        aic.addServiceName(this.serviceName);
+        aic.addServiceName(this.serviceNameFse.toString());
     }
 
     @Override
@@ -381,7 +381,7 @@ public final class CallService extends M
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder("<call-service ");
-        sb.append("service-name=\"").append(this.serviceName).append("\" ");
+        sb.append("service-name=\"").append(this.serviceNameFse).append("\" ");
         if (!this.inMapFma.isEmpty()) {
             sb.append("in-map-name=\"").append(this.inMapFma).append("\" ");
         }

Modified: 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java?rev=1350354&r1=1350353&r2=1350354&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java
 (original)
+++ 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/ValidateMethodCondition.java
 Thu Jun 14 18:11:18 2012
@@ -132,9 +132,6 @@ public final class ValidateMethodConditi
     }
 
     public void prettyPrint(StringBuilder messageBuffer, MethodContext 
methodContext) {
-        // allow methodContext to be null
-        String methodName = methodContext == null ? this.methodName : 
methodContext.expandString(this.methodName);
-        String className = methodContext == null ? this.className : 
methodContext.expandString(this.className);
         messageBuffer.append("validate-method[");
         messageBuffer.append(className);
         messageBuffer.append(".");

Modified: 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java?rev=1350354&r1=1350353&r2=1350354&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java
 (original)
+++ 
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java
 Thu Jun 14 18:11:18 2012
@@ -101,8 +101,8 @@ public final class CreateObject extends 
                     typeClass = methodObjectDef.getTypeClass(methodContext);
                 } catch (ClassNotFoundException e) {
                     String errMsg = "ERROR: Could not complete the " + 
simpleMethod.getShortDescription() + " process [Parameter type not found with 
name " + methodObjectDef.getTypeName() + "]";
-                    Debug.logError(errMsg, module);
-                    methodContext.setErrorReturn(errMsg, simpleMethod);
+                    Debug.logWarning(e, errMsg, module);
+                    simpleMethod.addErrorMessage(methodContext, errMsg);
                     return false;
                 }
                 parameterTypes[i] = typeClass;


Reply via email to