|
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallService.java Thu Apr 19 15:09:03 2012 @@ -46,53 +46,37 @@ import org.w3c.dom.Element; * Calls a service using the given parameters */ public class CallService extends MethodOperation { - public static final class CallServiceFactory implements Factory<CallService> { - public CallService createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new CallService(element, simpleMethod); - } - - public String getName() { - return "call-service"; - } - } public static final String module = CallService.class.getName(); public static final String resource = "MiniLangErrorUiLabels"; - protected String serviceName; - protected ContextAccessor<Map<String, Object>> inMapAcsr; - protected String includeUserLoginStr; protected String breakOnErrorStr; + protected FlexibleMessage defaultMessage; protected String errorCode; - protected String successCode; - - /** Require a new transaction for this service */ - protected String requireNewTransactionStr; - /** Override the default transaction timeout, only works if we start the transaction */ - protected int transactionTimeout; - protected FlexibleMessage errorPrefix; protected FlexibleMessage errorSuffix; - protected FlexibleMessage successPrefix; - protected FlexibleMessage successSuffix; + protected String includeUserLoginStr; + protected ContextAccessor<Map<String, Object>> inMapAcsr; protected FlexibleMessage messagePrefix; protected FlexibleMessage messageSuffix; - protected FlexibleMessage defaultMessage; - + /** Require a new transaction for this service */ + protected String requireNewTransactionStr; /** A list of strings with names of new maps to create */ protected List<String> resultsToMap = FastList.newInstance(); - /** A list of ResultToFieldDef objects */ protected List<ResultToFieldDef> resultToField = FastList.newInstance(); - /** the key is the request attribute name, the value is the result name to get */ protected Map<FlexibleServletAccessor<Object>, ContextAccessor<Object>> resultToRequest = FastMap.newInstance(); - - /** the key is the session attribute name, the value is the result name to get */ - protected Map<FlexibleServletAccessor<Object>, ContextAccessor<Object>> resultToSession = FastMap.newInstance(); - /** the key is the result entry name, the value is the result name to get */ protected Map<ContextAccessor<Object>, ContextAccessor<Object>> resultToResult = FastMap.newInstance(); + /** the key is the session attribute name, the value is the result name to get */ + protected Map<FlexibleServletAccessor<Object>, ContextAccessor<Object>> resultToSession = FastMap.newInstance(); + protected String serviceName; + protected String successCode; + protected FlexibleMessage successPrefix; + protected FlexibleMessage successSuffix; + /** Override the default transaction timeout, only works if we start the transaction */ + protected int transactionTimeout; public CallService(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); @@ -101,9 +85,9 @@ public class CallService extends MethodO includeUserLoginStr = element.getAttribute("include-user-login"); breakOnErrorStr = element.getAttribute("break-on-error"); errorCode = element.getAttribute("error-code"); - if (UtilValidate.isEmpty(errorCode)) errorCode = "error"; + if (UtilValidate.isEmpty(errorCode)) + errorCode = "error"; this.requireNewTransactionStr = element.getAttribute("require-new-transaction"); - String timeoutStr = UtilXml.checkEmpty(element.getAttribute("transaction-timeout"), element.getAttribute("transaction-timout")); int timeout = -1; if (!UtilValidate.isEmpty(timeoutStr)) { @@ -115,62 +99,57 @@ public class CallService extends MethodO } } this.transactionTimeout = timeout; - successCode = element.getAttribute("success-code"); - if (UtilValidate.isEmpty(successCode)) successCode = "success"; - + if (UtilValidate.isEmpty(successCode)) + successCode = "success"; errorPrefix = new FlexibleMessage(UtilXml.firstChildElement(element, "error-prefix"), "service.error.prefix"); errorSuffix = new FlexibleMessage(UtilXml.firstChildElement(element, "error-suffix"), "service.error.suffix"); successPrefix = new FlexibleMessage(UtilXml.firstChildElement(element, "success-prefix"), "service.success.prefix"); successSuffix = new FlexibleMessage(UtilXml.firstChildElement(element, "success-suffix"), "service.success.suffix"); messagePrefix = new FlexibleMessage(UtilXml.firstChildElement(element, "message-prefix"), "service.message.prefix"); messageSuffix = new FlexibleMessage(UtilXml.firstChildElement(element, "message-suffix"), "service.message.suffix"); - defaultMessage = new FlexibleMessage(UtilXml.firstChildElement(element, "default-message"), null);//"service.default.message" - + defaultMessage = new FlexibleMessage(UtilXml.firstChildElement(element, "default-message"), null);// "service.default.message" List<? extends Element> resultsToMapElements = UtilXml.childElementList(element, "results-to-map"); if (UtilValidate.isNotEmpty(resultsToMapElements)) { - for (Element resultsToMapElement: resultsToMapElements) { + for (Element resultsToMapElement : resultsToMapElements) { resultsToMap.add(resultsToMapElement.getAttribute("map-name")); } } - List<? extends Element> resultToFieldElements = UtilXml.childElementList(element, "result-to-field"); if (UtilValidate.isNotEmpty(resultToFieldElements)) { - for (Element resultToFieldElement: resultToFieldElements) { + for (Element resultToFieldElement : resultToFieldElements) { ResultToFieldDef rtfDef = new ResultToFieldDef(); rtfDef.resultName = resultToFieldElement.getAttribute("result-name"); rtfDef.mapAcsr = new ContextAccessor<Map<String, Object>>(resultToFieldElement.getAttribute("map-name")); String field = resultToFieldElement.getAttribute("field"); - if (UtilValidate.isEmpty(field)) field = resultToFieldElement.getAttribute("field-name"); + if (UtilValidate.isEmpty(field)) + field = resultToFieldElement.getAttribute("field-name"); rtfDef.fieldAcsr = new ContextAccessor<Object>(field, rtfDef.resultName); resultToField.add(rtfDef); } } - // get result-to-request and result-to-session sub-ops List<? extends Element> resultToRequestElements = UtilXml.childElementList(element, "result-to-request"); if (UtilValidate.isNotEmpty(resultToRequestElements)) { - for (Element resultToRequestElement: resultToRequestElements) { + for (Element resultToRequestElement : resultToRequestElements) { FlexibleServletAccessor<Object> reqAcsr = new FlexibleServletAccessor<Object>(resultToRequestElement.getAttribute("request-name"), resultToRequestElement.getAttribute("result-name")); ContextAccessor<Object> resultAcsr = new ContextAccessor<Object>(resultToRequestElement.getAttribute("result-name")); resultToRequest.put(reqAcsr, resultAcsr); } } - List<? extends Element> resultToSessionElements = UtilXml.childElementList(element, "result-to-session"); if (UtilValidate.isNotEmpty(resultToSessionElements)) { - for (Element resultToSessionElement: resultToSessionElements) { + for (Element resultToSessionElement : resultToSessionElements) { FlexibleServletAccessor<Object> sesAcsr = new FlexibleServletAccessor<Object>(resultToSessionElement.getAttribute("session-name"), resultToSessionElement.getAttribute("result-name")); ContextAccessor<Object> resultAcsr = new ContextAccessor<Object>(resultToSessionElement.getAttribute("result-name")); resultToSession.put(sesAcsr, resultAcsr); } } - List<? extends Element> resultToResultElements = UtilXml.childElementList(element, "result-to-result"); if (UtilValidate.isNotEmpty(resultToResultElements)) { - for (Element resultToResultElement: resultToResultElements) { + for (Element resultToResultElement : resultToResultElements) { ContextAccessor<Object> serResAcsr = new ContextAccessor<Object>(resultToResultElement.getAttribute("service-result-name"), resultToResultElement.getAttribute("result-name")); ContextAccessor<Object> resultAcsr = new ContextAccessor<Object>(resultToResultElement.getAttribute("result-name")); resultToResult.put(serResAcsr, resultAcsr); @@ -178,20 +157,13 @@ public class CallService extends MethodO } } - public String getServiceName() { - return this.serviceName; - } - @Override public boolean exec(MethodContext methodContext) { boolean includeUserLogin = !"false".equals(methodContext.expandString(includeUserLoginStr)); boolean breakOnError = !"false".equals(methodContext.expandString(breakOnErrorStr)); - - String serviceName = methodContext.expandString(this.serviceName); String errorCode = methodContext.expandString(this.errorCode); String successCode = methodContext.expandString(this.successCode); - Map<String, Object> inMap = null; if (inMapAcsr.isEmpty()) { inMap = FastMap.newInstance(); @@ -202,7 +174,6 @@ public class CallService extends MethodO inMapAcsr.put(methodContext, inMap); } } - // before invoking the service, clear messages if (methodContext.getMethodType() == MethodContext.EVENT) { methodContext.removeEnv(simpleMethod.getEventErrorMessageName()); @@ -213,25 +184,20 @@ public class CallService extends MethodO methodContext.removeEnv(simpleMethod.getServiceSuccessMessageName()); methodContext.removeEnv(simpleMethod.getServiceResponseMessageName()); } - // invoke the service Map<String, Object> result = null; - // add UserLogin to context if expected if (includeUserLogin) { GenericValue userLogin = methodContext.getUserLogin(); - if (userLogin != null && inMap.get("userLogin") == null) { inMap.put("userLogin", userLogin); } } - // always add Locale to context unless null Locale locale = methodContext.getLocale(); if (locale != null) { inMap.put("locale", locale); } - try { if (UtilValidate.isEmpty(this.requireNewTransactionStr) && this.transactionTimeout < 0) { result = methodContext.getDispatcher().runSync(serviceName, inMap); @@ -263,15 +229,13 @@ public class CallService extends MethodO return true; } } - if (resultsToMap.size() > 0) { - for (String mapName: resultsToMap) { + for (String mapName : resultsToMap) { methodContext.putEnv(mapName, UtilMisc.makeMapWritable(result)); } } - if (resultToField.size() > 0) { - for (ResultToFieldDef rtfDef: resultToField) { + for (ResultToFieldDef rtfDef : resultToField) { if (!rtfDef.mapAcsr.isEmpty()) { Map<String, Object> tempMap = rtfDef.mapAcsr.get(methodContext); if (tempMap == null) { @@ -284,44 +248,39 @@ public class CallService extends MethodO } } } - // only run this if it is in an EVENT context if (methodContext.getMethodType() == MethodContext.EVENT) { if (resultToRequest.size() > 0) { - for (Map.Entry<FlexibleServletAccessor<Object>, ContextAccessor<Object>> entry: resultToRequest.entrySet()) { + for (Map.Entry<FlexibleServletAccessor<Object>, ContextAccessor<Object>> entry : resultToRequest.entrySet()) { FlexibleServletAccessor<Object> requestAcsr = entry.getKey(); ContextAccessor<Object> resultAcsr = entry.getValue(); requestAcsr.put(methodContext.getRequest(), resultAcsr.get(result, methodContext), methodContext.getEnvMap()); } } - if (resultToSession.size() > 0) { - for (Map.Entry<FlexibleServletAccessor<Object>, ContextAccessor<Object>> entry: resultToSession.entrySet()) { + for (Map.Entry<FlexibleServletAccessor<Object>, ContextAccessor<Object>> entry : resultToSession.entrySet()) { FlexibleServletAccessor<Object> sessionAcsr = entry.getKey(); ContextAccessor<Object> resultAcsr = entry.getValue(); sessionAcsr.put(methodContext.getRequest().getSession(), resultAcsr.get(result, methodContext), methodContext.getEnvMap()); } } } - // only run this if it is in an SERVICE context if (methodContext.getMethodType() == MethodContext.SERVICE) { if (resultToResult.size() > 0) { - for (Map.Entry<ContextAccessor<Object>, ContextAccessor<Object>> entry: resultToResult.entrySet()) { + for (Map.Entry<ContextAccessor<Object>, ContextAccessor<Object>> entry : resultToResult.entrySet()) { ContextAccessor<Object> targetResultAcsr = entry.getKey(); ContextAccessor<Object> resultAcsr = entry.getValue(); targetResultAcsr.put(methodContext.getResults(), resultAcsr.get(result, methodContext), methodContext); } } } - String errorPrefixStr = errorPrefix.getMessage(methodContext.getLoader(), methodContext); String errorSuffixStr = errorSuffix.getMessage(methodContext.getLoader(), methodContext); String successPrefixStr = successPrefix.getMessage(methodContext.getLoader(), methodContext); String successSuffixStr = successSuffix.getMessage(methodContext.getLoader(), methodContext); String messagePrefixStr = messagePrefix.getMessage(methodContext.getLoader(), methodContext); String messageSuffixStr = messageSuffix.getMessage(methodContext.getLoader(), methodContext); - String errorMessage = null; List<String> errorMessageList = null; // See if there is a single message @@ -330,28 +289,27 @@ public class CallService extends MethodO } else if (result.containsKey(ModelService.ERROR_MESSAGE_LIST)) { errorMessageList = UtilGenerics.checkList(result.get(ModelService.ERROR_MESSAGE_LIST)); } - if ((UtilValidate.isNotEmpty(errorMessage) || UtilValidate.isNotEmpty(errorMessageList)) && breakOnError) { if (methodContext.getMethodType() == MethodContext.EVENT) { - if (UtilValidate.isNotEmpty(errorMessage)){ - if (Debug.verboseOn()){ + if (UtilValidate.isNotEmpty(errorMessage)) { + if (Debug.verboseOn()) { errorMessage += UtilProperties.getMessage(resource, "simpleMethod.error_show_service_name", UtilMisc.toMap("serviceName", serviceName, "methodName", simpleMethod.getMethodName()), locale); } methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errorMessage); } else { - if (Debug.verboseOn()){ + if (Debug.verboseOn()) { errorMessageList.add(UtilProperties.getMessage(resource, "simpleMethod.error_show_service_name", UtilMisc.toMap("serviceName", serviceName, "methodName", simpleMethod.getMethodName()), locale)); } methodContext.putEnv(simpleMethod.getEventErrorMessageListName(), errorMessageList); } } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - ServiceUtil.addErrors(UtilMisc.<String, String>getListFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageListName()), - UtilMisc.<String, String, Object>getMapFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageMapName()), result); - // the old way, makes a mess of messages passed up the stack: methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errorMessage); + ServiceUtil.addErrors(UtilMisc.<String, String> getListFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageListName()), UtilMisc.<String, String, Object> getMapFromMap(methodContext.getEnvMap(), this.simpleMethod.getServiceErrorMessageMapName()), result); + // the old way, makes a mess of messages passed up the stack: + // methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), + // errorMessage); Debug.logError(new Exception(errorMessage), module); } } - String successMessage = ServiceUtil.makeSuccessMessage(result, messagePrefixStr, messageSuffixStr, successPrefixStr, successSuffixStr); if (UtilValidate.isNotEmpty(successMessage)) { if (methodContext.getMethodType() == MethodContext.EVENT) { @@ -360,7 +318,6 @@ public class CallService extends MethodO methodContext.putEnv(simpleMethod.getServiceSuccessMessageName(), successMessage); } } - String defaultMessageStr = defaultMessage.getMessage(methodContext.getLoader(), methodContext); if (UtilValidate.isEmpty(errorMessage) && UtilValidate.isEmpty(errorMessageList) && UtilValidate.isEmpty(successMessage) && UtilValidate.isNotEmpty(defaultMessageStr)) { if (methodContext.getMethodType() == MethodContext.EVENT) { @@ -369,10 +326,8 @@ public class CallService extends MethodO methodContext.putEnv(simpleMethod.getServiceSuccessMessageName(), defaultMessageStr); } } - // handle the result String responseCode = result.containsKey(ModelService.RESPONSE_MESSAGE) ? (String) result.get(ModelService.RESPONSE_MESSAGE) : successCode; - if (errorCode.equals(responseCode)) { if (breakOnError) { if (methodContext.getMethodType() == MethodContext.EVENT) { @@ -396,19 +351,34 @@ public class CallService extends MethodO } @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + + public String getServiceName() { + return this.serviceName; + } + + @Override public String rawString() { // TODO: something more than the empty tag return "<call-service/>"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class CallServiceFactory implements Factory<CallService> { + public CallService createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new CallService(element, simpleMethod); + } + + public String getName() { + return "call-service"; + } } public static class ResultToFieldDef { - public String resultName; - public ContextAccessor<Map<String, Object>> mapAcsr; public ContextAccessor<Object> fieldAcsr; + public ContextAccessor<Map<String, Object>> mapAcsr; + public String resultName; } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallServiceAsynch.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallServiceAsynch.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallServiceAsynch.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallServiceAsynch.java Thu Apr 19 15:09:03 2012 @@ -36,21 +36,12 @@ import org.w3c.dom.Element; * Calls a service using the given parameters */ public class CallServiceAsynch extends MethodOperation { - public static final class CallServiceAsynchFactory implements Factory<CallServiceAsynch> { - public CallServiceAsynch createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new CallServiceAsynch(element, simpleMethod); - } - - public String getName() { - return "call-service-asynch"; - } - } public static final String module = CallServiceAsynch.class.getName(); - protected String serviceName; - protected ContextAccessor<Map<String, Object>> inMapAcsr; protected String includeUserLoginStr; + protected ContextAccessor<Map<String, Object>> inMapAcsr; + protected String serviceName; public CallServiceAsynch(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); @@ -63,7 +54,6 @@ public class CallServiceAsynch extends M public boolean exec(MethodContext methodContext) { String serviceName = methodContext.expandString(this.serviceName); boolean includeUserLogin = !"false".equals(methodContext.expandString(includeUserLoginStr)); - Map<String, Object> inMap = null; if (inMapAcsr.isEmpty()) { inMap = FastMap.newInstance(); @@ -74,7 +64,6 @@ public class CallServiceAsynch extends M inMapAcsr.put(methodContext, inMap); } } - // add UserLogin to context if expected if (includeUserLogin) { GenericValue userLogin = methodContext.getUserLogin(); @@ -83,20 +72,17 @@ public class CallServiceAsynch extends M inMap.put("userLogin", userLogin); } } - // always add Locale to context unless null Locale locale = methodContext.getLocale(); if (locale != null) { inMap.put("locale", locale); } - // invoke the service try { methodContext.getDispatcher().runAsync(serviceName, inMap); } catch (GenericServiceException e) { Debug.logError(e, module); String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem invoking the " + serviceName + " service: " + e.getMessage() + "]"; - if (methodContext.getMethodType() == MethodContext.EVENT) { methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); @@ -106,10 +92,15 @@ public class CallServiceAsynch extends M } return false; } - return true; } + @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + public String getServiceName() { return this.serviceName; } @@ -119,9 +110,14 @@ public class CallServiceAsynch extends M // TODO: something more than the empty tag return "<call-service-asynch/>"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class CallServiceAsynchFactory implements Factory<CallServiceAsynch> { + public CallServiceAsynch createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new CallServiceAsynch(element, simpleMethod); + } + + public String getName() { + return "call-service-asynch"; + } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMapProcessor.java Thu Apr 19 15:09:03 2012 @@ -18,38 +18,33 @@ *******************************************************************************/ package org.ofbiz.minilang.method.callops; -import java.util.*; +import java.util.List; +import java.util.Map; import javolution.util.FastList; import javolution.util.FastMap; -import org.w3c.dom.*; -import org.ofbiz.base.util.*; -import org.ofbiz.minilang.*; -import org.ofbiz.minilang.method.*; -import org.ofbiz.minilang.operation.*; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.method.MethodContext; +import org.ofbiz.minilang.method.MethodOperation; +import org.ofbiz.minilang.operation.MapProcessor; +import org.w3c.dom.Element; /** * An event operation that calls a simple map processor inlined or from a separate file */ public class CallSimpleMapProcessor extends MethodOperation { - public static final class CallSimpleMapProcessorFactory implements Factory<CallSimpleMapProcessor> { - public CallSimpleMapProcessor createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new CallSimpleMapProcessor(element, simpleMethod); - } - public String getName() { - return "call-map-processor"; - } - } - - String xmlResource; - String processorName; - ContextAccessor<Map<String, Object>> inMapAcsr; - ContextAccessor<Map<String, Object>> outMapAcsr; ContextAccessor<List<Object>> errorListAcsr; - MapProcessor inlineMapProcessor = null; + ContextAccessor<Map<String, Object>> inMapAcsr; + ContextAccessor<Map<String, Object>> outMapAcsr; + String processorName; + String xmlResource; public CallSimpleMapProcessor(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); @@ -58,7 +53,6 @@ public class CallSimpleMapProcessor exte inMapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("in-map-name")); outMapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("out-map-name")); errorListAcsr = new ContextAccessor<List<Object>>(element.getAttribute("error-list-name"), "error_list"); - Element simpleMapProcessorElement = UtilXml.firstChildElement(element, "simple-map-processor"); if (simpleMapProcessorElement != null) { inlineMapProcessor = new MapProcessor(simpleMapProcessorElement); @@ -72,48 +66,52 @@ public class CallSimpleMapProcessor exte messages = FastList.newInstance(); errorListAcsr.put(methodContext, messages); } - Map<String, Object> inMap = inMapAcsr.get(methodContext); if (inMap == null) { inMap = FastMap.newInstance(); inMapAcsr.put(methodContext, inMap); } - Map<String, Object> outMap = outMapAcsr.get(methodContext); if (outMap == null) { outMap = FastMap.newInstance(); outMapAcsr.put(methodContext, outMap); } - // run external map processor first if (UtilValidate.isNotEmpty(this.xmlResource) && UtilValidate.isNotEmpty(this.processorName)) { String xmlResource = methodContext.expandString(this.xmlResource); String processorName = methodContext.expandString(this.processorName); try { - org.ofbiz.minilang.SimpleMapProcessor.runSimpleMapProcessor( - xmlResource, processorName, inMap, outMap, messages, - methodContext.getLocale(), methodContext.getLoader()); + org.ofbiz.minilang.SimpleMapProcessor.runSimpleMapProcessor(xmlResource, processorName, inMap, outMap, messages, methodContext.getLocale(), methodContext.getLoader()); } catch (MiniLangException e) { messages.add("Error running SimpleMapProcessor in XML file \"" + xmlResource + "\": " + e.toString()); } } - // run inlined map processor last so it can override the external map processor if (inlineMapProcessor != null) { inlineMapProcessor.exec(inMap, outMap, messages, methodContext.getLocale(), methodContext.getLoader()); } - return true; } @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + + @Override public String rawString() { // TODO: something more than the empty tag return "<call-simple-map-processor/>"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class CallSimpleMapProcessorFactory implements Factory<CallSimpleMapProcessor> { + public CallSimpleMapProcessor createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new CallSimpleMapProcessor(element, simpleMethod); + } + + public String getName() { + return "call-map-processor"; + } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMethod.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMethod.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMethod.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CallSimpleMethod.java Thu Apr 19 15:09:03 2012 @@ -32,20 +32,11 @@ import org.w3c.dom.Element; * An operation that calls a simple method in the same, or from another, file */ public class CallSimpleMethod extends MethodOperation { - public static final class CallSimpleMethodFactory implements Factory<CallSimpleMethod> { - public CallSimpleMethod createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new CallSimpleMethod(element, simpleMethod); - } - - public String getName() { - return "call-simple-method"; - } - } public static final String module = CallSimpleMethod.class.getName(); - String xmlResource; String methodName; + String xmlResource; public CallSimpleMethod(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); @@ -53,20 +44,11 @@ public class CallSimpleMethod extends Me this.xmlResource = element.getAttribute("xml-resource"); } - public String getXmlResource() { - return this.xmlResource; - } - - public String getMethodName() { - return this.methodName; - } - @Override public boolean exec(MethodContext methodContext) { if (UtilValidate.isNotEmpty(this.methodName)) { String methodName = methodContext.expandString(this.methodName); String xmlResource = methodContext.expandString(this.xmlResource); - SimpleMethod simpleMethodToCall = null; try { simpleMethodToCall = getSimpleMethodToCall(methodContext.getLoader()); @@ -76,18 +58,17 @@ public class CallSimpleMethod extends Me methodContext.setErrorReturn(errMsg, simpleMethod); return false; } - if (simpleMethodToCall == null) { String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process, could not find SimpleMethod " + methodName + " in XML document in resource: " + xmlResource; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } - String returnVal = simpleMethodToCall.exec(methodContext); - if (Debug.verboseOn()) Debug.logVerbose("Called inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], returnVal is [" + returnVal + "]", module); - + if (Debug.verboseOn()) + Debug.logVerbose("Called inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], returnVal is [" + returnVal + "]", module); if (returnVal != null && returnVal.equals(simpleMethodToCall.getDefaultErrorCode())) { - // in this case just set the error code just in case it hasn't already been set, the error messages will already be in place... + // in this case just set the error code just in case it hasn't already + // been set, the error messages will already be in place... if (methodContext.getMethodType() == MethodContext.EVENT) { methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); } else if (methodContext.getMethodType() == MethodContext.SERVICE) { @@ -95,18 +76,19 @@ public class CallSimpleMethod extends Me } return false; } - - // if the response code/message is error, if so show the error and return false + // if the response code/message is error, if so show the error and return + // false if (methodContext.getMethodType() == MethodContext.EVENT) { String responseCode = (String) methodContext.getEnv(simpleMethod.getEventResponseCodeName()); if (responseCode != null && responseCode.equals(simpleMethod.getDefaultErrorCode())) { - Debug.logWarning("Got error [" + responseCode + "] calling inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], message is " + methodContext.getEnv(simpleMethod.getEventErrorMessageName()) , module); + Debug.logWarning("Got error [" + responseCode + "] calling inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], message is " + methodContext.getEnv(simpleMethod.getEventErrorMessageName()), module); return false; } } else if (methodContext.getMethodType() == MethodContext.SERVICE) { String resonseMessage = (String) methodContext.getEnv(simpleMethod.getServiceResponseMessageName()); if (resonseMessage != null && resonseMessage.equals(simpleMethod.getDefaultErrorCode())) { - Debug.logWarning("Got error [" + resonseMessage + "] calling inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], message is " + methodContext.getEnv(simpleMethod.getServiceErrorMessageName()) + ", and the error message list is: " + methodContext.getEnv(simpleMethod.getServiceErrorMessageListName()), module); + Debug.logWarning("Got error [" + resonseMessage + "] calling inline simple-method named [" + methodName + "] in resource [" + xmlResource + "], message is " + methodContext.getEnv(simpleMethod.getServiceErrorMessageName()) + ", and the error message list is: " + + methodContext.getEnv(simpleMethod.getServiceErrorMessageListName()), module); return false; } } @@ -116,10 +98,19 @@ public class CallSimpleMethod extends Me methodContext.setErrorReturn(errMsg, simpleMethod); return false; } - return true; } + @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + + public String getMethodName() { + return this.methodName; + } + public SimpleMethod getSimpleMethodToCall(ClassLoader loader) throws MiniLangException { SimpleMethod simpleMethodToCall = null; if (UtilValidate.isEmpty(xmlResource)) { @@ -131,13 +122,22 @@ public class CallSimpleMethod extends Me return simpleMethodToCall; } + public String getXmlResource() { + return this.xmlResource; + } + @Override public String rawString() { return "<call-simple-method xml-resource=\"" + this.xmlResource + "\" method-name=\"" + this.methodName + "\" />"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class CallSimpleMethodFactory implements Factory<CallSimpleMethod> { + public CallSimpleMethod createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new CallSimpleMethod(element, simpleMethod); + } + + public String getName() { + return "call-simple-method"; + } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CheckErrors.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CheckErrors.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CheckErrors.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CheckErrors.java Thu Apr 19 15:09:03 2012 @@ -32,19 +32,9 @@ import org.w3c.dom.Element; * An event operation that checks a message list and may introduce a return code and stop the event */ public class CheckErrors extends MethodOperation { - public static final class CheckErrorsFactory implements Factory<CheckErrors> { - public CheckErrors createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new CheckErrors(element, simpleMethod); - } - - public String getName() { - return "check-errors"; - } - } - ContextAccessor<List<Object>> errorListAcsr; String errorCode; - + ContextAccessor<List<Object>> errorListAcsr; FlexibleMessage errorPrefix; FlexibleMessage errorSuffix; FlexibleMessage messagePrefix; @@ -53,10 +43,9 @@ public class CheckErrors extends MethodO public CheckErrors(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); errorCode = element.getAttribute("error-code"); - if (UtilValidate.isEmpty(errorCode)) errorCode = "error"; - + if (UtilValidate.isEmpty(errorCode)) + errorCode = "error"; errorListAcsr = new ContextAccessor<List<Object>>(element.getAttribute("error-list-name"), "error_list"); - errorPrefix = new FlexibleMessage(UtilXml.firstChildElement(element, "error-prefix"), "check.error.prefix"); errorSuffix = new FlexibleMessage(UtilXml.firstChildElement(element, "error-suffix"), "check.error.suffix"); messagePrefix = new FlexibleMessage(UtilXml.firstChildElement(element, "message-prefix"), "check.message.prefix"); @@ -66,17 +55,13 @@ public class CheckErrors extends MethodO @Override public boolean exec(MethodContext methodContext) { List<Object> messages = errorListAcsr.get(methodContext); - if (UtilValidate.isNotEmpty(messages)) { String errorCode = methodContext.expandString(this.errorCode); - if (methodContext.getMethodType() == MethodContext.EVENT) { - /* The OLD way, now puts formatting control in the template... - String errMsg = errorPrefix.getMessage(methodContext.getLoader(), methodContext) + - ServiceUtil.makeMessageList(messages, messagePrefix.getMessage(methodContext.getLoader(), methodContext), - messageSuffix.getMessage(methodContext.getLoader(), methodContext)) + - errorSuffix.getMessage(methodContext.getLoader(), methodContext); - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); + /* + * The OLD way, now puts formatting control in the template... String errMsg = errorPrefix.getMessage(methodContext.getLoader(), methodContext) + ServiceUtil.makeMessageList(messages, + * messagePrefix.getMessage(methodContext.getLoader(), methodContext), messageSuffix.getMessage(methodContext.getLoader(), methodContext)) + + * errorSuffix.getMessage(methodContext.getLoader(), methodContext); methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); */ methodContext.putEnv(simpleMethod.getEventErrorMessageListName(), messages); methodContext.putEnv(simpleMethod.getEventResponseCodeName(), errorCode); @@ -89,18 +74,28 @@ public class CheckErrors extends MethodO return false; } } - return true; } @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + + @Override public String rawString() { // TODO: something more than the empty tag return "<check-errors/>"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class CheckErrorsFactory implements Factory<CheckErrors> { + public CheckErrors createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new CheckErrors(element, simpleMethod); + } + + public String getName() { + return "check-errors"; + } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CreateObject.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CreateObject.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CreateObject.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/CreateObject.java Thu Apr 19 15:09:03 2012 @@ -18,60 +18,57 @@ *******************************************************************************/ package org.ofbiz.minilang.method.callops; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Map; import javolution.util.FastList; import javolution.util.FastMap; -import org.w3c.dom.*; -import org.ofbiz.base.util.*; - -import org.ofbiz.minilang.*; -import org.ofbiz.minilang.method.*; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.ObjectType; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.method.FieldObject; +import org.ofbiz.minilang.method.MethodContext; +import org.ofbiz.minilang.method.MethodObject; +import org.ofbiz.minilang.method.MethodOperation; +import org.ofbiz.minilang.method.StringObject; +import org.w3c.dom.Element; /** * Creates a Java object using the given fields as parameters */ public class CreateObject extends MethodOperation { - public static final class CreateObjectFactory implements Factory<CreateObject> { - public CreateObject createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new CreateObject(element, simpleMethod); - } - - public String getName() { - return "create-object"; - } - } public static final String module = CreateObject.class.getName(); String className; ContextAccessor<Object> fieldAcsr; ContextAccessor<Map<String, Object>> mapAcsr; - /** A list of MethodObject objects to use as the method call parameters */ List<MethodObject<?>> parameters; public CreateObject(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); className = element.getAttribute("class-name"); - - // the schema for this element now just has the "field" attribute, though the old "field-name" and "map-name" pair is still supported + // the schema for this element now just has the "field" attribute, though the old + // "field-name" and "map-name" pair is still supported fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name")); mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name")); - List<? extends Element> parameterElements = UtilXml.childElementList(element); if (parameterElements.size() > 0) { parameters = FastList.newInstance(); - for (Element parameterElement: parameterElements) { + for (Element parameterElement : parameterElements) { MethodObject<?> methodObject = null; if ("string".equals(parameterElement.getNodeName())) { methodObject = new StringObject(parameterElement, simpleMethod); } else if ("field".equals(parameterElement.getNodeName())) { methodObject = new FieldObject<Object>(parameterElement, simpleMethod); } else { - //whoops, invalid tag here, print warning + // whoops, invalid tag here, print warning Debug.logWarning("Found an unsupported tag under the call-object-method tag: " + parameterElement.getNodeName() + "; ignoring", module); } if (methodObject != null) { @@ -84,28 +81,23 @@ public class CreateObject extends Method @Override public boolean exec(MethodContext methodContext) { String className = methodContext.expandString(this.className); - Class<?> methodClass = null; try { methodClass = ObjectType.loadClass(className, methodContext.getLoader()); } catch (ClassNotFoundException e) { Debug.logError(e, "Class to create not found with name " + className + " in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Class to create not found with name " + className + ": " + e.toString() + "]"; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } - Object[] args = null; Class<?>[] parameterTypes = null; if (parameters != null) { args = new Object[parameters.size()]; parameterTypes = new Class<?>[parameters.size()]; - int i = 0; - for (MethodObject<?> methodObjectDef: parameters) { + for (MethodObject<?> methodObjectDef : parameters) { args[i] = methodObjectDef.getObject(methodContext); - Class<?> typeClass = methodObjectDef.getTypeClass(methodContext.getLoader()); if (typeClass == null) { String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Parameter type not found with name " + methodObjectDef.getTypeName() + "]"; @@ -113,22 +105,18 @@ public class CreateObject extends Method methodContext.setErrorReturn(errMsg, simpleMethod); return false; } - parameterTypes[i] = typeClass; i++; } } - try { Constructor<?> constructor = methodClass.getConstructor(parameterTypes); try { Object newObject = constructor.newInstance(args); - - //if fieldAcsr is empty, ignore return value + // if fieldAcsr is empty, ignore return value if (!fieldAcsr.isEmpty()) { if (!mapAcsr.isEmpty()) { Map<String, Object> retMap = mapAcsr.get(methodContext); - if (retMap == null) { retMap = FastMap.newInstance(); mapAcsr.put(methodContext, retMap); @@ -141,54 +129,58 @@ public class CreateObject extends Method } } catch (InstantiationException e) { Debug.logError(e, "Could not instantiate object in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Could not instantiate object: " + e.toString() + "]"; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } catch (IllegalAccessException e) { Debug.logError(e, "Illegal access constructing object in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Illegal access constructing object: " + e.toString() + "]"; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } catch (IllegalArgumentException e) { Debug.logError(e, "Illegal argument calling method in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Illegal argument calling constructor: " + e.toString() + "]"; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } catch (InvocationTargetException e) { Debug.logError(e.getTargetException(), "Constructor in create-object operation threw an exception", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Constructor in create-object threw an exception: " + e.getTargetException() + "]"; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } } catch (NoSuchMethodException e) { Debug.logError(e, "Could not find constructor to execute in simple-method create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Could not find constructor to execute: " + e.toString() + "]"; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } catch (SecurityException e) { Debug.logError(e, "Security exception finding constructor to execute in simple-method create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Security exception finding constructor to execute: " + e.toString() + "]"; methodContext.setErrorReturn(errMsg, simpleMethod); return false; } - return true; } @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + + @Override public String rawString() { // TODO: something more than the empty tag return "<create-object/>"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class CreateObjectFactory implements Factory<CreateObject> { + public CreateObject createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new CreateObject(element, simpleMethod); + } + + public String getName() { + return "create-object"; + } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/FlexibleMessage.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/FlexibleMessage.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/FlexibleMessage.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/FlexibleMessage.java Thu Apr 19 15:09:03 2012 @@ -20,10 +20,12 @@ package org.ofbiz.minilang.method.callop import java.io.Serializable; -import org.w3c.dom.*; -import org.ofbiz.base.util.*; - -import org.ofbiz.minilang.method.*; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.minilang.method.MethodContext; +import org.w3c.dom.Element; /** * Simple class to wrap messages that come either from a straight string or a properties file @@ -33,21 +35,19 @@ public class FlexibleMessage implements public static final String module = FlexibleMessage.class.getName(); + boolean isProperty = false; String message = null; String propertyResource = null; - boolean isProperty = false; public FlexibleMessage(Element element, String defaultProperty) { String resAttr = null; String propAttr = null; String elVal = null; - if (element != null) { resAttr = element.getAttribute("resource"); propAttr = element.getAttribute("property"); elVal = UtilXml.elementValue(element); } - if (UtilValidate.isNotEmpty(resAttr)) { propertyResource = resAttr; message = propAttr; @@ -66,17 +66,10 @@ public class FlexibleMessage implements public String getMessage(ClassLoader loader, MethodContext methodContext) { String message = methodContext.expandString(this.message); String propertyResource = methodContext.expandString(this.propertyResource); - - // if (Debug.infoOn()) Debug.logInfo("[FlexibleMessage.getMessage] isProperty: " + isProperty + ", message: " + message + ", propertyResource: " + propertyResource, module); if (!isProperty && message != null) { - // if (Debug.infoOn()) Debug.logInfo("[FlexibleMessage.getMessage] Adding message: " + message, module); return message; } else if (isProperty && propertyResource != null && message != null) { - // URL propertyURL = UtilURL.fromResource(propertyResource, loader); - //String propMsg = UtilProperties.getPropertyValue(propertyResource, message); String propMsg = UtilProperties.getMessage(propertyResource, message, methodContext.getEnvMap(), methodContext.getLocale()); - - // if (Debug.infoOn()) Debug.logInfo("[FlexibleMessage.getMessage] Got property message: " + propMsg, module); if (propMsg == null) { return "In Simple Map Processing property message could not be found in resource [" + propertyResource + "] with name [" + message + "]. "; } else { Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/Return.java Thu Apr 19 15:09:03 2012 @@ -18,25 +18,16 @@ *******************************************************************************/ package org.ofbiz.minilang.method.callops; -import org.w3c.dom.*; - import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.minilang.*; -import org.ofbiz.minilang.method.*; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.MethodContext; +import org.ofbiz.minilang.method.MethodOperation; +import org.w3c.dom.Element; /** * An event operation that returns the given response code */ public class Return extends MethodOperation { - public static final class ReturnFactory implements Factory<Return> { - public Return createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new Return(element, simpleMethod); - } - - public String getName() { - return "return"; - } - } String responseCode; @@ -50,7 +41,6 @@ public class Return extends MethodOperat @Override public boolean exec(MethodContext methodContext) { String responseCode = methodContext.expandString(this.responseCode); - if (methodContext.getMethodType() == MethodContext.EVENT) { methodContext.putEnv(simpleMethod.getEventResponseCodeName(), responseCode); return false; @@ -63,13 +53,24 @@ public class Return extends MethodOperat } @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + + @Override public String rawString() { // TODO: something more than the empty tag return "<return/>"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class ReturnFactory implements Factory<Return> { + public Return createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new Return(element, simpleMethod); + } + + public String getName() { + return "return"; + } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/SetServiceFields.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/SetServiceFields.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/SetServiceFields.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/callops/SetServiceFields.java Thu Apr 19 15:09:03 2012 @@ -38,22 +38,13 @@ import org.w3c.dom.Element; * Sets all Service parameters/attributes in the to-map using the map as a source */ public class SetServiceFields extends MethodOperation { - public static final class SetServiceFieldsFactory implements Factory<SetServiceFields> { - public SetServiceFields createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new SetServiceFields(element, simpleMethod); - } - - public String getName() { - return "set-service-fields"; - } - } public static final String module = SetServiceFields.class.getName(); - String serviceName; + ContextAccessor<List<Object>> errorListAcsr; ContextAccessor<Map<String, ? extends Object>> mapAcsr; + String serviceName; ContextAccessor<Map<String, Object>> toMapAcsr; - ContextAccessor<List<Object>> errorListAcsr; public SetServiceFields(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); @@ -70,21 +61,17 @@ public class SetServiceFields extends Me messages = FastList.newInstance(); errorListAcsr.put(methodContext, messages); } - String serviceName = methodContext.expandString(this.serviceName); - Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext); if (fromMap == null) { Debug.logWarning("The from map in set-service-field was not found with name: " + mapAcsr, module); return true; } - Map<String, Object> toMap = toMapAcsr.get(methodContext); if (toMap == null) { toMap = FastMap.newInstance(); toMapAcsr.put(methodContext, toMap); } - LocalDispatcher dispatcher = methodContext.getDispatcher(); ModelService modelService = null; try { @@ -96,10 +83,15 @@ public class SetServiceFields extends Me return false; } toMap.putAll(modelService.makeValid(fromMap, "IN", true, messages, methodContext.getTimeZone(), methodContext.getLocale())); - return true; } + @Override + public String expandedString(MethodContext methodContext) { + // TODO: something more than a stub/dummy + return this.rawString(); + } + public String getServiceName() { return this.serviceName; } @@ -109,9 +101,14 @@ public class SetServiceFields extends Me // TODO: something more than the empty tag return "<set-service-fields/>"; } - @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + + public static final class SetServiceFieldsFactory implements Factory<SetServiceFields> { + public SetServiceFields createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new SetServiceFields(element, simpleMethod); + } + + public String getName() { + return "set-service-fields"; + } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Assert.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Assert.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Assert.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/Assert.java Thu Apr 19 15:09:03 2012 @@ -35,31 +35,19 @@ import org.w3c.dom.Element; * Operation used to check each sub-condition independently and for each one that fails (does not evaluate to true), adds an error to the error message list. */ public class Assert extends MethodOperation { - public static final class AssertFactory implements Factory<Assert> { - public Assert createMethodOperation(Element element, SimpleMethod simpleMethod) { - return new Assert(element, simpleMethod); - } - - public String getName() { - return "assert"; - } - } public static final String module = Assert.class.getName(); - protected ContextAccessor<List<Object>> errorListAcsr; - protected FlexibleStringExpander titleExdr; - /** List of Conditional objects */ protected List<Conditional> conditionalList = FastList.newInstance(); + protected ContextAccessor<List<Object>> errorListAcsr; + protected FlexibleStringExpander titleExdr; public Assert(Element element, SimpleMethod simpleMethod) { super(element, simpleMethod); - errorListAcsr = new ContextAccessor<List<Object>>(element.getAttribute("error-list-name"), "error_list"); titleExdr = FlexibleStringExpander.getInstance(element.getAttribute("title")); - - for (Element conditionalElement: UtilXml.childElementList(element)) { + for (Element conditionalElement : UtilXml.childElementList(element)) { this.conditionalList.add(ConditionalFactory.makeConditional(conditionalElement, simpleMethod)); } } @@ -71,13 +59,10 @@ public class Assert extends MethodOperat messages = FastList.newInstance(); errorListAcsr.put(methodContext, messages); } - String title = this.titleExdr.expandString(methodContext.getEnvMap()); - - // check each conditional and if fails generate a message to add to the error list - for (Conditional condition: conditionalList) { + // check each conditional and if fails generate a message to add to the error list + for (Conditional condition : conditionalList) { boolean conditionTrue = condition.checkCondition(methodContext); - if (!conditionTrue) { // pretty print condition StringBuilder messageBuffer = new StringBuilder(); @@ -92,19 +77,12 @@ public class Assert extends MethodOperat messages.add(messageBuffer.toString()); } } - return true; } @Override - public String rawString() { - return expandedString(null); - } - - @Override public String expandedString(MethodContext methodContext) { String title = this.titleExdr.expandString(methodContext.getEnvMap()); - StringBuilder messageBuf = new StringBuilder(); messageBuf.append("<assert"); if (UtilValidate.isNotEmpty(title)) { @@ -113,10 +91,25 @@ public class Assert extends MethodOperat messageBuf.append("\""); } messageBuf.append(">"); - for (Conditional condition: conditionalList) { + for (Conditional condition : conditionalList) { condition.prettyPrint(messageBuf, methodContext); } messageBuf.append("</assert>"); return messageBuf.toString(); } + + @Override + public String rawString() { + return expandedString(null); + } + + public static final class AssertFactory implements Factory<Assert> { + public Assert createMethodOperation(Element element, SimpleMethod simpleMethod) { + return new Assert(element, simpleMethod); + } + + public String getName() { + return "assert"; + } + } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CombinedCondition.java Thu Apr 19 15:09:03 2012 @@ -18,85 +18,41 @@ *******************************************************************************/ package org.ofbiz.minilang.method.conditional; -import java.util.*; +import java.util.Iterator; +import java.util.List; + import javolution.util.FastList; -import org.w3c.dom.*; -import org.ofbiz.base.util.*; -import org.ofbiz.minilang.*; -import org.ofbiz.minilang.method.*; + +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.MethodContext; +import org.w3c.dom.Element; /** * Implements generic combining conditions such as or, and, etc. */ public class CombinedCondition implements Conditional { - public static final class OrConditionFactory extends ConditionalFactory<CombinedCondition> { - @Override - public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { - return new CombinedCondition(element, OR, simpleMethod); - } - - @Override - public String getName() { - return "or"; - } - } - - public static final class XorConditionFactory extends ConditionalFactory<CombinedCondition> { - @Override - public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { - return new CombinedCondition(element, XOR, simpleMethod); - } - - @Override - public String getName() { - return "xor"; - } - } - - public static final class AndConditionFactory extends ConditionalFactory<CombinedCondition> { - @Override - public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { - return new CombinedCondition(element, AND, simpleMethod); - } - - @Override - public String getName() { - return "and"; - } - } - - public static final class NotConditionFactory extends ConditionalFactory<CombinedCondition> { - @Override - public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { - return new CombinedCondition(element, NOT, simpleMethod); - } - - @Override - public String getName() { - return "not"; - } - } public static final int OR = 1; public static final int XOR = 2; public static final int AND = 3; public static final int NOT = 4; - SimpleMethod simpleMethod; int conditionType; + SimpleMethod simpleMethod; List<Conditional> subConditions = FastList.newInstance(); public CombinedCondition(Element element, int conditionType, SimpleMethod simpleMethod) { this.simpleMethod = simpleMethod; this.conditionType = conditionType; - for (Element subElement: UtilXml.childElementList(element)) { + for (Element subElement : UtilXml.childElementList(element)) { subConditions.add(ConditionalFactory.makeConditional(subElement, simpleMethod)); } } public boolean checkCondition(MethodContext methodContext) { - if (subConditions.size() == 0) return true; - + if (subConditions.size() == 0) + return true; Iterator<Conditional> subCondIter = subConditions.iterator(); switch (this.conditionType) { case OR: @@ -144,23 +100,71 @@ public class CombinedCondition implement subCond.prettyPrint(messageBuffer, methodContext); if (subCondIter.hasNext()) { switch (this.conditionType) { - case OR: - messageBuffer.append(" OR "); - break; - case XOR: - messageBuffer.append(" XOR "); - break; - case AND: - messageBuffer.append(" AND "); - break; - case NOT: - messageBuffer.append(" NOT "); - break; - default: - messageBuffer.append("?"); + case OR: + messageBuffer.append(" OR "); + break; + case XOR: + messageBuffer.append(" XOR "); + break; + case AND: + messageBuffer.append(" AND "); + break; + case NOT: + messageBuffer.append(" NOT "); + break; + default: + messageBuffer.append("?"); } } } messageBuffer.append(")"); } + + public static final class AndConditionFactory extends ConditionalFactory<CombinedCondition> { + @Override + public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { + return new CombinedCondition(element, AND, simpleMethod); + } + + @Override + public String getName() { + return "and"; + } + } + + public static final class NotConditionFactory extends ConditionalFactory<CombinedCondition> { + @Override + public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { + return new CombinedCondition(element, NOT, simpleMethod); + } + + @Override + public String getName() { + return "not"; + } + } + + public static final class OrConditionFactory extends ConditionalFactory<CombinedCondition> { + @Override + public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { + return new CombinedCondition(element, OR, simpleMethod); + } + + @Override + public String getName() { + return "or"; + } + } + + public static final class XorConditionFactory extends ConditionalFactory<CombinedCondition> { + @Override + public CombinedCondition createCondition(Element element, SimpleMethod simpleMethod) { + return new CombinedCondition(element, XOR, simpleMethod); + } + + @Override + public String getName() { + return "xor"; + } + } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java?rev=1327981&r1=1327980&r2=1327981&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/conditional/CompareCondition.java Thu Apr 19 15:09:03 2012 @@ -18,47 +18,36 @@ *******************************************************************************/ package org.ofbiz.minilang.method.conditional; -import java.util.*; +import java.util.List; +import java.util.Map; import javolution.util.FastList; -import org.w3c.dom.*; -import org.ofbiz.base.util.*; -import org.ofbiz.minilang.*; -import org.ofbiz.minilang.method.*; -import org.ofbiz.minilang.operation.*; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.method.MethodContext; +import org.ofbiz.minilang.operation.BaseCompare; +import org.w3c.dom.Element; /** * Implements compare to a constant condition. */ public class CompareCondition implements Conditional { - public static final class CompareConditionFactory extends ConditionalFactory<CompareCondition> { - @Override - public CompareCondition createCondition(Element element, SimpleMethod simpleMethod) { - return new CompareCondition(element, simpleMethod); - } - - @Override - public String getName() { - return "if-compare"; - } - } - public static final String module = CompareCondition.class.getName(); - SimpleMethod simpleMethod; - - ContextAccessor<Map<String, ? extends Object>> mapAcsr; ContextAccessor<Object> fieldAcsr; - String value; - + String format; + ContextAccessor<Map<String, ? extends Object>> mapAcsr; String operator; + SimpleMethod simpleMethod; String type; - String format; + String value; public CompareCondition(Element element, SimpleMethod simpleMethod) { this.simpleMethod = simpleMethod; - // NOTE: this is still supported, but is deprecated this.mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map-name")); this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field")); @@ -67,7 +56,6 @@ public class CompareCondition implements this.fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field-name")); } this.value = element.getAttribute("value"); - this.operator = element.getAttribute("operator"); this.type = element.getAttribute("type"); this.format = element.getAttribute("format"); @@ -78,9 +66,7 @@ public class CompareCondition implements String operator = methodContext.expandString(this.operator); String type = methodContext.expandString(this.type); String format = methodContext.expandString(this.format); - Object fieldVal = getFieldVal(methodContext); - List<Object> messages = FastList.newInstance(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, value, operator, type, format, messages, null, methodContext.getLoader(), true); if (messages.size() > 0) { @@ -88,11 +74,10 @@ public class CompareCondition implements if (methodContext.getMethodType() == MethodContext.EVENT) { StringBuilder fullString = new StringBuilder(); - for (Object message: messages) { + for (Object message : messages) { fullString.append(message); } Debug.logWarning(fullString.toString(), module); - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), fullString.toString()); methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); } else if (methodContext.getMethodType() == MethodContext.SERVICE) { @@ -101,9 +86,8 @@ public class CompareCondition implements } return false; } - - if (resultBool != null) return resultBool.booleanValue(); - + if (resultBool != null) + return resultBool.booleanValue(); return false; } @@ -112,7 +96,8 @@ public class CompareCondition implements if (!mapAcsr.isEmpty()) { Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext); if (fromMap == null) { - if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module); + if (Debug.infoOn()) + Debug.logInfo("Map not found with name " + mapAcsr + ", using empty string for comparison", module); } else { fieldVal = fieldAcsr.get(fromMap, methodContext); } @@ -120,7 +105,6 @@ public class CompareCondition implements // no map name, try the env fieldVal = fieldAcsr.get(methodContext); } - // always use an empty string by default if (fieldVal == null) { fieldVal = ""; @@ -134,7 +118,6 @@ public class CompareCondition implements String type = methodContext.expandString(this.type); String format = methodContext.expandString(this.format); Object fieldVal = getFieldVal(methodContext); - messageBuffer.append("["); if (!this.mapAcsr.isEmpty()) { messageBuffer.append(this.mapAcsr); @@ -144,9 +127,7 @@ public class CompareCondition implements messageBuffer.append("="); messageBuffer.append(fieldVal); messageBuffer.append("] "); - messageBuffer.append(operator); - messageBuffer.append(" "); messageBuffer.append(value); messageBuffer.append(" as "); @@ -156,4 +137,16 @@ public class CompareCondition implements messageBuffer.append(format); } } + + public static final class CompareConditionFactory extends ConditionalFactory<CompareCondition> { + @Override + public CompareCondition createCondition(Element element, SimpleMethod simpleMethod) { + return new CompareCondition(element, simpleMethod); + } + + @Override + public String getName() { + return "if-compare"; + } + } } |
| Free forum by Nabble | Edit this page |
