01: /*
02: * $Id: SimpleMapOperation.java,v 1.1 2003/08/17 06:06:11 ajzeneski Exp $
03: *
04: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * 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.operation;
25:
26: import java.util.*;
27:
28: import org.w3c.dom.*;
29: import org.ofbiz.base.util.*;
30:
31: /**
32: * A single operation, does the specified operation on the given field
33: *
34: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
35: * @version $Revision: 1.1 $
36: * @since 2.0
37: */
38: public abstract class SimpleMapOperation {
39:
40: String message = null;
41: String propertyResource = null;
42: boolean isProperty = false;
43: SimpleMapProcess simpleMapProcess;
44: String fieldName;
45:
46: public SimpleMapOperation(Element element,
47: SimpleMapProcess simpleMapProcess) {
48: Element failMessage = UtilXml.firstChildElement(element,
49: "fail-message");
50: Element failProperty = UtilXml.firstChildElement(element,
51: "fail-property");
52:
53: if (failMessage != null) {
54: this .message = failMessage.getAttribute("message");
55: this .isProperty = false;
56: } else if (failProperty != null) {
57: this .propertyResource = failProperty
58: .getAttribute("resource");
59: this .message = failProperty.getAttribute("property");
60: this .isProperty = true;
61: }
62:
63: this .simpleMapProcess = simpleMapProcess;
64: this .fieldName = simpleMapProcess.getFieldName();
65: }
66:
67: public abstract void exec(Map inMap, Map results, List messages,
68: Locale locale, ClassLoader loader);
69:
70: public void addMessage(List messages, ClassLoader loader) {
71: if (!isProperty && message != null) {
72: messages.add(message);
73: // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding message: " + message, module);
74: } else if (isProperty && propertyResource != null
75: && message != null) {
76: String propMsg = UtilProperties.getPropertyValue(UtilURL
77: .fromResource(propertyResource, loader), message);
78:
79: if (propMsg == null || propMsg.length() == 0)
80: messages
81: .add("Simple Map Processing error occurred, but no message was found, sorry.");
82: else
83: messages.add(propMsg);
84: // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding property message: " + propMsg, module);
85: } else {
86: messages
87: .add("Simple Map Processing error occurred, but no message was found, sorry.");
88: // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] ERROR: No message found", module);
89: }
90: }
91: }
|