001: /*
002: * $Id: SimpleMapProcess.java,v 1.1 2003/08/17 06:06:11 ajzeneski Exp $
003: *
004: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024: package org.ofbiz.minilang.operation;
025:
026: import java.util.*;
027:
028: import org.w3c.dom.*;
029: import org.ofbiz.base.util.*;
030:
031: /**
032: * A complete string process for a given field; contains multiple string operations
033: *
034: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
035: * @version $Revision: 1.1 $
036: * @since 2.0
037: */
038: public class SimpleMapProcess {
039:
040: public static final String module = SimpleMapProcess.class
041: .getName();
042:
043: List simpleMapOperations = new LinkedList();
044: String field = "";
045:
046: public SimpleMapProcess(Element simpleMapProcessElement) {
047: this .field = simpleMapProcessElement.getAttribute("field");
048: readOperations(simpleMapProcessElement);
049: }
050:
051: public String getFieldName() {
052: return field;
053: }
054:
055: public void exec(Map inMap, Map results, List messages,
056: Locale locale, ClassLoader loader) {
057: Iterator strOpsIter = simpleMapOperations.iterator();
058:
059: while (strOpsIter.hasNext()) {
060: SimpleMapOperation simpleMapOperation = (SimpleMapOperation) strOpsIter
061: .next();
062:
063: simpleMapOperation.exec(inMap, results, messages, locale,
064: loader);
065: }
066: }
067:
068: void readOperations(Element simpleMapProcessElement) {
069: List operationElements = UtilXml.childElementList(
070: simpleMapProcessElement, null);
071:
072: if (operationElements != null && operationElements.size() > 0) {
073: Iterator operElemIter = operationElements.iterator();
074:
075: while (operElemIter.hasNext()) {
076: Element curOperElem = (Element) operElemIter.next();
077: String nodeName = curOperElem.getNodeName();
078:
079: if ("validate-method".equals(nodeName)) {
080: simpleMapOperations.add(new ValidateMethod(
081: curOperElem, this ));
082: } else if ("compare".equals(nodeName)) {
083: simpleMapOperations.add(new Compare(curOperElem,
084: this ));
085: } else if ("compare-field".equals(nodeName)) {
086: simpleMapOperations.add(new CompareField(
087: curOperElem, this ));
088: } else if ("regexp".equals(nodeName)) {
089: simpleMapOperations.add(new Regexp(curOperElem,
090: this ));
091: } else if ("not-empty".equals(nodeName)) {
092: simpleMapOperations.add(new NotEmpty(curOperElem,
093: this ));
094: } else if ("copy".equals(nodeName)) {
095: simpleMapOperations
096: .add(new Copy(curOperElem, this ));
097: } else if ("convert".equals(nodeName)) {
098: simpleMapOperations.add(new Convert(curOperElem,
099: this ));
100: } else {
101: Debug.logWarning(
102: "[SimpleMapProcessor.SimpleMapProcess.readOperations] Operation element \""
103: + nodeName + "\" not recognized",
104: module);
105: }
106: }
107: }
108: }
109: }
|