KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: CallSimpleMapProcessor.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.*;
27
28 import org.w3c.dom.*;
29 import org.ofbiz.base.util.*;
30 import org.ofbiz.minilang.*;
31 import org.ofbiz.minilang.method.*;
32 import org.ofbiz.minilang.operation.*;
33
34 /**
35  * An event operation that calls a simple map processor inlined or from a separate file
36  *
37  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
38  * @version $Rev: 5462 $
39  * @since 2.0
40  */

41 public class CallSimpleMapProcessor extends MethodOperation {
42     
43     String JavaDoc xmlResource;
44     String JavaDoc processorName;
45     ContextAccessor inMapAcsr;
46     ContextAccessor outMapAcsr;
47     ContextAccessor errorListAcsr;
48
49     MapProcessor inlineMapProcessor = null;
50
51     public CallSimpleMapProcessor(Element element, SimpleMethod simpleMethod) {
52         super(element, simpleMethod);
53         xmlResource = element.getAttribute("xml-resource");
54         processorName = element.getAttribute("processor-name");
55         inMapAcsr = new ContextAccessor(element.getAttribute("in-map-name"));
56         outMapAcsr = new ContextAccessor(element.getAttribute("out-map-name"));
57         errorListAcsr = new ContextAccessor(element.getAttribute("error-list-name"), "error_list");
58
59         Element simpleMapProcessorElement = UtilXml.firstChildElement(element, "simple-map-processor");
60         if (simpleMapProcessorElement != null) {
61             inlineMapProcessor = new MapProcessor(simpleMapProcessorElement);
62         }
63     }
64
65     public boolean exec(MethodContext methodContext) {
66         List messages = (List) errorListAcsr.get(methodContext);
67         if (messages == null) {
68             messages = new LinkedList();
69             errorListAcsr.put(methodContext, messages);
70         }
71
72         Map inMap = (Map) inMapAcsr.get(methodContext);
73         if (inMap == null) {
74             inMap = new HashMap();
75             inMapAcsr.put(methodContext, inMap);
76         }
77
78         Map outMap = (Map) outMapAcsr.get(methodContext);
79         if (outMap == null) {
80             outMap = new HashMap();
81             outMapAcsr.put(methodContext, outMap);
82         }
83
84         // run external map processor first
85
if (this.xmlResource != null && this.xmlResource.length() > 0 &&
86                 this.processorName != null && this.processorName.length() > 0) {
87             String JavaDoc xmlResource = methodContext.expandString(this.xmlResource);
88             String JavaDoc processorName = methodContext.expandString(this.processorName);
89             try {
90                 org.ofbiz.minilang.SimpleMapProcessor.runSimpleMapProcessor(
91                     xmlResource, processorName, inMap, outMap, messages,
92                     methodContext.getLocale(), methodContext.getLoader());
93             } catch (MiniLangException e) {
94                 messages.add("Error running SimpleMapProcessor in XML file \"" + xmlResource + "\": " + e.toString());
95             }
96         }
97
98         // run inlined map processor last so it can override the external map processor
99
if (inlineMapProcessor != null) {
100             inlineMapProcessor.exec(inMap, outMap, messages,
101                 (methodContext.getRequest() != null ? methodContext.getRequest().getLocale() : null),
102                 methodContext.getLoader());
103         }
104
105         return true;
106     }
107
108     public String JavaDoc rawString() {
109         // TODO: something more than the empty tag
110
return "<call-simple-map-processor/>";
111     }
112     public String JavaDoc expandedString(MethodContext methodContext) {
113         // TODO: something more than a stub/dummy
114
return this.rawString();
115     }
116 }
117
Popular Tags