You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2007/10/21 06:06:01 UTC
svn commit: r586855 - in
/ofbiz/trunk/framework/service/src/org/ofbiz/service:
GeneralServiceException.java ModelService.java ServiceUtil.java
eca/ServiceEcaAction.java eca/ServiceEcaCondition.java
test/ServiceEngineTestServices.java
Author: doogie
Date: Sat Oct 20 21:06:00 2007
New Revision: 586855
URL: http://svn.apache.org/viewvc?rev=586855&view=rev
Log:
All error message lists and maps are now make use of java 1.5
features.
Modified:
ofbiz/trunk/framework/service/src/org/ofbiz/service/GeneralServiceException.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaCondition.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/GeneralServiceException.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/GeneralServiceException.java?rev=586855&r1=586854&r2=586855&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/GeneralServiceException.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/GeneralServiceException.java Sat Oct 20 21:06:00 2007
@@ -23,14 +23,15 @@
import java.util.Map;
import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilMisc;
/**
* General Service Exception - base Exception for in-Service Errors
*/
public class GeneralServiceException extends org.ofbiz.base.util.GeneralException {
- protected List errorMsgList = null;
- protected Map errorMsgMap = null;
+ protected List<Object> errorMsgList = null;
+ protected Map<String, ? extends Object> errorMsgMap = null;
protected Map nestedServiceResult = null;
public GeneralServiceException() {
@@ -49,9 +50,9 @@
super(nested);
}
- public GeneralServiceException(String str, List errorMsgList, Map errorMsgMap, Map nestedServiceResult, Throwable nested) {
+ public GeneralServiceException(String str, List<? extends Object> errorMsgList, Map<String, ? extends Object> errorMsgMap, Map nestedServiceResult, Throwable nested) {
super(str, nested);
- this.errorMsgList = errorMsgList;
+ this.errorMsgList = UtilMisc.makeListWritable(errorMsgList);
this.errorMsgMap = errorMsgMap;
this.nestedServiceResult = nestedServiceResult;
}
@@ -64,9 +65,9 @@
return ServiceUtil.returnError(errMsg, this.errorMsgList, this.errorMsgMap, this.nestedServiceResult);
}
- public void addErrorMessages(List errMsgs) {
+ public void addErrorMessages(List<? extends Object> errMsgs) {
if (this.errorMsgList == null) {
- this.errorMsgList = new LinkedList();
+ this.errorMsgList = new LinkedList<Object>();
}
this.errorMsgList.addAll(errMsgs);
}
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?rev=586855&r1=586854&r2=586855&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Sat Oct 20 21:06:00 2007
@@ -699,7 +699,7 @@
* @param mode The mode which to build the new map
* @param includeInternal When false will exclude internal fields
*/
- public Map makeValid(Map source, String mode, boolean includeInternal, List errorMessages) {
+ public Map makeValid(Map source, String mode, boolean includeInternal, List<Object> errorMessages) {
return makeValid(source, mode, includeInternal, errorMessages, null);
}
@@ -711,7 +711,7 @@
* @param includeInternal When false will exclude internal fields
* @param locale Locale to use to do some type conversion
*/
- public Map makeValid(Map source, String mode, boolean includeInternal, List errorMessages, Locale locale) {
+ public Map makeValid(Map source, String mode, boolean includeInternal, List<Object> errorMessages, Locale locale) {
return makeValid(source, mode, includeInternal, errorMessages, null, locale);
}
@@ -724,7 +724,7 @@
* @param tz TimeZone to use to do some type conversion
* @param locale Locale to use to do some type conversion
*/
- public Map makeValid(Map source, String mode, boolean includeInternal, List errorMessages, TimeZone timeZone, Locale locale) {
+ public Map makeValid(Map source, String mode, boolean includeInternal, List<Object> errorMessages, TimeZone timeZone, Locale locale) {
Map target = FastMap.newInstance();
if (source == null) {
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java?rev=586855&r1=586854&r2=586855&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceUtil.java Sat Oct 20 21:06:00 2007
@@ -70,12 +70,12 @@
}
/** A small routine used all over to improve code efficiency, make a result map with the message and the error response code */
- public static Map returnError(String errorMessage, List errorMessageList) {
+ public static Map returnError(String errorMessage, List<? extends Object> errorMessageList) {
return returnProblem(ModelService.RESPOND_ERROR, errorMessage, errorMessageList, null, null);
}
/** A small routine used all over to improve code efficiency, make a result map with the message and the error response code */
- public static Map returnError(List errorMessageList) {
+ public static Map returnError(List<? extends Object> errorMessageList) {
return returnProblem(ModelService.RESPOND_ERROR, null, errorMessageList, null, null);
}
@@ -83,7 +83,7 @@
return returnProblem(ModelService.RESPOND_FAIL, errorMessage, null, null, null);
}
- public static Map returnFailure(List errorMessageList) {
+ public static Map returnFailure(List<? extends Object> errorMessageList) {
return returnProblem(ModelService.RESPOND_FAIL, null, errorMessageList, null, null);
}
@@ -92,23 +92,23 @@
}
/** A small routine used all over to improve code efficiency, make a result map with the message and the error response code, also forwards any error messages from the nestedResult */
- public static Map returnError(String errorMessage, List errorMessageList, Map errorMessageMap, Map nestedResult) {
+ public static Map returnError(String errorMessage, List<? extends Object> errorMessageList, Map<String, ? extends Object> errorMessageMap, Map nestedResult) {
return returnProblem(ModelService.RESPOND_ERROR, errorMessage, errorMessageList, errorMessageMap, nestedResult);
}
- public static Map returnProblem(String returnType, String errorMessage, List errorMessageList, Map errorMessageMap, Map nestedResult) {
+ public static Map returnProblem(String returnType, String errorMessage, List<? extends Object> errorMessageList, Map<String, ? extends Object> errorMessageMap, Map nestedResult) {
Map result = FastMap.newInstance();
result.put(ModelService.RESPONSE_MESSAGE, returnType);
if (errorMessage != null) {
result.put(ModelService.ERROR_MESSAGE, errorMessage);
}
- List errorList = new LinkedList();
+ List<Object> errorList = new LinkedList<Object>();
if (errorMessageList != null) {
errorList.addAll(errorMessageList);
}
- Map errorMap = FastMap.newInstance();
+ Map<String, Object> errorMap = FastMap.newInstance();
if (errorMessageMap != null) {
errorMap.putAll(errorMessageMap);
}
@@ -118,10 +118,10 @@
errorList.add(nestedResult.get(ModelService.ERROR_MESSAGE));
}
if (nestedResult.get(ModelService.ERROR_MESSAGE_LIST) != null) {
- errorList.addAll((List) nestedResult.get(ModelService.ERROR_MESSAGE_LIST));
+ errorList.addAll(UtilGenerics.checkList(nestedResult.get(ModelService.ERROR_MESSAGE_LIST)));
}
if (nestedResult.get(ModelService.ERROR_MESSAGE_MAP) != null) {
- errorMap.putAll((Map) nestedResult.get(ModelService.ERROR_MESSAGE_MAP));
+ errorMap.putAll(UtilGenerics.<String, Object>checkMap(nestedResult.get(ModelService.ERROR_MESSAGE_MAP)));
}
}
@@ -214,11 +214,10 @@
if (result.get(ModelService.ERROR_MESSAGE) != null) errorMessage.append((String) result.get(ModelService.ERROR_MESSAGE));
if (result.get(ModelService.ERROR_MESSAGE_LIST) != null) {
- List errors = (List) result.get(ModelService.ERROR_MESSAGE_LIST);
- Iterator errorIter = errors.iterator();
- while (errorIter.hasNext()) {
+ List<? extends Object> errors = UtilGenerics.checkList(result.get(ModelService.ERROR_MESSAGE_LIST));
+ for (Object message: errors) {
// NOTE: this MUST use toString and not cast to String because it may be a MessageString object
- String curMessage = errorIter.next().toString();
+ String curMessage = message.toString();
if (errorMessage.length() > 0) {
errorMessage.append(", ");
}
@@ -235,8 +234,8 @@
return null;
}
String errorMsg = (String) result.get(ModelService.ERROR_MESSAGE);
- List errorMsgList = (List) result.get(ModelService.ERROR_MESSAGE_LIST);
- Map errorMsgMap = (Map) result.get(ModelService.ERROR_MESSAGE_MAP);
+ List<? extends Object> errorMsgList = UtilGenerics.checkList(result.get(ModelService.ERROR_MESSAGE_LIST));
+ Map<String, ? extends Object> errorMsgMap = UtilGenerics.checkMap(result.get(ModelService.ERROR_MESSAGE_MAP));
StringBuilder outMsg = new StringBuilder();
if (errorMsg != null) {
@@ -248,11 +247,7 @@
outMsg.append(makeMessageList(errorMsgList, msgPrefix, msgSuffix));
if (errorMsgMap != null) {
- Iterator mapIter = errorMsgMap.entrySet().iterator();
-
- while (mapIter.hasNext()) {
- Map.Entry entry = (Map.Entry) mapIter.next();
-
+ for (Map.Entry<String, ? extends Object> entry: errorMsgMap.entrySet()) {
outMsg.append(msgPrefix);
outMsg.append(entry.getKey());
outMsg.append(": ");
@@ -300,12 +295,10 @@
}
}
- public static String makeMessageList(List msgList, String msgPrefix, String msgSuffix) {
+ public static String makeMessageList(List<? extends Object> msgList, String msgPrefix, String msgSuffix) {
StringBuilder outMsg = new StringBuilder();
if (msgList != null && msgList.size() > 0) {
- Iterator iter = msgList.iterator();
- while (iter.hasNext()) {
- Object msg = iter.next();
+ for (Object msg: msgList) {
if (msg == null) continue;
String curMsg = msg.toString();
if (msgPrefix != null) outMsg.append(msgPrefix);
@@ -325,9 +318,9 @@
* @param targetMap The Map to add any Map error messages to
* @param callResult The result from an invocation
*/
- public static void addErrors(List targetList, Map targetMap, Map callResult) {
- List newList;
- Map errorMsgMap;
+ public static void addErrors(List<Object> targetList, Map<String, Object> targetMap, Map callResult) {
+ List<? extends Object> newList;
+ Map<String, ? extends Object> errorMsgMap;
//See if there is a single message
if (callResult.containsKey(ModelService.ERROR_MESSAGE)) {
@@ -336,13 +329,13 @@
//See if there is a message list
if (callResult.containsKey(ModelService.ERROR_MESSAGE_LIST)) {
- newList = (List) callResult.get(ModelService.ERROR_MESSAGE_LIST);
+ newList = UtilGenerics.checkList(callResult.get(ModelService.ERROR_MESSAGE_LIST));
targetList.addAll(newList);
}
//See if there are an error message map
if (callResult.containsKey(ModelService.ERROR_MESSAGE_MAP)) {
- errorMsgMap = (Map) callResult.get(ModelService.ERROR_MESSAGE_MAP);
+ errorMsgMap = UtilGenerics.checkMap(callResult.get(ModelService.ERROR_MESSAGE_MAP));
targetMap.putAll(errorMsgMap);
}
}
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java?rev=586855&r1=586854&r2=586855&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaAction.java Sat Oct 20 21:06:00 2007
@@ -23,6 +23,7 @@
import javolution.util.FastMap;
+import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
@@ -158,21 +159,25 @@
if (result != null && !success) {
String errorMessage = (String) actionResult.get(ModelService.ERROR_MESSAGE);
- List errorMessageList = (List) actionResult.get(ModelService.ERROR_MESSAGE_LIST);
- Map errorMessageMap = (Map) actionResult.get(ModelService.ERROR_MESSAGE_MAP);
+ List<? extends Object> errorMessageList = UtilGenerics.checkList(actionResult.get(ModelService.ERROR_MESSAGE_LIST));
+ Map<String, ? extends Object> errorMessageMap = UtilGenerics.checkMap(actionResult.get(ModelService.ERROR_MESSAGE_MAP));
// do something with the errorMessage
if (UtilValidate.isNotEmpty(errorMessage)) {
if (UtilValidate.isEmpty((String) result.get(ModelService.ERROR_MESSAGE))) {
result.put(ModelService.ERROR_MESSAGE, errorMessage);
} else {
- if (errorMessageList == null) errorMessageList = new LinkedList();
- errorMessageList.add(0, errorMessage);
+ List<Object> origErrorMessageList = UtilGenerics.checkList(result.get(ModelService.ERROR_MESSAGE_LIST));
+ if (origErrorMessageList == null) {
+ origErrorMessageList = new LinkedList<Object>();
+ result.put(ModelService.ERROR_MESSAGE_LIST, origErrorMessageList);
+ }
+ origErrorMessageList.add(0, errorMessage);
}
}
// do something with the errorMessageList
if (errorMessageList != null && errorMessageList.size() > 0) {
- List origErrorMessageList = (List) result.get(ModelService.ERROR_MESSAGE_LIST);
+ List<Object> origErrorMessageList = UtilGenerics.checkList(result.get(ModelService.ERROR_MESSAGE_LIST));
if (origErrorMessageList == null) {
result.put(ModelService.ERROR_MESSAGE_LIST, errorMessageList);
} else {
@@ -181,7 +186,7 @@
}
// do something with the errorMessageMap
if (errorMessageMap != null && errorMessageMap.size() > 0) {
- Map origErrorMessageMap = (Map) result.get(ModelService.ERROR_MESSAGE_MAP);
+ Map<String, Object> origErrorMessageMap = UtilGenerics.checkMap(result.get(ModelService.ERROR_MESSAGE_MAP));
if (origErrorMessageMap == null) {
result.put(ModelService.ERROR_MESSAGE_MAP, errorMessageMap);
} else {
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaCondition.java?rev=586855&r1=586854&r2=586855&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaCondition.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/eca/ServiceEcaCondition.java Sat Oct 20 21:06:00 2007
@@ -29,6 +29,7 @@
import org.ofbiz.service.ServiceUtil;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilMisc;
import org.w3c.dom.Element;
@@ -152,14 +153,13 @@
if (Debug.verboseOn()) Debug.logVerbose("Comparing : " + lhsValue + " " + operator + " " + rhsValue, module);
// evaluate the condition & invoke the action(s)
- List messages = new LinkedList();
+ List<Object> messages = new LinkedList<Object>();
Boolean cond = ObjectType.doRealCompare(lhsValue, rhsValue, operator, compareType, format, messages, null, dctx.getClassLoader(), isConstant);
// if any messages were returned send them out
if (messages.size() > 0) {
- Iterator m = messages.iterator();
- while (m.hasNext()) {
- Debug.logWarning((String) m.next(), module);
+ for (Object message: messages) {
+ Debug.logWarning(message.toString(), module);
}
}
if (cond != null) {
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java?rev=586855&r1=586854&r2=586855&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTestServices.java Sat Oct 20 21:06:00 2007
@@ -48,7 +48,7 @@
// make sure to wait for these to both finish to make sure results aren't checked until they are done
Map threadAResult = threadAWaiter.waitForResult();
Map threadBResult = threadBWaiter.waitForResult();
- List errorList = FastList.newInstance();
+ List<Object> errorList = FastList.newInstance();
if (ServiceUtil.isError(threadAResult)) {
errorList.add("Error running testServiceDeadLockRetryThreadA: " + ServiceUtil.getErrorMessage(threadAResult));
}
@@ -147,7 +147,7 @@
// make sure to wait for these to both finish to make sure results aren't checked until they are done
Map grabberResult = grabberWaiter.waitForResult();
Map waiterResult = waiterWaiter.waitForResult();
- List errorList = FastList.newInstance();
+ List<Object> errorList = FastList.newInstance();
if (ServiceUtil.isError(grabberResult)) {
errorList.add("Error running testServiceLockWaitTimeoutRetryGrabber: " + ServiceUtil.getErrorMessage(grabberResult));
}