0001: /*******************************************************************************
0002: * Licensed to the Apache Software Foundation (ASF) under one
0003: * or more contributor license agreements. See the NOTICE file
0004: * distributed with this work for additional information
0005: * regarding copyright ownership. The ASF licenses this file
0006: * to you under the Apache License, Version 2.0 (the
0007: * "License"); you may not use this file except in compliance
0008: * with the License. You may obtain a copy of the License at
0009: *
0010: * http://www.apache.org/licenses/LICENSE-2.0
0011: *
0012: * Unless required by applicable law or agreed to in writing,
0013: * software distributed under the License is distributed on an
0014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015: * KIND, either express or implied. See the License for the
0016: * specific language governing permissions and limitations
0017: * under the License.
0018: *******************************************************************************/package org.ofbiz.minilang;
0019:
0020: import java.net.MalformedURLException;
0021: import java.net.URL;
0022: import java.util.Iterator;
0023: import java.util.List;
0024: import java.util.Locale;
0025: import java.util.Map;
0026: import javax.servlet.http.HttpServletRequest;
0027: import javax.servlet.http.HttpServletResponse;
0028:
0029: import javolution.util.FastList;
0030: import javolution.util.FastMap;
0031: import org.w3c.dom.Document;
0032: import org.w3c.dom.Element;
0033:
0034: import org.ofbiz.base.location.FlexibleLocation;
0035: import org.ofbiz.base.util.Debug;
0036: import org.ofbiz.base.util.UtilMisc;
0037: import org.ofbiz.base.util.UtilProperties;
0038: import org.ofbiz.base.util.UtilValidate;
0039: import org.ofbiz.base.util.UtilXml;
0040: import org.ofbiz.base.util.cache.UtilCache;
0041: import org.ofbiz.entity.GenericEntity;
0042: import org.ofbiz.entity.GenericValue;
0043: import org.ofbiz.entity.transaction.GenericTransactionException;
0044: import org.ofbiz.entity.transaction.TransactionUtil;
0045: import org.ofbiz.minilang.method.MethodContext;
0046: import org.ofbiz.minilang.method.MethodOperation;
0047: import org.ofbiz.service.DispatchContext;
0048: import org.ofbiz.service.ModelService;
0049:
0050: /**
0051: * SimpleMethod Mini Language Core Object
0052: */
0053: public class SimpleMethod {
0054:
0055: public static final String module = SimpleMethod.class.getName();
0056: public static final String err_resource = "MiniLangErrorUiLabels";
0057:
0058: protected static UtilCache simpleMethodsDirectCache = new UtilCache(
0059: "minilang.SimpleMethodsDirect", 0, 0);
0060: protected static UtilCache simpleMethodsResourceCache = new UtilCache(
0061: "minilang.SimpleMethodsResource", 0, 0);
0062: protected static UtilCache simpleMethodsURLCache = new UtilCache(
0063: "minilang.SimpleMethodsURL", 0, 0);
0064:
0065: // ----- Event Context Invokers -----
0066:
0067: public static String runSimpleEvent(String xmlResource,
0068: String methodName, HttpServletRequest request,
0069: HttpServletResponse response) throws MiniLangException {
0070: return runSimpleMethod(xmlResource, methodName,
0071: new MethodContext(request, response, null));
0072: }
0073:
0074: public static String runSimpleEvent(String xmlResource,
0075: String methodName, HttpServletRequest request,
0076: HttpServletResponse response, ClassLoader loader)
0077: throws MiniLangException {
0078: return runSimpleMethod(xmlResource, methodName,
0079: new MethodContext(request, response, loader));
0080: }
0081:
0082: public static String runSimpleEvent(URL xmlURL, String methodName,
0083: HttpServletRequest request, HttpServletResponse response,
0084: ClassLoader loader) throws MiniLangException {
0085: return runSimpleMethod(xmlURL, methodName, new MethodContext(
0086: request, response, loader));
0087: }
0088:
0089: // ----- Service Context Invokers -----
0090:
0091: public static Map runSimpleService(String xmlResource,
0092: String methodName, DispatchContext ctx, Map context)
0093: throws MiniLangException {
0094: MethodContext methodContext = new MethodContext(ctx, context,
0095: null);
0096: runSimpleMethod(xmlResource, methodName, methodContext);
0097: return methodContext.getResults();
0098: }
0099:
0100: public static Map runSimpleService(String xmlResource,
0101: String methodName, DispatchContext ctx, Map context,
0102: ClassLoader loader) throws MiniLangException {
0103: MethodContext methodContext = new MethodContext(ctx, context,
0104: loader);
0105: runSimpleMethod(xmlResource, methodName, methodContext);
0106: return methodContext.getResults();
0107: }
0108:
0109: public static Map runSimpleService(URL xmlURL, String methodName,
0110: DispatchContext ctx, Map context, ClassLoader loader)
0111: throws MiniLangException {
0112: MethodContext methodContext = new MethodContext(ctx, context,
0113: loader);
0114: runSimpleMethod(xmlURL, methodName, methodContext);
0115: return methodContext.getResults();
0116: }
0117:
0118: // ----- General Method Invokers -----
0119:
0120: public static String runSimpleMethod(String xmlResource,
0121: String methodName, MethodContext methodContext)
0122: throws MiniLangException {
0123: Map simpleMethods = getSimpleMethods(xmlResource, methodName,
0124: methodContext.getLoader());
0125: SimpleMethod simpleMethod = (SimpleMethod) simpleMethods
0126: .get(methodName);
0127: if (simpleMethod == null) {
0128: throw new MiniLangException("Could not find SimpleMethod "
0129: + methodName + " in XML document in resource: "
0130: + xmlResource);
0131: }
0132: return simpleMethod.exec(methodContext);
0133: }
0134:
0135: public static String runSimpleMethod(URL xmlURL, String methodName,
0136: MethodContext methodContext) throws MiniLangException {
0137: Map simpleMethods = getSimpleMethods(xmlURL, methodName);
0138: SimpleMethod simpleMethod = (SimpleMethod) simpleMethods
0139: .get(methodName);
0140: if (simpleMethod == null) {
0141: throw new MiniLangException("Could not find SimpleMethod "
0142: + methodName + " in XML document from URL: "
0143: + xmlURL.toString());
0144: }
0145: return simpleMethod.exec(methodContext);
0146: }
0147:
0148: public static Map getSimpleMethods(String xmlResource,
0149: String methodName, ClassLoader loader)
0150: throws MiniLangException {
0151: Map simpleMethods = (Map) simpleMethodsResourceCache
0152: .get(xmlResource);
0153: if (simpleMethods == null) {
0154: synchronized (SimpleMethod.class) {
0155: simpleMethods = (Map) simpleMethodsResourceCache
0156: .get(xmlResource);
0157: if (simpleMethods == null) {
0158: //URL xmlURL = UtilURL.fromResource(xmlResource, loader);
0159: URL xmlURL = null;
0160: try {
0161: xmlURL = FlexibleLocation.resolveLocation(
0162: xmlResource, loader);
0163: } catch (MalformedURLException e) {
0164: throw new MiniLangException(
0165: "Could not find SimpleMethod XML document in resource: "
0166: + xmlResource + "; error was: "
0167: + e.toString(), e);
0168: }
0169:
0170: if (xmlURL == null) {
0171: throw new MiniLangException(
0172: "Could not find SimpleMethod XML document in resource: "
0173: + xmlResource);
0174: }
0175: simpleMethods = getAllSimpleMethods(xmlURL);
0176:
0177: // put it in the cache
0178: simpleMethodsResourceCache.put(xmlResource,
0179: simpleMethods);
0180: }
0181: }
0182: }
0183:
0184: return simpleMethods;
0185: }
0186:
0187: public static Map getSimpleMethods(URL xmlURL, String methodName)
0188: throws MiniLangException {
0189: Map simpleMethods = (Map) simpleMethodsURLCache.get(xmlURL);
0190:
0191: if (simpleMethods == null) {
0192: synchronized (SimpleMethod.class) {
0193: simpleMethods = (Map) simpleMethodsURLCache.get(xmlURL);
0194: if (simpleMethods == null) {
0195: simpleMethods = getAllSimpleMethods(xmlURL);
0196:
0197: // put it in the cache
0198: simpleMethodsURLCache.put(xmlURL, simpleMethods);
0199: }
0200: }
0201: }
0202:
0203: return simpleMethods;
0204: }
0205:
0206: protected static Map getAllSimpleMethods(URL xmlURL)
0207: throws MiniLangException {
0208: Map simpleMethods = FastMap.newInstance();
0209:
0210: // read in the file
0211: Document document = null;
0212: try {
0213: document = UtilXml.readXmlDocument(xmlURL, true);
0214: } catch (java.io.IOException e) {
0215: throw new MiniLangException("Could not read XML file", e);
0216: } catch (org.xml.sax.SAXException e) {
0217: throw new MiniLangException("Could not parse XML file", e);
0218: } catch (javax.xml.parsers.ParserConfigurationException e) {
0219: throw new MiniLangException(
0220: "XML parser not setup correctly", e);
0221: }
0222:
0223: if (document == null) {
0224: throw new MiniLangException(
0225: "Could not find SimpleMethod XML document: "
0226: + xmlURL.toString());
0227: }
0228:
0229: Element rootElement = document.getDocumentElement();
0230: List simpleMethodElements = UtilXml.childElementList(
0231: rootElement, "simple-method");
0232:
0233: Iterator simpleMethodIter = simpleMethodElements.iterator();
0234:
0235: while (simpleMethodIter.hasNext()) {
0236: Element simpleMethodElement = (Element) simpleMethodIter
0237: .next();
0238: SimpleMethod simpleMethod = new SimpleMethod(
0239: simpleMethodElement, simpleMethods, xmlURL
0240: .toString());
0241: simpleMethods.put(simpleMethod.getMethodName(),
0242: simpleMethod);
0243: }
0244:
0245: return simpleMethods;
0246: }
0247:
0248: public static Map getDirectSimpleMethods(String name,
0249: String content, String fromLocation)
0250: throws MiniLangException {
0251: Map simpleMethods = (Map) simpleMethodsDirectCache.get(name);
0252:
0253: if (simpleMethods == null) {
0254: synchronized (SimpleMethod.class) {
0255: simpleMethods = (Map) simpleMethodsDirectCache
0256: .get(name);
0257: if (simpleMethods == null) {
0258: simpleMethods = getAllDirectSimpleMethods(name,
0259: content, fromLocation);
0260:
0261: // put it in the cache
0262: simpleMethodsDirectCache.put(name, simpleMethods);
0263: }
0264: }
0265: }
0266:
0267: return simpleMethods;
0268: }
0269:
0270: protected static Map getAllDirectSimpleMethods(String name,
0271: String content, String fromLocation)
0272: throws MiniLangException {
0273: if (UtilValidate.isEmpty(fromLocation)) {
0274: fromLocation = "<location not known>";
0275: }
0276:
0277: Map simpleMethods = FastMap.newInstance();
0278:
0279: // read in the file
0280: Document document = null;
0281:
0282: try {
0283: if (content != null) {
0284: document = UtilXml.readXmlDocument(content, true);
0285: }
0286: } catch (java.io.IOException e) {
0287: throw new MiniLangException("Could not read XML content", e);
0288: } catch (org.xml.sax.SAXException e) {
0289: throw new MiniLangException(
0290: "Could not parse direct XML content", e);
0291: } catch (javax.xml.parsers.ParserConfigurationException e) {
0292: throw new MiniLangException(
0293: "XML parser not setup correctly", e);
0294: }
0295:
0296: if (document == null) {
0297: throw new MiniLangException(
0298: "Could not load SimpleMethod XML document: " + name);
0299: }
0300:
0301: Element rootElement = document.getDocumentElement();
0302: List simpleMethodElements = UtilXml.childElementList(
0303: rootElement, "simple-method");
0304:
0305: Iterator simpleMethodIter = simpleMethodElements.iterator();
0306:
0307: while (simpleMethodIter.hasNext()) {
0308: Element simpleMethodElement = (Element) simpleMethodIter
0309: .next();
0310: SimpleMethod simpleMethod = new SimpleMethod(
0311: simpleMethodElement, simpleMethods, fromLocation);
0312: simpleMethods.put(simpleMethod.getMethodName(),
0313: simpleMethod);
0314: }
0315:
0316: return simpleMethods;
0317: }
0318:
0319: // Member fields begin here...
0320: protected List methodOperations = FastList.newInstance();
0321: protected Map parentSimpleMethodsMap;
0322: protected String fromLocation;
0323: protected String methodName;
0324: protected String shortDescription;
0325: protected String defaultErrorCode;
0326: protected String defaultSuccessCode;
0327:
0328: protected String parameterMapName;
0329:
0330: // event fields
0331: protected String eventRequestName;
0332: protected String eventSessionName;
0333: protected String eventResponseName;
0334: protected String eventResponseCodeName;
0335: protected String eventErrorMessageName;
0336: protected String eventErrorMessageListName;
0337: protected String eventEventMessageName;
0338: protected String eventEventMessageListName;
0339:
0340: // service fields
0341: protected String serviceResponseMessageName;
0342: protected String serviceErrorMessageName;
0343: protected String serviceErrorMessageListName;
0344: protected String serviceErrorMessageMapName;
0345: protected String serviceSuccessMessageName;
0346: protected String serviceSuccessMessageListName;
0347:
0348: protected boolean loginRequired = true;
0349: protected boolean useTransaction = true;
0350:
0351: protected String localeName;
0352: protected String delegatorName;
0353: protected String securityName;
0354: protected String dispatcherName;
0355: protected String userLoginName;
0356:
0357: public SimpleMethod(Element simpleMethodElement,
0358: Map parentSimpleMethodsMap, String fromLocation) {
0359: this .parentSimpleMethodsMap = parentSimpleMethodsMap;
0360: this .fromLocation = fromLocation;
0361: this .methodName = simpleMethodElement
0362: .getAttribute("method-name");
0363: this .shortDescription = simpleMethodElement
0364: .getAttribute("short-description");
0365:
0366: defaultErrorCode = simpleMethodElement
0367: .getAttribute("default-error-code");
0368: if (defaultErrorCode == null || defaultErrorCode.length() == 0) {
0369: defaultErrorCode = "error";
0370: }
0371: defaultSuccessCode = simpleMethodElement
0372: .getAttribute("default-success-code");
0373: if (defaultSuccessCode == null
0374: || defaultSuccessCode.length() == 0) {
0375: defaultSuccessCode = "success";
0376: }
0377:
0378: parameterMapName = simpleMethodElement
0379: .getAttribute("parameter-map-name");
0380: if (parameterMapName == null || parameterMapName.length() == 0) {
0381: parameterMapName = "parameters";
0382: }
0383:
0384: eventRequestName = simpleMethodElement
0385: .getAttribute("event-request-object-name");
0386: if (eventRequestName == null || eventRequestName.length() == 0) {
0387: eventRequestName = "request";
0388: }
0389: eventSessionName = simpleMethodElement
0390: .getAttribute("event-session-object-name");
0391: if (eventSessionName == null || eventSessionName.length() == 0) {
0392: eventSessionName = "session";
0393: }
0394: eventResponseName = simpleMethodElement
0395: .getAttribute("event-response-object-name");
0396: if (eventResponseName == null
0397: || eventResponseName.length() == 0) {
0398: eventResponseName = "response";
0399: }
0400: eventResponseCodeName = simpleMethodElement
0401: .getAttribute("event-response-code-name");
0402: if (eventResponseCodeName == null
0403: || eventResponseCodeName.length() == 0) {
0404: eventResponseCodeName = "_response_code_";
0405: }
0406: eventErrorMessageName = simpleMethodElement
0407: .getAttribute("event-error-message-name");
0408: if (eventErrorMessageName == null
0409: || eventErrorMessageName.length() == 0) {
0410: eventErrorMessageName = "_error_message_";
0411: }
0412: eventErrorMessageListName = simpleMethodElement
0413: .getAttribute("event-error-message-list-name");
0414: if (eventErrorMessageListName == null
0415: || eventErrorMessageListName.length() == 0) {
0416: eventErrorMessageListName = "_error_message_list_";
0417: }
0418: eventEventMessageName = simpleMethodElement
0419: .getAttribute("event-event-message-name");
0420: if (eventEventMessageName == null
0421: || eventEventMessageName.length() == 0) {
0422: eventEventMessageName = "_event_message_";
0423: }
0424: eventEventMessageListName = simpleMethodElement
0425: .getAttribute("event-event-message-list-name");
0426: if (eventEventMessageListName == null
0427: || eventEventMessageListName.length() == 0) {
0428: eventEventMessageListName = "_event_message_list_";
0429: }
0430:
0431: serviceResponseMessageName = simpleMethodElement
0432: .getAttribute("service-response-message-name");
0433: if (serviceResponseMessageName == null
0434: || serviceResponseMessageName.length() == 0) {
0435: serviceResponseMessageName = "responseMessage";
0436: }
0437: serviceErrorMessageName = simpleMethodElement
0438: .getAttribute("service-error-message-name");
0439: if (serviceErrorMessageName == null
0440: || serviceErrorMessageName.length() == 0) {
0441: serviceErrorMessageName = "errorMessage";
0442: }
0443: serviceErrorMessageListName = simpleMethodElement
0444: .getAttribute("service-error-message-list-name");
0445: if (serviceErrorMessageListName == null
0446: || serviceErrorMessageListName.length() == 0) {
0447: serviceErrorMessageListName = "errorMessageList";
0448: }
0449: serviceErrorMessageMapName = simpleMethodElement
0450: .getAttribute("service-error-message-map-name");
0451: if (serviceErrorMessageMapName == null
0452: || serviceErrorMessageMapName.length() == 0) {
0453: serviceErrorMessageMapName = "errorMessageMap";
0454: }
0455:
0456: serviceSuccessMessageName = simpleMethodElement
0457: .getAttribute("service-success-message-name");
0458: if (serviceSuccessMessageName == null
0459: || serviceSuccessMessageName.length() == 0) {
0460: serviceSuccessMessageName = "successMessage";
0461: }
0462: serviceSuccessMessageListName = simpleMethodElement
0463: .getAttribute("service-success-message-list-name");
0464: if (serviceSuccessMessageListName == null
0465: || serviceSuccessMessageListName.length() == 0) {
0466: serviceSuccessMessageListName = "successMessageList";
0467: }
0468:
0469: loginRequired = !"false".equals(simpleMethodElement
0470: .getAttribute("login-required"));
0471: useTransaction = !"false".equals(simpleMethodElement
0472: .getAttribute("use-transaction"));
0473:
0474: localeName = simpleMethodElement.getAttribute("locale-name");
0475: if (localeName == null || localeName.length() == 0) {
0476: localeName = "locale";
0477: }
0478: delegatorName = simpleMethodElement
0479: .getAttribute("delegator-name");
0480: if (delegatorName == null || delegatorName.length() == 0) {
0481: delegatorName = "delegator";
0482: }
0483: securityName = simpleMethodElement
0484: .getAttribute("security-name");
0485: if (securityName == null || securityName.length() == 0) {
0486: securityName = "security";
0487: }
0488: dispatcherName = simpleMethodElement
0489: .getAttribute("dispatcher-name");
0490: if (dispatcherName == null || dispatcherName.length() == 0) {
0491: dispatcherName = "dispatcher";
0492: }
0493: userLoginName = simpleMethodElement
0494: .getAttribute("user-login-name");
0495: if (userLoginName == null || userLoginName.length() == 0) {
0496: userLoginName = "userLogin";
0497: }
0498:
0499: readOperations(simpleMethodElement, this .methodOperations, this );
0500: }
0501:
0502: public String getFromLocation() {
0503: return this .fromLocation;
0504: }
0505:
0506: public String getMethodName() {
0507: return this .methodName;
0508: }
0509:
0510: public SimpleMethod getSimpleMethodInSameFile(
0511: String simpleMethodName) {
0512: if (parentSimpleMethodsMap == null)
0513: return null;
0514: return (SimpleMethod) parentSimpleMethodsMap
0515: .get(simpleMethodName);
0516: }
0517:
0518: public String getShortDescription() {
0519: return this .shortDescription + " [" + this .fromLocation + "#"
0520: + this .methodName + "]";
0521: }
0522:
0523: public String getDefaultErrorCode() {
0524: return this .defaultErrorCode;
0525: }
0526:
0527: public String getDefaultSuccessCode() {
0528: return this .defaultSuccessCode;
0529: }
0530:
0531: public String getParameterMapName() {
0532: return this .parameterMapName;
0533: }
0534:
0535: // event fields
0536: public String getEventRequestName() {
0537: return this .eventRequestName;
0538: }
0539:
0540: public String getEventSessionName() {
0541: return this .eventSessionName;
0542: }
0543:
0544: public String getEventResponseCodeName() {
0545: return this .eventResponseCodeName;
0546: }
0547:
0548: public String getEventErrorMessageName() {
0549: return this .eventErrorMessageName;
0550: }
0551:
0552: public String getEventErrorMessageListName() {
0553: return this .eventErrorMessageListName;
0554: }
0555:
0556: public String getEventEventMessageName() {
0557: return this .eventEventMessageName;
0558: }
0559:
0560: public String getEventEventMessageListName() {
0561: return this .eventEventMessageListName;
0562: }
0563:
0564: // service fields
0565: public String getServiceResponseMessageName() {
0566: return this .serviceResponseMessageName;
0567: }
0568:
0569: public String getServiceErrorMessageName() {
0570: return this .serviceErrorMessageName;
0571: }
0572:
0573: public String getServiceErrorMessageListName() {
0574: return this .serviceErrorMessageListName;
0575: }
0576:
0577: public String getServiceSuccessMessageName() {
0578: return this .serviceSuccessMessageName;
0579: }
0580:
0581: public String getServiceSuccessMessageListName() {
0582: return this .serviceSuccessMessageListName;
0583: }
0584:
0585: public boolean getLoginRequired() {
0586: return this .loginRequired;
0587: }
0588:
0589: public boolean getUseTransaction() {
0590: return this .useTransaction;
0591: }
0592:
0593: public String getDelegatorEnvName() {
0594: return this .delegatorName;
0595: }
0596:
0597: public String getSecurityEnvName() {
0598: return this .securityName;
0599: }
0600:
0601: public String getDispatcherEnvName() {
0602: return this .dispatcherName;
0603: }
0604:
0605: public String getUserLoginEnvName() {
0606: return this .userLoginName;
0607: }
0608:
0609: /** Execute the Simple Method operations */
0610: public String exec(MethodContext methodContext) {
0611: // always put the null field object in as "null"
0612: methodContext.putEnv("null", GenericEntity.NULL_FIELD);
0613: methodContext.putEnv("nullField", GenericEntity.NULL_FIELD);
0614:
0615: methodContext.putEnv(delegatorName, methodContext
0616: .getDelegator());
0617: methodContext.putEnv(securityName, methodContext.getSecurity());
0618: methodContext.putEnv(dispatcherName, methodContext
0619: .getDispatcher());
0620: methodContext.putEnv(localeName, methodContext.getLocale());
0621: methodContext.putEnv(parameterMapName, methodContext
0622: .getParameters());
0623:
0624: if (methodContext.getMethodType() == MethodContext.EVENT) {
0625: methodContext.putEnv(eventRequestName, methodContext
0626: .getRequest());
0627: methodContext.putEnv(eventSessionName, methodContext
0628: .getRequest().getSession());
0629: methodContext.putEnv(eventResponseName, methodContext
0630: .getResponse());
0631: }
0632:
0633: methodContext.putEnv("methodName", this .getMethodName());
0634: methodContext.putEnv("methodShortDescription", this
0635: .getShortDescription());
0636:
0637: GenericValue userLogin = methodContext.getUserLogin();
0638: Locale locale = methodContext.getLocale();
0639:
0640: if (userLogin != null) {
0641: methodContext.putEnv(userLoginName, userLogin);
0642: }
0643: if (loginRequired) {
0644: if (userLogin == null) {
0645: Map messageMap = UtilMisc.toMap("shortDescription",
0646: shortDescription);
0647: String errMsg = UtilProperties.getMessage(
0648: SimpleMethod.err_resource,
0649: "simpleMethod.must_logged_process", messageMap,
0650: locale)
0651: + ".";
0652:
0653: if (methodContext.getMethodType() == MethodContext.EVENT) {
0654: methodContext.getRequest().setAttribute(
0655: "_ERROR_MESSAGE_", errMsg);
0656: return defaultErrorCode;
0657: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
0658: methodContext.putResult(ModelService.ERROR_MESSAGE,
0659: errMsg);
0660: methodContext.putResult(
0661: ModelService.RESPONSE_MESSAGE,
0662: ModelService.RESPOND_ERROR);
0663: return null;
0664: }
0665: }
0666: }
0667:
0668: // if using transaction, try to start here
0669: boolean beganTransaction = false;
0670:
0671: if (useTransaction) {
0672: try {
0673: beganTransaction = TransactionUtil.begin();
0674: } catch (GenericTransactionException e) {
0675: String errMsg = UtilProperties.getMessage(
0676: SimpleMethod.err_resource,
0677: "simpleMethod.error_begin_transaction", locale)
0678: + ": " + e.getMessage();
0679: Debug.logWarning(errMsg, module);
0680: Debug.logWarning(e, module);
0681: if (methodContext.getMethodType() == MethodContext.EVENT) {
0682: methodContext.getRequest().setAttribute(
0683: "_ERROR_MESSAGE_", errMsg);
0684: return defaultErrorCode;
0685: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
0686: methodContext.putResult(ModelService.ERROR_MESSAGE,
0687: errMsg);
0688: methodContext.putResult(
0689: ModelService.RESPONSE_MESSAGE,
0690: ModelService.RESPOND_ERROR);
0691: return null;
0692: }
0693: }
0694: }
0695:
0696: // declare errorMsg here just in case transaction ops fail
0697: String errorMsg = "";
0698:
0699: boolean finished = false;
0700: try {
0701: finished = runSubOps(methodOperations, methodContext);
0702: } catch (Throwable t) {
0703: // make SURE nothing gets thrown through
0704: String errMsg = UtilProperties.getMessage(
0705: SimpleMethod.err_resource,
0706: "simpleMethod.error_running", locale)
0707: + ": " + t.getMessage();
0708: Debug.logError(errMsg, module);
0709: finished = false;
0710: errorMsg += errMsg + "<br/>";
0711: }
0712:
0713: String returnValue = null;
0714: String response = null;
0715: StringBuffer summaryErrorStringBuffer = new StringBuffer();
0716: if (methodContext.getMethodType() == MethodContext.EVENT) {
0717: boolean forceError = false;
0718:
0719: String tempErrorMsg = (String) methodContext
0720: .getEnv(eventErrorMessageName);
0721: if (errorMsg.length() > 0
0722: || (tempErrorMsg != null && tempErrorMsg.length() > 0)) {
0723: errorMsg += tempErrorMsg;
0724: methodContext.getRequest().setAttribute(
0725: "_ERROR_MESSAGE_", errorMsg);
0726: forceError = true;
0727:
0728: summaryErrorStringBuffer.append(errorMsg);
0729: }
0730: List tempErrorMsgList = (List) methodContext
0731: .getEnv(eventErrorMessageListName);
0732: if (tempErrorMsgList != null && tempErrorMsgList.size() > 0) {
0733: methodContext.getRequest().setAttribute(
0734: "_ERROR_MESSAGE_LIST_", tempErrorMsgList);
0735: forceError = true;
0736:
0737: summaryErrorStringBuffer.append("; ");
0738: summaryErrorStringBuffer.append(tempErrorMsgList
0739: .toString());
0740: }
0741:
0742: String eventMsg = (String) methodContext
0743: .getEnv(eventEventMessageName);
0744: if (eventMsg != null && eventMsg.length() > 0) {
0745: methodContext.getRequest().setAttribute(
0746: "_EVENT_MESSAGE_", eventMsg);
0747: }
0748: List eventMsgList = (List) methodContext
0749: .getEnv(eventEventMessageListName);
0750: if (eventMsgList != null && eventMsgList.size() > 0) {
0751: methodContext.getRequest().setAttribute(
0752: "_EVENT_MESSAGE_LIST_", eventMsgList);
0753: }
0754:
0755: response = (String) methodContext
0756: .getEnv(eventResponseCodeName);
0757: if (response == null || response.length() == 0) {
0758: if (forceError) {
0759: //override response code, always use error code
0760: Debug
0761: .logInfo(
0762: "No response code string found, but error messages found so assuming error; returning code ["
0763: + defaultErrorCode + "]",
0764: module);
0765: response = defaultErrorCode;
0766: } else {
0767: Debug.logInfo(
0768: "No response code string or errors found, assuming success; returning code ["
0769: + defaultSuccessCode + "]", module);
0770: response = defaultSuccessCode;
0771: }
0772: } else if ("null".equalsIgnoreCase(response)) {
0773: response = null;
0774: }
0775: returnValue = response;
0776: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
0777: boolean forceError = false;
0778:
0779: String tempErrorMsg = (String) methodContext
0780: .getEnv(serviceErrorMessageName);
0781: if (errorMsg.length() > 0
0782: || (tempErrorMsg != null && tempErrorMsg.length() > 0)) {
0783: errorMsg += tempErrorMsg;
0784: methodContext.putResult(ModelService.ERROR_MESSAGE,
0785: errorMsg);
0786: forceError = true;
0787:
0788: summaryErrorStringBuffer.append(errorMsg);
0789: }
0790:
0791: List errorMsgList = (List) methodContext
0792: .getEnv(serviceErrorMessageListName);
0793: if (errorMsgList != null && errorMsgList.size() > 0) {
0794: methodContext.putResult(
0795: ModelService.ERROR_MESSAGE_LIST, errorMsgList);
0796: forceError = true;
0797:
0798: summaryErrorStringBuffer.append("; ");
0799: summaryErrorStringBuffer
0800: .append(errorMsgList.toString());
0801: }
0802:
0803: Map errorMsgMap = (Map) methodContext
0804: .getEnv(serviceErrorMessageMapName);
0805: if (errorMsgMap != null && errorMsgMap.size() > 0) {
0806: methodContext.putResult(ModelService.ERROR_MESSAGE_MAP,
0807: errorMsgMap);
0808: forceError = true;
0809:
0810: summaryErrorStringBuffer.append("; ");
0811: summaryErrorStringBuffer.append(errorMsgMap.toString());
0812: }
0813:
0814: String successMsg = (String) methodContext
0815: .getEnv(serviceSuccessMessageName);
0816: if (successMsg != null && successMsg.length() > 0) {
0817: methodContext.putResult(ModelService.SUCCESS_MESSAGE,
0818: successMsg);
0819: }
0820:
0821: List successMsgList = (List) methodContext
0822: .getEnv(serviceSuccessMessageListName);
0823: if (successMsgList != null && successMsgList.size() > 0) {
0824: methodContext.putResult(
0825: ModelService.SUCCESS_MESSAGE_LIST,
0826: successMsgList);
0827: }
0828:
0829: response = (String) methodContext
0830: .getEnv(serviceResponseMessageName);
0831: if (response == null || response.length() == 0) {
0832: if (forceError) {
0833: //override response code, always use error code
0834: Debug
0835: .logVerbose(
0836: "No response code string found, but error messages found so assuming error; returning code ["
0837: + defaultErrorCode + "]",
0838: module);
0839: response = defaultErrorCode;
0840: } else {
0841: Debug.logVerbose(
0842: "No response code string or errors found, assuming success; returning code ["
0843: + defaultSuccessCode + "]", module);
0844: response = defaultSuccessCode;
0845: }
0846: }
0847: methodContext.putResult(ModelService.RESPONSE_MESSAGE,
0848: response);
0849: returnValue = null;
0850: } else {
0851: response = defaultSuccessCode;
0852: returnValue = defaultSuccessCode;
0853: }
0854:
0855: // decide whether or not to commit based on the response message, ie only rollback if error is returned and not finished
0856: boolean doCommit = true;
0857: if (!finished && defaultErrorCode.equals(response)) {
0858: doCommit = false;
0859: }
0860:
0861: if (doCommit) {
0862: // commit here passing beganTransaction to perform it properly
0863: try {
0864: TransactionUtil.commit(beganTransaction);
0865: } catch (GenericTransactionException e) {
0866: String errMsg = "Error trying to commit transaction, could not process method: "
0867: + e.getMessage();
0868: Debug.logWarning(e, errMsg, module);
0869: errorMsg += errMsg + "<br/>";
0870: }
0871: } else {
0872: // rollback here passing beganTransaction to either rollback, or set rollback only
0873: try {
0874: TransactionUtil.rollback(beganTransaction,
0875: "Error in simple-method ["
0876: + this .getShortDescription() + "]: "
0877: + summaryErrorStringBuffer, null);
0878: } catch (GenericTransactionException e) {
0879: String errMsg = "Error trying to rollback transaction, could not process method: "
0880: + e.getMessage();
0881: Debug.logWarning(e, errMsg, module);
0882: errorMsg += errMsg + "<br/>";
0883: }
0884: }
0885:
0886: return returnValue;
0887: }
0888:
0889: public static void readOperations(Element simpleMethodElement,
0890: List methodOperations, SimpleMethod simpleMethod) {
0891: List operationElements = UtilXml
0892: .childElementList(simpleMethodElement);
0893:
0894: if (operationElements != null && operationElements.size() > 0) {
0895: Iterator operElemIter = operationElements.iterator();
0896:
0897: while (operElemIter.hasNext()) {
0898: Element curOperElem = (Element) operElemIter.next();
0899: String nodeName = curOperElem.getNodeName();
0900:
0901: if ("call-map-processor".equals(nodeName)) {
0902: methodOperations
0903: .add(new org.ofbiz.minilang.method.callops.CallSimpleMapProcessor(
0904: curOperElem, simpleMethod));
0905: } else if ("check-errors".equals(nodeName)) {
0906: methodOperations
0907: .add(new org.ofbiz.minilang.method.callops.CheckErrors(
0908: curOperElem, simpleMethod));
0909: } else if ("add-error".equals(nodeName)) {
0910: methodOperations
0911: .add(new org.ofbiz.minilang.method.callops.AddError(
0912: curOperElem, simpleMethod));
0913: } else if ("return".equals(nodeName)) {
0914: methodOperations
0915: .add(new org.ofbiz.minilang.method.callops.Return(
0916: curOperElem, simpleMethod));
0917: } else if ("set-service-fields".equals(nodeName)) {
0918: methodOperations
0919: .add(new org.ofbiz.minilang.method.callops.SetServiceFields(
0920: curOperElem, simpleMethod));
0921: } else if ("call-service".equals(nodeName)) {
0922: methodOperations
0923: .add(new org.ofbiz.minilang.method.callops.CallService(
0924: curOperElem, simpleMethod));
0925: } else if ("call-service-asynch".equals(nodeName)) {
0926: methodOperations
0927: .add(new org.ofbiz.minilang.method.callops.CallServiceAsynch(
0928: curOperElem, simpleMethod));
0929: } else if ("call-bsh".equals(nodeName)) {
0930: methodOperations
0931: .add(new org.ofbiz.minilang.method.callops.CallBsh(
0932: curOperElem, simpleMethod));
0933: } else if ("call-simple-method".equals(nodeName)) {
0934: methodOperations
0935: .add(new org.ofbiz.minilang.method.callops.CallSimpleMethod(
0936: curOperElem, simpleMethod));
0937:
0938: } else if ("call-object-method".equals(nodeName)) {
0939: methodOperations
0940: .add(new org.ofbiz.minilang.method.callops.CallObjectMethod(
0941: curOperElem, simpleMethod));
0942: } else if ("call-class-method".equals(nodeName)) {
0943: methodOperations
0944: .add(new org.ofbiz.minilang.method.callops.CallClassMethod(
0945: curOperElem, simpleMethod));
0946: } else if ("create-object".equals(nodeName)) {
0947: methodOperations
0948: .add(new org.ofbiz.minilang.method.callops.CreateObject(
0949: curOperElem, simpleMethod));
0950:
0951: } else if ("field-to-request".equals(nodeName)) {
0952: methodOperations
0953: .add(new org.ofbiz.minilang.method.eventops.FieldToRequest(
0954: curOperElem, simpleMethod));
0955: } else if ("field-to-session".equals(nodeName)) {
0956: methodOperations
0957: .add(new org.ofbiz.minilang.method.eventops.FieldToSession(
0958: curOperElem, simpleMethod));
0959: } else if ("request-to-field".equals(nodeName)) {
0960: methodOperations
0961: .add(new org.ofbiz.minilang.method.eventops.RequestToField(
0962: curOperElem, simpleMethod));
0963: } else if ("request-parameters-to-list"
0964: .equals(nodeName)) {
0965: methodOperations
0966: .add(new org.ofbiz.minilang.method.eventops.RequestParametersToList(
0967: curOperElem, simpleMethod));
0968: } else if ("session-to-field".equals(nodeName)) {
0969: methodOperations
0970: .add(new org.ofbiz.minilang.method.eventops.SessionToField(
0971: curOperElem, simpleMethod));
0972: } else if ("webapp-property-to-field".equals(nodeName)) {
0973: methodOperations
0974: .add(new org.ofbiz.minilang.method.eventops.WebappPropertyToField(
0975: curOperElem, simpleMethod));
0976:
0977: } else if ("field-to-result".equals(nodeName)) {
0978: methodOperations
0979: .add(new org.ofbiz.minilang.method.serviceops.FieldToResult(
0980: curOperElem, simpleMethod));
0981:
0982: } else if ("map-to-map".equals(nodeName)) {
0983: methodOperations
0984: .add(new org.ofbiz.minilang.method.envops.MapToMap(
0985: curOperElem, simpleMethod));
0986: } else if ("field-to-list".equals(nodeName)) {
0987: methodOperations
0988: .add(new org.ofbiz.minilang.method.envops.FieldToList(
0989: curOperElem, simpleMethod));
0990: } else if ("list-to-list".equals(nodeName)) {
0991: methodOperations
0992: .add(new org.ofbiz.minilang.method.envops.ListToList(
0993: curOperElem, simpleMethod));
0994: } else if ("order-map-list".equals(nodeName)) {
0995: methodOperations
0996: .add(new org.ofbiz.minilang.method.envops.OrderMapList(
0997: curOperElem, simpleMethod));
0998:
0999: } else if ("set".equals(nodeName)) {
1000: methodOperations
1001: .add(new org.ofbiz.minilang.method.envops.SetOperation(
1002: curOperElem, simpleMethod));
1003: } else if ("env-to-env".equals(nodeName)) {
1004: MethodOperation mop = new org.ofbiz.minilang.method.envops.EnvToEnv(
1005: curOperElem, simpleMethod);
1006: methodOperations.add(mop);
1007: Debug
1008: .logInfo(
1009: "The env-to-env operation has been deprecated in favor of the set operation; found use of this in ["
1010: + simpleMethod
1011: .getShortDescription()
1012: + "]: " + mop.rawString(),
1013: module);
1014: } else if ("env-to-field".equals(nodeName)) {
1015: MethodOperation mop = new org.ofbiz.minilang.method.envops.EnvToField(
1016: curOperElem, simpleMethod);
1017: methodOperations.add(mop);
1018: Debug
1019: .logInfo(
1020: "The env-to-field operation has been deprecated in favor of the set operation; found use of this in ["
1021: + simpleMethod
1022: .getShortDescription()
1023: + "]: " + mop.rawString(),
1024: module);
1025: } else if ("field-to-env".equals(nodeName)) {
1026: MethodOperation mop = new org.ofbiz.minilang.method.envops.FieldToEnv(
1027: curOperElem, simpleMethod);
1028: methodOperations.add(mop);
1029: Debug
1030: .logInfo(
1031: "The field-to-env operation has been deprecated in favor of the set operation; found use of this in ["
1032: + simpleMethod
1033: .getShortDescription()
1034: + "]: " + mop.rawString(),
1035: module);
1036: } else if ("field-to-field".equals(nodeName)) {
1037: MethodOperation mop = new org.ofbiz.minilang.method.envops.FieldToField(
1038: curOperElem, simpleMethod);
1039: methodOperations.add(mop);
1040: Debug
1041: .logInfo(
1042: "The field-to-field operation has been deprecated in favor of the set operation; found use of this in ["
1043: + simpleMethod
1044: .getShortDescription()
1045: + "]: " + mop.rawString(),
1046: module);
1047: } else if ("string-to-field".equals(nodeName)) {
1048: MethodOperation mop = new org.ofbiz.minilang.method.envops.StringToField(
1049: curOperElem, simpleMethod);
1050: methodOperations.add(mop);
1051: Debug
1052: .logInfo(
1053: "The string-to-field operation has been deprecated in favor of the set operation; found use of this in ["
1054: + simpleMethod
1055: .getShortDescription()
1056: + "]: " + mop.rawString(),
1057: module);
1058:
1059: } else if ("string-append".equals(nodeName)) {
1060: methodOperations
1061: .add(new org.ofbiz.minilang.method.envops.StringAppend(
1062: curOperElem, simpleMethod));
1063: } else if ("string-to-list".equals(nodeName)) {
1064: methodOperations
1065: .add(new org.ofbiz.minilang.method.envops.StringToList(
1066: curOperElem, simpleMethod));
1067: } else if ("to-string".equals(nodeName)) {
1068: methodOperations
1069: .add(new org.ofbiz.minilang.method.envops.ToString(
1070: curOperElem, simpleMethod));
1071: } else if ("clear-field".equals(nodeName)) {
1072: methodOperations
1073: .add(new org.ofbiz.minilang.method.envops.ClearField(
1074: curOperElem, simpleMethod));
1075: } else if ("iterate".equals(nodeName)) {
1076: methodOperations
1077: .add(new org.ofbiz.minilang.method.envops.Iterate(
1078: curOperElem, simpleMethod));
1079: } else if ("iterate-map".equals(nodeName)) {
1080: methodOperations
1081: .add(new org.ofbiz.minilang.method.envops.IterateMap(
1082: curOperElem, simpleMethod));
1083: } else if ("loop".equals(nodeName)) {
1084: methodOperations
1085: .add(new org.ofbiz.minilang.method.envops.Loop(
1086: curOperElem, simpleMethod));
1087: } else if ("first-from-list".equals(nodeName)) {
1088: methodOperations
1089: .add(new org.ofbiz.minilang.method.envops.FirstFromList(
1090: curOperElem, simpleMethod));
1091:
1092: } else if ("transaction-begin".equals(nodeName)) {
1093: methodOperations
1094: .add(new org.ofbiz.minilang.method.entityops.TransactionBegin(
1095: curOperElem, simpleMethod));
1096: } else if ("transaction-commit".equals(nodeName)) {
1097: methodOperations
1098: .add(new org.ofbiz.minilang.method.entityops.TransactionCommit(
1099: curOperElem, simpleMethod));
1100: } else if ("transaction-rollback".equals(nodeName)) {
1101: methodOperations
1102: .add(new org.ofbiz.minilang.method.entityops.TransactionRollback(
1103: curOperElem, simpleMethod));
1104:
1105: } else if ("now-timestamp-to-env".equals(nodeName)) {
1106: methodOperations
1107: .add(new org.ofbiz.minilang.method.entityops.NowTimestampToEnv(
1108: curOperElem, simpleMethod));
1109: } else if ("now-date-to-env".equals(nodeName)) {
1110: methodOperations
1111: .add(new org.ofbiz.minilang.method.entityops.NowDateToEnv(
1112: curOperElem, simpleMethod));
1113: } else if ("sequenced-id-to-env".equals(nodeName)) {
1114: methodOperations
1115: .add(new org.ofbiz.minilang.method.entityops.SequencedIdToEnv(
1116: curOperElem, simpleMethod));
1117: } else if ("make-next-seq-id".equals(nodeName)) {
1118: methodOperations
1119: .add(new org.ofbiz.minilang.method.entityops.MakeNextSeqId(
1120: curOperElem, simpleMethod));
1121: } else if ("set-current-user-login".equals(nodeName)) {
1122: methodOperations
1123: .add(new org.ofbiz.minilang.method.entityops.SetCurrentUserLogin(
1124: curOperElem, simpleMethod));
1125:
1126: } else if ("find-by-primary-key".equals(nodeName)) {
1127: methodOperations
1128: .add(new org.ofbiz.minilang.method.entityops.FindByPrimaryKey(
1129: curOperElem, simpleMethod));
1130: } else if ("find-by-and".equals(nodeName)) {
1131: methodOperations
1132: .add(new org.ofbiz.minilang.method.entityops.FindByAnd(
1133: curOperElem, simpleMethod));
1134: } else if ("entity-one".equals(nodeName)) {
1135: methodOperations
1136: .add(new org.ofbiz.minilang.method.entityops.EntityOne(
1137: curOperElem, simpleMethod));
1138: } else if ("entity-and".equals(nodeName)) {
1139: methodOperations
1140: .add(new org.ofbiz.minilang.method.entityops.EntityAnd(
1141: curOperElem, simpleMethod));
1142: } else if ("entity-condition".equals(nodeName)) {
1143: methodOperations
1144: .add(new org.ofbiz.minilang.method.entityops.EntityCondition(
1145: curOperElem, simpleMethod));
1146: } else if ("entity-count".equals(nodeName)) {
1147: methodOperations
1148: .add(new org.ofbiz.minilang.method.entityops.EntityCount(
1149: curOperElem, simpleMethod));
1150: } else if ("get-related-one".equals(nodeName)) {
1151: methodOperations
1152: .add(new org.ofbiz.minilang.method.entityops.GetRelatedOne(
1153: curOperElem, simpleMethod));
1154: } else if ("get-related".equals(nodeName)) {
1155: methodOperations
1156: .add(new org.ofbiz.minilang.method.entityops.GetRelated(
1157: curOperElem, simpleMethod));
1158: } else if ("filter-list-by-and".equals(nodeName)) {
1159: methodOperations
1160: .add(new org.ofbiz.minilang.method.entityops.FilterListByAnd(
1161: curOperElem, simpleMethod));
1162: } else if ("filter-list-by-date".equals(nodeName)) {
1163: methodOperations
1164: .add(new org.ofbiz.minilang.method.entityops.FilterListByDate(
1165: curOperElem, simpleMethod));
1166: } else if ("order-value-list".equals(nodeName)) {
1167: methodOperations
1168: .add(new org.ofbiz.minilang.method.entityops.OrderValueList(
1169: curOperElem, simpleMethod));
1170:
1171: } else if ("make-value".equals(nodeName)) {
1172: methodOperations
1173: .add(new org.ofbiz.minilang.method.entityops.MakeValue(
1174: curOperElem, simpleMethod));
1175: } else if ("clone-value".equals(nodeName)) {
1176: methodOperations
1177: .add(new org.ofbiz.minilang.method.entityops.CloneValue(
1178: curOperElem, simpleMethod));
1179: } else if ("create-value".equals(nodeName)) {
1180: methodOperations
1181: .add(new org.ofbiz.minilang.method.entityops.CreateValue(
1182: curOperElem, simpleMethod));
1183: } else if ("store-value".equals(nodeName)) {
1184: methodOperations
1185: .add(new org.ofbiz.minilang.method.entityops.StoreValue(
1186: curOperElem, simpleMethod));
1187: } else if ("refresh-value".equals(nodeName)) {
1188: methodOperations
1189: .add(new org.ofbiz.minilang.method.entityops.RefreshValue(
1190: curOperElem, simpleMethod));
1191: } else if ("remove-value".equals(nodeName)) {
1192: methodOperations
1193: .add(new org.ofbiz.minilang.method.entityops.RemoveValue(
1194: curOperElem, simpleMethod));
1195: } else if ("remove-related".equals(nodeName)) {
1196: methodOperations
1197: .add(new org.ofbiz.minilang.method.entityops.RemoveRelated(
1198: curOperElem, simpleMethod));
1199: } else if ("remove-by-and".equals(nodeName)) {
1200: methodOperations
1201: .add(new org.ofbiz.minilang.method.entityops.RemoveByAnd(
1202: curOperElem, simpleMethod));
1203: } else if ("clear-cache-line".equals(nodeName)) {
1204: methodOperations
1205: .add(new org.ofbiz.minilang.method.entityops.ClearCacheLine(
1206: curOperElem, simpleMethod));
1207: } else if ("clear-entity-caches".equals(nodeName)) {
1208: methodOperations
1209: .add(new org.ofbiz.minilang.method.entityops.ClearEntityCaches(
1210: curOperElem, simpleMethod));
1211: } else if ("set-pk-fields".equals(nodeName)) {
1212: methodOperations
1213: .add(new org.ofbiz.minilang.method.entityops.SetPkFields(
1214: curOperElem, simpleMethod));
1215: } else if ("set-nonpk-fields".equals(nodeName)) {
1216: methodOperations
1217: .add(new org.ofbiz.minilang.method.entityops.SetNonpkFields(
1218: curOperElem, simpleMethod));
1219:
1220: } else if ("store-list".equals(nodeName)) {
1221: methodOperations
1222: .add(new org.ofbiz.minilang.method.entityops.StoreList(
1223: curOperElem, simpleMethod));
1224: } else if ("remove-list".equals(nodeName)) {
1225: methodOperations
1226: .add(new org.ofbiz.minilang.method.entityops.RemoveList(
1227: curOperElem, simpleMethod));
1228:
1229: } else if ("assert".equals(nodeName)) {
1230: methodOperations
1231: .add(new org.ofbiz.minilang.method.conditional.Assert(
1232: curOperElem, simpleMethod));
1233: } else if ("if".equals(nodeName)) {
1234: methodOperations
1235: .add(new org.ofbiz.minilang.method.conditional.MasterIf(
1236: curOperElem, simpleMethod));
1237: } else if ("while".equals(nodeName)) {
1238: methodOperations
1239: .add(new org.ofbiz.minilang.method.conditional.While(
1240: curOperElem, simpleMethod));
1241: } else if ("if-validate-method".equals(nodeName)) {
1242: methodOperations
1243: .add(new org.ofbiz.minilang.method.ifops.IfValidateMethod(
1244: curOperElem, simpleMethod));
1245: } else if ("if-instance-of".equals(nodeName)) {
1246: methodOperations
1247: .add(new org.ofbiz.minilang.method.ifops.IfInstanceOf(
1248: curOperElem, simpleMethod));
1249: } else if ("if-compare".equals(nodeName)) {
1250: methodOperations
1251: .add(new org.ofbiz.minilang.method.ifops.IfCompare(
1252: curOperElem, simpleMethod));
1253: } else if ("if-compare-field".equals(nodeName)) {
1254: methodOperations
1255: .add(new org.ofbiz.minilang.method.ifops.IfCompareField(
1256: curOperElem, simpleMethod));
1257: } else if ("if-regexp".equals(nodeName)) {
1258: methodOperations
1259: .add(new org.ofbiz.minilang.method.ifops.IfRegexp(
1260: curOperElem, simpleMethod));
1261: } else if ("if-empty".equals(nodeName)) {
1262: methodOperations
1263: .add(new org.ofbiz.minilang.method.ifops.IfEmpty(
1264: curOperElem, simpleMethod));
1265: } else if ("if-not-empty".equals(nodeName)) {
1266: methodOperations
1267: .add(new org.ofbiz.minilang.method.ifops.IfNotEmpty(
1268: curOperElem, simpleMethod));
1269: } else if ("if-has-permission".equals(nodeName)) {
1270: methodOperations
1271: .add(new org.ofbiz.minilang.method.ifops.IfHasPermission(
1272: curOperElem, simpleMethod));
1273: } else if ("check-permission".equals(nodeName)) {
1274: methodOperations
1275: .add(new org.ofbiz.minilang.method.ifops.CheckPermission(
1276: curOperElem, simpleMethod));
1277: } else if ("check-id".equals(nodeName)) {
1278: methodOperations
1279: .add(new org.ofbiz.minilang.method.ifops.CheckId(
1280: curOperElem, simpleMethod));
1281: } else if ("else".equals(nodeName)) {
1282: // don't add anything, but don't complain either, this one is handled in the individual operations
1283: } else if ("property-to-field".equals(nodeName)) {
1284: methodOperations
1285: .add(new org.ofbiz.minilang.method.otherops.PropertyToField(
1286: curOperElem, simpleMethod));
1287: } else if ("calculate".equals(nodeName)) {
1288: methodOperations
1289: .add(new org.ofbiz.minilang.method.otherops.Calculate(
1290: curOperElem, simpleMethod));
1291: } else if ("log".equals(nodeName)) {
1292: methodOperations
1293: .add(new org.ofbiz.minilang.method.otherops.Log(
1294: curOperElem, simpleMethod));
1295: } else {
1296: Debug.logWarning("Operation element \"" + nodeName
1297: + "\" no recognized", module);
1298: }
1299: }
1300: }
1301: }
1302:
1303: /** Execs the given operations returning true if all return true, or returning
1304: * false and stopping if any return false.
1305: */
1306: public static boolean runSubOps(List methodOperations,
1307: MethodContext methodContext) {
1308: Iterator methodOpsIter = methodOperations.iterator();
1309: while (methodOpsIter.hasNext()) {
1310: MethodOperation methodOperation = (MethodOperation) methodOpsIter
1311: .next();
1312: try {
1313: if (!methodOperation.exec(methodContext)) {
1314: return false;
1315: }
1316: } catch (Throwable t) {
1317: String errMsg = "Error in simple-method operation ["
1318: + methodOperation.rawString() + "]: "
1319: + t.toString();
1320: Debug.logError(t, errMsg, module);
1321: throw new RuntimeException(errMsg);
1322: }
1323: }
1324: return true;
1325: }
1326: }
|