KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > minilang > SimpleMethod


1 /*
2  * $Id: SimpleMethod.java 6248 2005-12-06 00:08:52Z jaz $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.minilang;
25
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Locale JavaDoc;
31 import java.util.Map JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 import javolution.util.FastList;
36 import javolution.util.FastMap;
37 import org.w3c.dom.Document JavaDoc;
38 import org.w3c.dom.Element JavaDoc;
39
40 import org.ofbiz.base.location.FlexibleLocation;
41 import org.ofbiz.base.util.Debug;
42 import org.ofbiz.base.util.UtilMisc;
43 import org.ofbiz.base.util.UtilProperties;
44 import org.ofbiz.base.util.UtilValidate;
45 import org.ofbiz.base.util.UtilXml;
46 import org.ofbiz.base.util.cache.UtilCache;
47 import org.ofbiz.entity.GenericEntity;
48 import org.ofbiz.entity.GenericValue;
49 import org.ofbiz.entity.transaction.GenericTransactionException;
50 import org.ofbiz.entity.transaction.TransactionUtil;
51 import org.ofbiz.minilang.method.MethodContext;
52 import org.ofbiz.minilang.method.MethodOperation;
53 import org.ofbiz.service.DispatchContext;
54 import org.ofbiz.service.ModelService;
55
56 /**
57  * SimpleMethod Mini Language Core Object
58  *
59  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
60  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
61  * @version $Rev: 6248 $
62  * @since 2.0
63  */

