KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > minilang > method > callops > CheckErrors


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

24 package org.ofbiz.minilang.method.callops;
25
26 import java.util.List JavaDoc;
27
28 import org.ofbiz.base.util.UtilXml;
29 import org.ofbiz.minilang.SimpleMethod;
30 import org.ofbiz.minilang.method.ContextAccessor;
31 import org.ofbiz.minilang.method.MethodContext;
32 import org.ofbiz.minilang.method.MethodOperation;
33 import org.w3c.dom.Element JavaDoc;
34
35 /**
36  * An event operation that checks a message list and may introduce a return code and stop the event
37  *
38  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
39  * @version $Rev: 5462 $
40  * @since 2.0
41  */

42 public class CheckErrors extends MethodOperation {
43     
44     ContextAccessor errorListAcsr;
45     String JavaDoc errorCode;
46
47     FlexibleMessage errorPrefix;
48     FlexibleMessage errorSuffix;
49     FlexibleMessage messagePrefix;
50     FlexibleMessage messageSuffix;
51
52     public CheckErrors(Element JavaDoc element, SimpleMethod simpleMethod) {
53         super(element, simpleMethod);
54         errorCode = element.getAttribute("error-code");
55         if (errorCode == null || errorCode.length() == 0) errorCode = "error";
56         
57         errorListAcsr = new ContextAccessor(element.getAttribute("error-list-name"), "error_list");
58
59         errorPrefix = new FlexibleMessage(UtilXml.firstChildElement(element, "error-prefix"), "check.error.prefix");
60         errorSuffix = new FlexibleMessage(UtilXml.firstChildElement(element, "error-suffix"), "check.error.suffix");
61         messagePrefix = new FlexibleMessage(UtilXml.firstChildElement(element, "message-prefix"), "check.message.prefix");
62         messageSuffix = new FlexibleMessage(UtilXml.firstChildElement(element, "message-suffix"), "check.message.suffix");
63     }
64
65     public boolean exec(MethodContext methodContext) {
66         List JavaDoc messages = (List JavaDoc) errorListAcsr.get(methodContext);
67
68         if (messages != null && messages.size() > 0) {
69             String JavaDoc errorCode = methodContext.expandString(this.errorCode);
70             
71             if (methodContext.getMethodType() == MethodContext.EVENT) {
72                 /* The OLD way, now puts formatting control in the template...
73                 String errMsg = errorPrefix.getMessage(methodContext.getLoader(), methodContext) +
74                     ServiceUtil.makeMessageList(messages, messagePrefix.getMessage(methodContext.getLoader(), methodContext),
75                             messageSuffix.getMessage(methodContext.getLoader(), methodContext)) +
76                             errorSuffix.getMessage(methodContext.getLoader(), methodContext);
77                 methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg);
78                  */

79                 methodContext.putEnv(simpleMethod.getEventErrorMessageListName(), messages);
80                 methodContext.putEnv(simpleMethod.getEventResponseCodeName(), errorCode);
81                 return false;
82             } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
83                 methodContext.putEnv(simpleMethod.getServiceErrorMessageListName(), messages);
84                 methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), errorCode);
85                 return false;
86             } else {
87                 return false;
88             }
89         }
90
91         return true;
92     }
93
94     public String JavaDoc rawString() {
95         // TODO: something more than the empty tag
96
return "<check-errors/>";
97     }
98     public String JavaDoc expandedString(MethodContext methodContext) {
99         // TODO: something more than a stub/dummy
100
return this.rawString();
101     }
102 }
103
Popular Tags