64 public class SimpleMethod {
65     
66     public static final String JavaDoc module = SimpleMethod.class.getName();
67     public static final String JavaDoc err_resource = "MiniLangErrorUiLabels";
68
69     protected static UtilCache simpleMethodsDirectCache = new UtilCache("minilang.SimpleMethodsDirect", 0, 0);
70     protected static UtilCache simpleMethodsResourceCache = new UtilCache("minilang.SimpleMethodsResource", 0, 0);
71     protected static UtilCache simpleMethodsURLCache = new UtilCache("minilang.SimpleMethodsURL", 0, 0);
72
73     // ----- Event Context Invokers -----
74

75     public static String JavaDoc runSimpleEvent(String JavaDoc xmlResource, String JavaDoc methodName, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws MiniLangException {
76         return runSimpleMethod(xmlResource, methodName, new MethodContext(request, response, null));
77     }
78
79     public static String JavaDoc runSimpleEvent(String JavaDoc xmlResource, String JavaDoc methodName, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, ClassLoader JavaDoc loader) throws MiniLangException {
80         return runSimpleMethod(xmlResource, methodName, new MethodContext(request, response, loader));
81     }
82
83     public static String JavaDoc runSimpleEvent(URL JavaDoc xmlURL, String JavaDoc methodName, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, ClassLoader JavaDoc loader) throws MiniLangException {
84         return runSimpleMethod(xmlURL, methodName, new MethodContext(request, response, loader));
85     }
86
87     // ----- Service Context Invokers -----
88

89     public static Map JavaDoc runSimpleService(String JavaDoc xmlResource, String JavaDoc methodName, DispatchContext ctx, Map JavaDoc context) throws MiniLangException {
90         MethodContext methodContext = new MethodContext(ctx, context, null);
91         runSimpleMethod(xmlResource, methodName, methodContext);
92         return methodContext.getResults();
93     }
94
95     public static Map JavaDoc runSimpleService(String JavaDoc xmlResource, String JavaDoc methodName, DispatchContext ctx, Map JavaDoc context, ClassLoader JavaDoc loader) throws MiniLangException {
96         MethodContext methodContext = new MethodContext(ctx, context, loader);
97         runSimpleMethod(xmlResource, methodName, methodContext);
98         return methodContext.getResults();
99     }
100
101     public static Map JavaDoc runSimpleService(URL JavaDoc xmlURL, String JavaDoc methodName, DispatchContext ctx, Map JavaDoc context, ClassLoader JavaDoc loader) throws MiniLangException {
102         MethodContext methodContext = new MethodContext(ctx, context, loader);
103         runSimpleMethod(xmlURL, methodName, methodContext);
104         return methodContext.getResults();
105     }
106
107     // ----- General Method Invokers -----
108

109     public static String JavaDoc runSimpleMethod(String JavaDoc xmlResource, String JavaDoc methodName, MethodContext methodContext) throws MiniLangException {
110         Map JavaDoc simpleMethods = getSimpleMethods(xmlResource, methodName, methodContext.getLoader());
111         SimpleMethod simpleMethod = (SimpleMethod) simpleMethods.get(methodName);
112         if (simpleMethod == null) {
113             throw new MiniLangException("Could not find SimpleMethod " + methodName + " in XML document in resource: " + xmlResource);
114         }
115         return simpleMethod.exec(methodContext);
116     }
117
118     public static String JavaDoc runSimpleMethod(URL JavaDoc xmlURL, String JavaDoc methodName, MethodContext methodContext) throws MiniLangException {
119         Map JavaDoc simpleMethods = getSimpleMethods(xmlURL, methodName);
120         SimpleMethod simpleMethod = (SimpleMethod) simpleMethods.get(methodName);
121         if (simpleMethod == null) {
122             throw new MiniLangException("Could not find SimpleMethod " + methodName + " in XML document from URL: " + xmlURL.toString());
123         }
124         return simpleMethod.exec(methodContext);
125     }
126
127     public static Map JavaDoc getSimpleMethods(String JavaDoc xmlResource, String JavaDoc methodName, ClassLoader JavaDoc loader) throws MiniLangException {
128         Map JavaDoc simpleMethods = (Map JavaDoc) simpleMethodsResourceCache.get(xmlResource);
129         if (simpleMethods == null) {
130             synchronized (SimpleMethod.class) {
131                 simpleMethods = (Map JavaDoc) simpleMethodsResourceCache.get(xmlResource);
132                 if (simpleMethods == null) {
133                     //URL xmlURL = UtilURL.fromResource(xmlResource, loader);
134
URL JavaDoc xmlURL = null;
135                     try {
136                         xmlURL = FlexibleLocation.resolveLocation(xmlResource, loader);
137                     } catch (MalformedURLException JavaDoc e) {
138                         throw new MiniLangException("Could not find SimpleMethod XML document in resource: " + xmlResource + "; error was: " + e.toString(), e);
139                     }
140
141                     if (xmlURL == null) {
142                         throw new MiniLangException("Could not find SimpleMethod XML document in resource: " + xmlResource);
143                     }
144                     simpleMethods = getAllSimpleMethods(xmlURL);
145
146                     // put it in the cache
147
simpleMethodsResourceCache.put(xmlResource, simpleMethods);
148                 }
149             }
150         }
151
152         return simpleMethods;
153     }
154
155     public static Map JavaDoc getSimpleMethods(URL JavaDoc xmlURL, String JavaDoc methodName) throws MiniLangException {
156         Map JavaDoc simpleMethods = (Map JavaDoc) simpleMethodsURLCache.get(xmlURL);
157
158         if (simpleMethods == null) {
159             synchronized (SimpleMethod.class) {
160                 simpleMethods = (Map JavaDoc) simpleMethodsURLCache.get(xmlURL);
161                 if (simpleMethods == null) {
162                     simpleMethods = getAllSimpleMethods(xmlURL);
163
164                     // put it in the cache
165
simpleMethodsURLCache.put(xmlURL, simpleMethods);
166                 }
167             }
168         }
169
170         return simpleMethods;
171     }
172
173     protected static Map JavaDoc getAllSimpleMethods(URL JavaDoc xmlURL) throws MiniLangException {
174         Map JavaDoc simpleMethods = FastMap.newInstance();
175
176         // read in the file
177
Document JavaDoc document = null;
178         try {
179             document = UtilXml.readXmlDocument(xmlURL, true);
180         } catch (java.io.IOException JavaDoc e) {
181             throw new MiniLangException("Could not read XML file", e);
182         } catch (org.xml.sax.SAXException JavaDoc e) {
183             throw new MiniLangException("Could not parse XML file", e);
184         } catch (javax.xml.parsers.ParserConfigurationException JavaDoc e) {
185             throw new MiniLangException("XML parser not setup correctly", e);
186         }
187
188         if (document == null) {
189             throw new MiniLangException("Could not find SimpleMethod XML document: " + xmlURL.toString());
190         }
191
192         Element JavaDoc rootElement = document.getDocumentElement();
193         List JavaDoc simpleMethodElements = UtilXml.childElementList(rootElement, "simple-method");
194
195         Iterator JavaDoc simpleMethodIter = simpleMethodElements.iterator();
196
197         while (simpleMethodIter.hasNext()) {
198             Element JavaDoc simpleMethodElement = (Element JavaDoc) simpleMethodIter.next();
199             SimpleMethod simpleMethod = new SimpleMethod(simpleMethodElement, simpleMethods, xmlURL.toString());
200             simpleMethods.put(simpleMethod.getMethodName(), simpleMethod);
201         }
202
203         return simpleMethods;
204     }
205
206     public static Map JavaDoc getDirectSimpleMethods(String JavaDoc name, String JavaDoc content, String JavaDoc fromLocation) throws MiniLangException {
207         Map JavaDoc simpleMethods = (Map JavaDoc) simpleMethodsDirectCache.get(name);
208
209         if (simpleMethods == null) {
210             synchronized (SimpleMethod.class) {
211                 simpleMethods = (Map JavaDoc) simpleMethodsDirectCache.get(name);
212                 if (simpleMethods == null) {
213                     simpleMethods = getAllDirectSimpleMethods(name, content, fromLocation);
214
215                     // put it in the cache
216
simpleMethodsDirectCache.put(name, simpleMethods);
217                 }
218             }
219         }
220
221         return simpleMethods;
222     }
223
224     protected static Map JavaDoc getAllDirectSimpleMethods(String JavaDoc name, String JavaDoc content, String JavaDoc fromLocation) throws MiniLangException {
225         if (UtilValidate.isEmpty(fromLocation)) {
226             fromLocation = "<location not known>";
227         }
228         
229         Map JavaDoc simpleMethods = FastMap.newInstance();
230
231         // read in the file
232
Document JavaDoc document = null;
233
234         try {
235             if (content != null) {
236                 document = UtilXml.readXmlDocument(content, true);
237             }
238         } catch (java.io.IOException JavaDoc e) {
239             throw new MiniLangException("Could not read XML content", e);
240         } catch (org.xml.sax.SAXException JavaDoc e) {
241             throw new MiniLangException("Could not parse direct XML content", e);
242         } catch (javax.xml.parsers.ParserConfigurationException JavaDoc e) {
243             throw new MiniLangException("XML parser not setup correctly", e);
244         }
245
246         if (document == null) {
247             throw new MiniLangException("Could not load SimpleMethod XML document: " + name);
248         }
249
250         Element JavaDoc rootElement = document.getDocumentElement();
251         List JavaDoc simpleMethodElements = UtilXml.childElementList(rootElement, "simple-method");
252
253         Iterator JavaDoc simpleMethodIter = simpleMethodElements.iterator();
254
255         while (simpleMethodIter.hasNext()) {
256             Element JavaDoc simpleMethodElement = (Element JavaDoc) simpleMethodIter.next();
257             SimpleMethod simpleMethod = new SimpleMethod(simpleMethodElement, simpleMethods, fromLocation);
258             simpleMethods.put(simpleMethod.getMethodName(), simpleMethod);
259         }
260
261         return simpleMethods;
262     }
263
264     // Member fields begin here...
265
protected List JavaDoc methodOperations = FastList.newInstance();
266     protected Map JavaDoc parentSimpleMethodsMap;
267     protected String JavaDoc fromLocation;
268     protected String JavaDoc methodName;
269     protected String JavaDoc shortDescription;
270     protected String JavaDoc defaultErrorCode;
271     protected String JavaDoc defaultSuccessCode;
272
273     protected String JavaDoc parameterMapName;
274
275     // event fields
276
protected String JavaDoc eventRequestName;
277     protected String JavaDoc eventResponseName;
278     protected String JavaDoc eventResponseCodeName;
279     protected String JavaDoc eventErrorMessageName;
280     protected String JavaDoc eventErrorMessageListName;
281     protected String JavaDoc eventEventMessageName;
282     protected String JavaDoc eventEventMessageListName;
283
284     // service fields
285
protected String JavaDoc serviceResponseMessageName;
286     protected String JavaDoc serviceErrorMessageName;
287     protected String JavaDoc serviceErrorMessageListName;
288     protected String JavaDoc serviceErrorMessageMapName;
289     protected String JavaDoc serviceSuccessMessageName;
290     protected String JavaDoc serviceSuccessMessageListName;
291
292     protected boolean loginRequired = true;
293     protected boolean useTransaction = true;
294
295     protected String JavaDoc localeName;
296     protected String JavaDoc delegatorName;
297     protected String JavaDoc securityName;
298     protected String JavaDoc dispatcherName;
299     protected String JavaDoc userLoginName;
300
301     public SimpleMethod(Element JavaDoc simpleMethodElement, Map JavaDoc parentSimpleMethodsMap, String JavaDoc fromLocation) {
302         this.parentSimpleMethodsMap = parentSimpleMethodsMap;
303         this.fromLocation = fromLocation;
304         this.methodName = simpleMethodElement.getAttribute("method-name");
305         this.shortDescription = simpleMethodElement.getAttribute("short-description");
306
307         defaultErrorCode = simpleMethodElement.getAttribute("default-error-code");
308         if (defaultErrorCode == null || defaultErrorCode.length() == 0) {
309             defaultErrorCode = "error";
310         }
311         defaultSuccessCode = simpleMethodElement.getAttribute("default-success-code");
312         if (defaultSuccessCode == null || defaultSuccessCode.length() == 0) {
313             defaultSuccessCode = "success";
314         }
315
316         parameterMapName = simpleMethodElement.getAttribute("parameter-map-name");
317         if (parameterMapName == null || parameterMapName.length() == 0) {
318             parameterMapName = "parameters";
319         }
320
321         eventRequestName = simpleMethodElement.getAttribute("event-request-object-name");
322         if (eventRequestName == null || eventRequestName.length() == 0) {
323             eventRequestName = "request";
324         }
325         eventResponseName = simpleMethodElement.getAttribute("event-response-object-name");
326         if (eventResponseName == null || eventResponseName.length() == 0) {
327             eventResponseName = "response";
328         }
329         eventResponseCodeName = simpleMethodElement.getAttribute("event-response-code-name");
330         if (eventResponseCodeName == null || eventResponseCodeName.length() == 0) {
331             eventResponseCodeName = "_response_code_";
332         }
333         eventErrorMessageName = simpleMethodElement.getAttribute("event-error-message-name");
334         if (eventErrorMessageName == null || eventErrorMessageName.length() == 0) {
335             eventErrorMessageName = "_error_message_";
336         }
337         eventErrorMessageListName = simpleMethodElement.getAttribute("event-error-message-list-name");
338         if (eventErrorMessageListName == null || eventErrorMessageListName.length() == 0) {
339             eventErrorMessageListName = "_error_message_list_";
340         }
341         eventEventMessageName = simpleMethodElement.getAttribute("event-event-message-name");
342         if (eventEventMessageName == null || eventEventMessageName.length() == 0) {
343             eventEventMessageName = "_event_message_";
344         }
345         eventEventMessageListName = simpleMethodElement.getAttribute("event-event-message-list-name");
346         if (eventEventMessageListName == null || eventEventMessageListName.length() == 0) {
347             eventEventMessageListName = "_event_message_list_";
348         }
349
350         serviceResponseMessageName = simpleMethodElement.getAttribute("service-response-message-name");
351         if (serviceResponseMessageName == null || serviceResponseMessageName.length() == 0) {
352             serviceResponseMessageName = "responseMessage";
353         }
354         serviceErrorMessageName = simpleMethodElement.getAttribute("service-error-message-name");
355         if (serviceErrorMessageName == null || serviceErrorMessageName.length() == 0) {
356             serviceErrorMessageName = "errorMessage";
357         }
358         serviceErrorMessageListName = simpleMethodElement.getAttribute("service-error-message-list-name");
359         if (serviceErrorMessageListName == null || serviceErrorMessageListName.length() == 0) {
360             serviceErrorMessageListName = "errorMessageList";
361         }
362         serviceErrorMessageMapName = simpleMethodElement.getAttribute("service-error-message-map-name");
363         if (serviceErrorMessageMapName == null || serviceErrorMessageMapName.length() == 0) {
364             serviceErrorMessageMapName = "errorMessageMap";
365         }
366
367         serviceSuccessMessageName = simpleMethodElement.getAttribute("service-success-message-name");
368         if (serviceSuccessMessageName == null || serviceSuccessMessageName.length() == 0) {
369             serviceSuccessMessageName = "successMessage";
370         }
371         serviceSuccessMessageListName = simpleMethodElement.getAttribute("service-success-message-list-name");
372         if (serviceSuccessMessageListName == null || serviceSuccessMessageListName.length() == 0) {
373             serviceSuccessMessageListName = "successMessageList";
374         }
375
376         loginRequired = !"false".equals(simpleMethodElement.getAttribute("login-required"));
377         useTransaction = !"false".equals(simpleMethodElement.getAttribute("use-transaction"));
378
379         localeName = simpleMethodElement.getAttribute("locale-name");
380         if (localeName == null || localeName.length() == 0) {
381             localeName = "locale";
382         }
383         delegatorName = simpleMethodElement.getAttribute("delegator-name");
384         if (delegatorName == null || delegatorName.length() == 0) {
385             delegatorName = "delegator";
386         }
387         securityName = simpleMethodElement.getAttribute("security-name");
388         if (securityName == null || securityName.length() == 0) {
389             securityName = "security";
390         }
391         dispatcherName = simpleMethodElement.getAttribute("dispatcher-name");
392         if (dispatcherName == null || dispatcherName.length() == 0) {
393             dispatcherName = "dispatcher";
394         }
395         userLoginName = simpleMethodElement.getAttribute("user-login-name");
396         if (userLoginName == null || userLoginName.length() == 0) {
397             userLoginName = "userLogin";
398         }
399
400         readOperations(simpleMethodElement, this.methodOperations, this);
401     }
402
403     public String JavaDoc getFromLocation() {
404         return this.fromLocation;
405     }
406     public String JavaDoc getMethodName() {
407         return this.methodName;
408     }
409
410     public SimpleMethod getSimpleMethodInSameFile(String JavaDoc simpleMethodName) {
411         if (parentSimpleMethodsMap == null) return null;
412         return (SimpleMethod) parentSimpleMethodsMap.get(simpleMethodName);
413     }
414
415     public String JavaDoc getShortDescription() {
416         return this.shortDescription + " [" + this.fromLocation + "#" + this.methodName + "]";
417     }
418
419     public String JavaDoc getDefaultErrorCode() {
420         return this.defaultErrorCode;
421     }
422
423     public String JavaDoc getDefaultSuccessCode() {
424         return this.defaultSuccessCode;
425     }
426
427     public String JavaDoc getParameterMapName() {
428         return this.parameterMapName;
429     }
430
431     // event fields
432
public String JavaDoc getEventRequestName() {
433         return this.eventRequestName;
434     }
435
436     public String JavaDoc getEventResponseCodeName() {
437         return this.eventResponseCodeName;
438     }
439
440     public String JavaDoc getEventErrorMessageName() {
441         return this.eventErrorMessageName;
442     }
443     public String JavaDoc getEventErrorMessageListName() {
444         return this.eventErrorMessageListName;
445     }
446
447     public String JavaDoc getEventEventMessageName() {
448         return this.eventEventMessageName;
449     }
450     public String JavaDoc getEventEventMessageListName() {
451         return this.eventEventMessageListName;
452     }
453
454     // service fields
455
public String JavaDoc getServiceResponseMessageName() {
456         return this.serviceResponseMessageName;
457     }
458
459     public String JavaDoc getServiceErrorMessageName() {
460         return this.serviceErrorMessageName;
461     }
462
463     public String JavaDoc getServiceErrorMessageListName() {
464         return this.serviceErrorMessageListName;
465     }
466
467     public String JavaDoc getServiceSuccessMessageName() {
468         return this.serviceSuccessMessageName;
469     }
470
471     public String JavaDoc getServiceSuccessMessageListName() {
472         return this.serviceSuccessMessageListName;
473     }
474
475     public boolean getLoginRequired() {
476         return this.loginRequired;
477     }
478
479     public boolean getUseTransaction() {
480         return this.useTransaction;
481     }
482
483     public String JavaDoc getDelegatorEnvName() {
484         return this.delegatorName;
485     }
486
487     public String JavaDoc getSecurityEnvName() {
488         return this.securityName;
489     }
490
491     public String JavaDoc getDispatcherEnvName() {
492         return this.dispatcherName;
493     }
494
495     public String JavaDoc getUserLoginEnvName() {
496         return this.userLoginName;
497     }
498
499     /** Execute the Simple Method operations */
500     public String JavaDoc exec(MethodContext methodContext) {
501         // always put the null field object in as "null"
502
methodContext.putEnv("null", GenericEntity.NULL_FIELD);
503         methodContext.putEnv("nullField", GenericEntity.NULL_FIELD);
504         
505         methodContext.putEnv(delegatorName, methodContext.getDelegator());
506         methodContext.putEnv(securityName, methodContext.getSecurity());
507         methodContext.putEnv(dispatcherName, methodContext.getDispatcher());
508         methodContext.putEnv(localeName, methodContext.getLocale());
509         methodContext.putEnv(parameterMapName, methodContext.getParameters());
510
511         if (methodContext.getMethodType() == MethodContext.EVENT) {
512             methodContext.putEnv(eventRequestName, methodContext.getRequest());
513             methodContext.putEnv(eventResponseName, methodContext.getResponse());
514         }
515         
516         methodContext.putEnv("methodName", this.getMethodName());
517         methodContext.putEnv("methodShortDescription", this.getShortDescription());
518
519
520         GenericValue userLogin = methodContext.getUserLogin();
521         Locale JavaDoc locale = methodContext.getLocale();
522                 
523         if (userLogin != null) {
524             methodContext.putEnv(userLoginName, userLogin);
525         }
526         if (loginRequired) {
527             if (userLogin == null) {
528                 Map JavaDoc messageMap = UtilMisc.toMap("shortDescription", shortDescription);
529                 String JavaDoc errMsg = UtilProperties.getMessage(SimpleMethod.err_resource, "simpleMethod.must_logged_process", messageMap, locale) + ".";
530
531                 if (methodContext.getMethodType() == MethodContext.EVENT) {
532                      methodContext.getRequest().setAttribute("_ERROR_MESSAGE_", errMsg);
533                     return defaultErrorCode;
534                 } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
535                     methodContext.putResult(ModelService.ERROR_MESSAGE, errMsg);
536                     methodContext.putResult(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
537                     return null;
538                 }
539             }
540         }
541
542         // if using transaction, try to start here
543
boolean beganTransaction = false;
544
545         if (useTransaction) {
546             try {
547                 beganTransaction = TransactionUtil.begin();
548             } catch (GenericTransactionException e) {
549                 String JavaDoc errMsg = UtilProperties.getMessage(SimpleMethod.err_resource, "simpleMethod.error_begin_transaction", locale) + ": " + e.getMessage();
550                 Debug.logWarning(errMsg, module);
551                 Debug.logWarning(e, module);
552                 if (methodContext.getMethodType() == MethodContext.EVENT) {
553                     methodContext.getRequest().setAttribute("_ERROR_MESSAGE_", errMsg);
554                     return defaultErrorCode;
555                 } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
556                     methodContext.putResult(ModelService.ERROR_MESSAGE, errMsg);
557                     methodContext.putResult(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR);
558                     return null;
559                 }
560             }
561         }
562
563         // declare errorMsg here just in case transaction ops fail
564
String JavaDoc errorMsg = "";
565
566         boolean finished = false;
567         try {
568             finished = runSubOps(methodOperations, methodContext);
569         } catch (Throwable JavaDoc t) {
570             // make SURE nothing gets thrown through
571
String JavaDoc errMsg = UtilProperties.getMessage(SimpleMethod.err_resource, "simpleMethod.error_running", locale) + ": " + t.getMessage();
572             Debug.logError(errMsg, module);
573             finished = false;
574             errorMsg += errMsg + "<br/>";
575         }
576         
577         String JavaDoc returnValue = null;
578         String JavaDoc response = null;
579         StringBuffer JavaDoc summaryErrorStringBuffer = new StringBuffer JavaDoc();
580         if (methodContext.getMethodType() == MethodContext.EVENT) {
581             boolean forceError = false;
582             
583             String JavaDoc tempErrorMsg = (String JavaDoc) methodContext.getEnv(eventErrorMessageName);
584             if (errorMsg.length() > 0 || (tempErrorMsg != null && tempErrorMsg.length() > 0)) {
585                 errorMsg += tempErrorMsg;
586                 methodContext.getRequest().setAttribute("_ERROR_MESSAGE_", errorMsg);
587                 forceError = true;
588                 
589                 summaryErrorStringBuffer.append(errorMsg);
590             }
591             List JavaDoc tempErrorMsgList = (List JavaDoc) methodContext.getEnv(eventErrorMessageListName);
592             if (tempErrorMsgList != null && tempErrorMsgList.size() > 0) {
593                 methodContext.getRequest().setAttribute("_ERROR_MESSAGE_LIST_", tempErrorMsgList);
594                 forceError = true;
595                 
596                 summaryErrorStringBuffer.append("; ");
597                 summaryErrorStringBuffer.append(tempErrorMsgList.toString());
598             }
599
600             String JavaDoc eventMsg = (String JavaDoc) methodContext.getEnv(eventEventMessageName);
601             if (eventMsg != null && eventMsg.length() > 0) {
602                 methodContext.getRequest().setAttribute("_EVENT_MESSAGE_", eventMsg);
603             }
604             List JavaDoc eventMsgList = (List JavaDoc) methodContext.getEnv(eventEventMessageListName);
605             if (eventMsgList != null && eventMsgList.size() > 0) {
606                 methodContext.getRequest().setAttribute("_EVENT_MESSAGE_LIST_", eventMsgList);
607             }
608
609             response = (String JavaDoc) methodContext.getEnv(eventResponseCodeName);
610             if (response == null || response.length() == 0) {
611                 if (forceError) {
612                     //override response code, always use error code
613
Debug.logInfo("No response code string found, but error messages found so assuming error; returning code [" + defaultErrorCode + "]", module);
614                     response = defaultErrorCode;
615                 } else {
616                     Debug.logInfo("No response code string or errors found, assuming success; returning code [" + defaultSuccessCode + "]", module);
617                     response = defaultSuccessCode;
618                 }
619             }
620             returnValue = response;
621         } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
622             boolean forceError = false;
623             
624             String JavaDoc tempErrorMsg = (String JavaDoc) methodContext.getEnv(serviceErrorMessageName);
625             if (errorMsg.length() > 0 || (tempErrorMsg != null && tempErrorMsg.length() > 0)) {
626                 errorMsg += tempErrorMsg;
627                 methodContext.putResult(ModelService.ERROR_MESSAGE, errorMsg);
628                 forceError = true;
629
630                 summaryErrorStringBuffer.append(errorMsg);
631             }
632
633             List JavaDoc errorMsgList = (List JavaDoc) methodContext.getEnv(serviceErrorMessageListName);
634             if (errorMsgList != null && errorMsgList.size() > 0) {
635                 methodContext.putResult(ModelService.ERROR_MESSAGE_LIST, errorMsgList);
636                 forceError = true;
637                 
638                 summaryErrorStringBuffer.append("; ");
639                 summaryErrorStringBuffer.append(errorMsgList.toString());
640             }
641
642             Map JavaDoc errorMsgMap = (Map JavaDoc) methodContext.getEnv(serviceErrorMessageMapName);
643             if (errorMsgMap != null && errorMsgMap.size() > 0) {
644                 methodContext.putResult(ModelService.ERROR_MESSAGE_MAP, errorMsgMap);
645                 forceError = true;
646                 
647                 summaryErrorStringBuffer.append("; ");
648                 summaryErrorStringBuffer.append(errorMsgMap.toString());
649             }
650
651             String JavaDoc successMsg = (String JavaDoc) methodContext.getEnv(serviceSuccessMessageName);
652             if (successMsg != null && successMsg.length() > 0) {
653                 methodContext.putResult(ModelService.SUCCESS_MESSAGE, successMsg);
654             }
655
656             List JavaDoc successMsgList = (List JavaDoc) methodContext.getEnv(serviceSuccessMessageListName);
657             if (successMsgList != null && successMsgList.size() > 0) {
658                 methodContext.putResult(ModelService.SUCCESS_MESSAGE_LIST, successMsgList);
659             }
660
661             response = (String JavaDoc) methodContext.getEnv(serviceResponseMessageName);
662             if (response == null || response.length() == 0) {
663                 if (forceError) {
664                     //override response code, always use error code
665
Debug.logVerbose("No response code string found, but error messages found so assuming error; returning code [" + defaultErrorCode + "]", module);
666                     response = defaultErrorCode;
667                 } else {
668                     Debug.logVerbose("No response code string or errors found, assuming success; returning code [" + defaultSuccessCode + "]", module);
669                     response = defaultSuccessCode;
670                 }
671             }
672             methodContext.putResult(ModelService.RESPONSE_MESSAGE, response);
673             returnValue = null;
674         } else {
675             response = defaultSuccessCode;
676             returnValue = defaultSuccessCode;
677         }
678
679         // decide whether or not to commit based on the response message, ie only rollback if error is returned and not finished
680
boolean doCommit = true;
681         if (!finished && defaultErrorCode.equals(response)) {
682             doCommit = false;
683         }
684
685         if (doCommit) {
686             // commit here passing beganTransaction to perform it properly
687
try {
688                 TransactionUtil.commit(beganTransaction);
689             } catch (GenericTransactionException e) {
690                 String JavaDoc errMsg = "Error trying to commit transaction, could not process method: " + e.getMessage();
691                 Debug.logWarning(e, errMsg, module);
692                 errorMsg += errMsg + "<br/>";
693             }
694         } else {
695             // rollback here passing beganTransaction to either rollback, or set rollback only
696
try {
697                 TransactionUtil.rollback(beganTransaction, "Error in simple-method [" + this.getShortDescription() + "]: " + summaryErrorStringBuffer, null);
698             } catch (GenericTransactionException e) {
699                 String JavaDoc errMsg = "Error trying to rollback transaction, could not process method: " + e.getMessage();
700                 Debug.logWarning(e, errMsg, module);
701                 errorMsg += errMsg + "<br/>";
702             }
703         }
704         
705         return returnValue;
706     }
707
708     public static void readOperations(Element JavaDoc simpleMethodElement, List JavaDoc methodOperations, SimpleMethod simpleMethod) {
709         List JavaDoc operationElements = UtilXml.childElementList(simpleMethodElement);
710
711         if (operationElements != null && operationElements.size() > 0) {
712             Iterator JavaDoc operElemIter = operationElements.iterator();
713
714             while (operElemIter.hasNext()) {
715                 Element JavaDoc curOperElem = (Element JavaDoc) operElemIter.next();
716                 String JavaDoc nodeName = curOperElem.getNodeName();
717
718                 if ("call-map-processor".equals(nodeName)) {
719                     methodOperations.add(new org.ofbiz.minilang.method.callops.CallSimpleMapProcessor(curOperElem, simpleMethod));
720                 } else if ("check-errors".equals(nodeName)) {
721                     methodOperations.add(new org.ofbiz.minilang.method.callops.CheckErrors(curOperElem, simpleMethod));
722                 } else if ("add-error".equals(nodeName)) {
723                     methodOperations.add(new org.ofbiz.minilang.method.callops.AddError(curOperElem, simpleMethod));
724                 } else if ("return".equals(nodeName)) {
725                     methodOperations.add(new org.ofbiz.minilang.method.callops.Return(curOperElem, simpleMethod));
726                 } else if ("set-service-fields".equals(nodeName)) {
727                     methodOperations.add(new org.ofbiz.minilang.method.callops.SetServiceFields(curOperElem, simpleMethod));
728                 } else if ("call-service".equals(nodeName)) {
729                     methodOperations.add(new org.ofbiz.minilang.method.callops.CallService(curOperElem, simpleMethod));
730                 } else if ("call-service-asynch".equals(nodeName)) {
731                     methodOperations.add(new org.ofbiz.minilang.method.callops.CallServiceAsynch(curOperElem, simpleMethod));
732                 } else if ("call-bsh".equals(nodeName)) {
733                     methodOperations.add(new org.ofbiz.minilang.method.callops.CallBsh(curOperElem, simpleMethod));
734                 } else if ("call-simple-method".equals(nodeName)) {
735                     methodOperations.add(new org.ofbiz.minilang.method.callops.CallSimpleMethod(curOperElem, simpleMethod));
736
737                 } else if ("call-object-method".equals(nodeName)) {
738                     methodOperations.add(new org.ofbiz.minilang.method.callops.CallObjectMethod(curOperElem, simpleMethod));
739                 } else if ("call-class-method".equals(nodeName)) {
740                     methodOperations.add(new org.ofbiz.minilang.method.callops.CallClassMethod(curOperElem, simpleMethod));
741                 } else if ("create-object".equals(nodeName)) {
742                     methodOperations.add(new org.ofbiz.minilang.method.callops.CreateObject(curOperElem, simpleMethod));
743                     
744                 } else if ("field-to-request".equals(nodeName)) {
745                     methodOperations.add(new org.ofbiz.minilang.method.eventops.FieldToRequest(curOperElem, simpleMethod));
746                 } else if ("field-to-session".equals(nodeName)) {
747                     methodOperations.add(new org.ofbiz.minilang.method.eventops.FieldToSession(curOperElem, simpleMethod));
748                 } else if ("request-to-field".equals(nodeName)) {
749                     methodOperations.add(new org.ofbiz.minilang.method.eventops.RequestToField(curOperElem, simpleMethod));
750                 } else if ("request-parameters-to-list".equals(nodeName)) {
751                     methodOperations.add(new org.ofbiz.minilang.method.eventops.RequestParametersToList(curOperElem, simpleMethod));
752                 } else if ("session-to-field".equals(nodeName)) {
753                     methodOperations.add(new org.ofbiz.minilang.method.eventops.SessionToField(curOperElem, simpleMethod));
754                 } else if ("webapp-property-to-field".equals(nodeName)) {
755                     methodOperations.add(new org.ofbiz.minilang.method.eventops.WebappPropertyToField(curOperElem, simpleMethod));
756
757                 } else if ("field-to-result".equals(nodeName)) {
758                     methodOperations.add(new org.ofbiz.minilang.method.serviceops.FieldToResult(curOperElem, simpleMethod));
759
760                 } else if ("map-to-map".equals(nodeName)) {
761                     methodOperations.add(new org.ofbiz.minilang.method.envops.MapToMap(curOperElem, simpleMethod));
762                 } else if ("field-to-list".equals(nodeName)) {
763                     methodOperations.add(new org.ofbiz.minilang.method.envops.FieldToList(curOperElem, simpleMethod));
764                 } else if ("list-to-list".equals(nodeName)) {
765                     methodOperations.add(new org.ofbiz.minilang.method.envops.ListToList(curOperElem, simpleMethod));
766                 } else if ("order-map-list".equals(nodeName)) {
767                     methodOperations.add(new org.ofbiz.minilang.method.envops.OrderMapList(curOperElem, simpleMethod));
768
769                 } else if ("set".equals(nodeName)) {
770                     methodOperations.add(new org.ofbiz.minilang.method.envops.SetOperation(curOperElem, simpleMethod));
771                 } else if ("env-to-env".equals(nodeName)) {
772                     MethodOperation mop = new org.ofbiz.minilang.method.envops.EnvToEnv(curOperElem, simpleMethod);
773                     methodOperations.add(mop);
774                     Debug.logInfo("The env-to-env operation has been deprecated in favor of the set operation; found use of this in [" + simpleMethod.getShortDescription() + "]: " + mop.rawString(), module);
775                 } else if ("env-to-field".equals(nodeName)) {
776                     MethodOperation mop = new org.ofbiz.minilang.method.envops.EnvToField(curOperElem, simpleMethod);
777                     methodOperations.add(mop);
778                     Debug.logInfo("The env-to-field operation has been deprecated in favor of the set operation; found use of this in [" + simpleMethod.getShortDescription() + "]: " + mop.rawString(), module);
779                 } else if ("field-to-env".equals(nodeName)) {
780                     MethodOperation mop = new org.ofbiz.minilang.method.envops.FieldToEnv(curOperElem, simpleMethod);
781                     methodOperations.add(mop);
782                     Debug.logInfo("The field-to-env operation has been deprecated in favor of the set operation; found use of this in [" + simpleMethod.getShortDescription() + "]: " + mop.rawString(), module);
783                 } else if ("field-to-field".equals(nodeName)) {
784                     MethodOperation mop = new org.ofbiz.minilang.method.envops.FieldToField(curOperElem, simpleMethod);
785                     methodOperations.add(mop);
786                     Debug.logInfo("The field-to-field operation has been deprecated in favor of the set operation; found use of this in [" + simpleMethod.getShortDescription() + "]: " + mop.rawString(), module);
787                 } else if ("string-to-field".equals(nodeName)) {
788                     MethodOperation mop = new org.ofbiz.minilang.method.envops.StringToField(curOperElem, simpleMethod);
789                     methodOperations.add(mop);
790                     Debug.logInfo("The string-to-field operation has been deprecated in favor of the set operation; found use of this in [" + simpleMethod.getShortDescription() + "]: " + mop.rawString(), module);
791
792                 } else if ("string-append".equals(nodeName)) {
793                     methodOperations.add(new org.ofbiz.minilang.method.envops.StringAppend(curOperElem, simpleMethod));
794                 } else if ("string-to-list".equals(nodeName)) {
795                     methodOperations.add(new org.ofbiz.minilang.method.envops.StringToList(curOperElem, simpleMethod));
796                 } else if ("to-string".equals(nodeName)) {
797                     methodOperations.add(new org.ofbiz.minilang.method.envops.ToString(curOperElem, simpleMethod));
798                 } else if ("clear-field".equals(nodeName)) {
799                     methodOperations.add(new org.ofbiz.minilang.method.envops.ClearField(curOperElem, simpleMethod));
800                 } else if ("iterate".equals(nodeName)) {
801                     methodOperations.add(new org.ofbiz.minilang.method.envops.Iterate(curOperElem, simpleMethod));
802                 } else if ("iterate-map".equals(nodeName)) {
803                     methodOperations.add(new org.ofbiz.minilang.method.envops.IterateMap(curOperElem, simpleMethod));
804                 } else if ("loop".equals(nodeName)) {
805                     methodOperations.add(new org.ofbiz.minilang.method.envops.Loop(curOperElem, simpleMethod));
806                 } else if ("first-from-list".equals(nodeName)) {
807                     methodOperations.add(new org.ofbiz.minilang.method.envops.FirstFromList(curOperElem, simpleMethod));
808
809                 } else if ("transaction-begin".equals(nodeName)) {
810                     methodOperations.add(new org.ofbiz.minilang.method.entityops.TransactionBegin(curOperElem, simpleMethod));
811                 } else if ("transaction-commit".equals(nodeName)) {
812                     methodOperations.add(new org.ofbiz.minilang.method.entityops.TransactionCommit(curOperElem, simpleMethod));
813                 } else if ("transaction-rollback".equals(nodeName)) {
814                     methodOperations.add(new org.ofbiz.minilang.method.entityops.TransactionRollback(curOperElem, simpleMethod));
815                     
816                 } else if ("now-timestamp-to-env".equals(nodeName)) {
817                     methodOperations.add(new org.ofbiz.minilang.method.entityops.NowTimestampToEnv(curOperElem, simpleMethod));
818                 } else if ("now-date-to-env".equals(nodeName)) {
819                     methodOperations.add(new org.ofbiz.minilang.method.entityops.NowDateToEnv(curOperElem, simpleMethod));
820                 } else if ("sequenced-id-to-env".equals(nodeName)) {
821                     methodOperations.add(new org.ofbiz.minilang.method.entityops.SequencedIdToEnv(curOperElem, simpleMethod));
822                 } else if ("make-next-seq-id".equals(nodeName)) {
823                     methodOperations.add(new org.ofbiz.minilang.method.entityops.MakeNextSeqId(curOperElem, simpleMethod));
824                 } else if ("set-current-user-login".equals(nodeName)) {
825                     methodOperations.add(new org.ofbiz.minilang.method.entityops.SetCurrentUserLogin(curOperElem, simpleMethod));
826
827                 } else if ("find-by-primary-key".equals(nodeName)) {
828                     methodOperations.add(new org.ofbiz.minilang.method.entityops.FindByPrimaryKey(curOperElem, simpleMethod));
829                 } else if ("find-by-and".equals(nodeName)) {
830                     methodOperations.add(new org.ofbiz.minilang.method.entityops.FindByAnd(curOperElem, simpleMethod));
831                 } else if ("entity-one".equals(nodeName)) {
832                     methodOperations.add(new org.ofbiz.minilang.method.entityops.EntityOne(curOperElem, simpleMethod));
833                 } else if ("entity-and".equals(nodeName)) {
834                     methodOperations.add(new org.ofbiz.minilang.method.entityops.EntityAnd(curOperElem, simpleMethod));
835                 } else if ("entity-condition".equals(nodeName)) {
836                     methodOperations.add(new org.ofbiz.minilang.method.entityops.EntityCondition(curOperElem, simpleMethod));
837                 } else if ("entity-count".equals(nodeName)) {
838                     methodOperations.add(new org.ofbiz.minilang.method.entityops.EntityCount(curOperElem, simpleMethod));
839                 } else if ("get-related-one".equals(nodeName)) {
840                     methodOperations.add(new org.ofbiz.minilang.method.entityops.GetRelatedOne(curOperElem, simpleMethod));
841                 } else if ("get-related".equals(nodeName)) {
842                     methodOperations.add(new org.ofbiz.minilang.method.entityops.GetRelated(curOperElem, simpleMethod));
843                 } else if ("filter-list-by-and".equals(nodeName)) {
844                     methodOperations.add(new org.ofbiz.minilang.method.entityops.FilterListByAnd(curOperElem, simpleMethod));
845                 } else if ("filter-list-by-date".equals(nodeName)) {
846                     methodOperations.add(new org.ofbiz.minilang.method.entityops.FilterListByDate(curOperElem, simpleMethod));
847                 } else if ("order-value-list".equals(nodeName)) {
848                     methodOperations.add(new org.ofbiz.minilang.method.entityops.OrderValueList(curOperElem, simpleMethod));
849
850                 } else if ("make-value".equals(nodeName)) {
851                     methodOperations.add(new org.ofbiz.minilang.method.entityops.MakeValue(curOperElem, simpleMethod));
852                 } else if ("clone-value".equals(nodeName)) {
853                     methodOperations.add(new org.ofbiz.minilang.method.entityops.CloneValue(curOperElem, simpleMethod));
854                 } else if ("create-value".equals(nodeName)) {
855                     methodOperations.add(new org.ofbiz.minilang.method.entityops.CreateValue(curOperElem, simpleMethod));
856                 } else if ("store-value".equals(nodeName)) {
857                     methodOperations.add(new org.ofbiz.minilang.method.entityops.StoreValue(curOperElem, simpleMethod));
858                 } else if ("refresh-value".equals(nodeName)) {
859                     methodOperations.add(new org.ofbiz.minilang.method.entityops.RefreshValue(curOperElem, simpleMethod));
860                 } else if ("remove-value".equals(nodeName)) {
861                     methodOperations.add(new org.ofbiz.minilang.method.entityops.RemoveValue(curOperElem, simpleMethod));
862                 } else if ("remove-related".equals(nodeName)) {
863                     methodOperations.add(new org.ofbiz.minilang.method.entityops.RemoveRelated(curOperElem, simpleMethod));
864                 } else if ("remove-by-and".equals(nodeName)) {
865                     methodOperations.add(new org.ofbiz.minilang.method.entityops.RemoveByAnd(curOperElem, simpleMethod));
866                 } else if ("clear-cache-line".equals(nodeName)) {
867                     methodOperations.add(new org.ofbiz.minilang.method.entityops.ClearCacheLine(curOperElem, simpleMethod));
868                 } else if ("clear-entity-caches".equals(nodeName)) {
869                     methodOperations.add(new org.ofbiz.minilang.method.entityops.ClearEntityCaches(curOperElem, simpleMethod));
870                 } else if ("set-pk-fields".equals(nodeName)) {
871                     methodOperations.add(new org.ofbiz.minilang.method.entityops.SetPkFields(curOperElem, simpleMethod));
872                 } else if ("set-nonpk-fields".equals(nodeName)) {
873                     methodOperations.add(new org.ofbiz.minilang.method.entityops.SetNonpkFields(curOperElem, simpleMethod));
874
875                 } else if ("store-list".equals(nodeName)) {
876                     methodOperations.add(new org.ofbiz.minilang.method.entityops.StoreList(curOperElem, simpleMethod));
877                 } else if ("remove-list".equals(nodeName)) {
878                     methodOperations.add(new org.ofbiz.minilang.method.entityops.RemoveList(curOperElem, simpleMethod));
879
880                 } else if ("assert".equals(nodeName)) {
881                     methodOperations.add(new org.ofbiz.minilang.method.conditional.Assert(curOperElem, simpleMethod));
882                 } else if ("if".equals(nodeName)) {
883                     methodOperations.add(new org.ofbiz.minilang.method.conditional.MasterIf(curOperElem, simpleMethod));
884                 } else if ("if-validate-method".equals(nodeName)) {
885                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfValidateMethod(curOperElem, simpleMethod));
886                 } else if ("if-instance-of".equals(nodeName)) {
887                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfInstanceOf(curOperElem, simpleMethod));
888                 } else if ("if-compare".equals(nodeName)) {
889                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfCompare(curOperElem, simpleMethod));
890                 } else if ("if-compare-field".equals(nodeName)) {
891                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfCompareField(curOperElem, simpleMethod));
892                 } else if ("if-regexp".equals(nodeName)) {
893                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfRegexp(curOperElem, simpleMethod));
894                 } else if ("if-empty".equals(nodeName)) {
895                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfEmpty(curOperElem, simpleMethod));
896                 } else if ("if-not-empty".equals(nodeName)) {
897                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfNotEmpty(curOperElem, simpleMethod));
898                 } else if ("if-has-permission".equals(nodeName)) {
899                     methodOperations.add(new org.ofbiz.minilang.method.ifops.IfHasPermission(curOperElem, simpleMethod));
900                 } else if ("check-permission".equals(nodeName)) {
901                     methodOperations.add(new org.ofbiz.minilang.method.ifops.CheckPermission(curOperElem, simpleMethod));
902                 } else if ("check-id".equals(nodeName)) {
903                     methodOperations.add(new org.ofbiz.minilang.method.ifops.CheckId(curOperElem, simpleMethod));
904                 } else if ("else".equals(nodeName)) {
905                     // don't add anything, but don't complain either, this one is handled in the individual operations
906
} else if ("property-to-field".equals(nodeName)) {
907                     methodOperations.add(new org.ofbiz.minilang.method.otherops.PropertyToField(curOperElem, simpleMethod));
908                 } else if ("calculate".equals(nodeName)) {
909                     methodOperations.add(new org.ofbiz.minilang.method.otherops.Calculate(curOperElem, simpleMethod));
910                 } else if ("log".equals(nodeName)) {
911                     methodOperations.add(new org.ofbiz.minilang.method.otherops.Log(curOperElem, simpleMethod));
912                     
913                 } else {
914                     Debug.logWarning("Operation element \"" + nodeName + "\" no recognized", module);
915                 }
916             }
917         }
918     }
919
920     /** Execs the given operations returning true if all return true, or returning
921      * false and stopping if any return false.
922      */

923     public static boolean runSubOps(List JavaDoc methodOperations, MethodContext methodContext) {
924         Iterator JavaDoc methodOpsIter = methodOperations.iterator();
925         while (methodOpsIter.hasNext()) {
926             MethodOperation methodOperation = (MethodOperation) methodOpsIter.next();
927             try {
928                 if (!methodOperation.exec(methodContext)) {
929                     return false;
930                 }
931             } catch (Throwable JavaDoc t) {
932                 String JavaDoc errMsg = "Error in simple-method operation [" + methodOperation.rawString() + "]: " + t.toString();
933                 Debug.logError(t, errMsg, module);
934                 throw new RuntimeException JavaDoc(errMsg);
935             }
936         }
937         return true;
938     }
939 }
940
Popular Tags