KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > minilang > method > envops > MapToMap


1 /*
2  * $Id: MapToMap.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 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.envops;
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
33 /**
34  * Copies a map field to a map field
35  *
36  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
37  * @version $Rev: 5462 $
38  * @since 2.0
39  */

40 public class MapToMap extends MethodOperation {
41     
42     public static final String JavaDoc module = MapToMap.class.getName();
43     
44     ContextAccessor mapAcsr;
45     ContextAccessor toMapAcsr;
46
47     public MapToMap(Element element, SimpleMethod simpleMethod) {
48         super(element, simpleMethod);
49         mapAcsr = new ContextAccessor(element.getAttribute("map-name"));
50         toMapAcsr = new ContextAccessor(element.getAttribute("to-map-name"));
51     }
52
53     public boolean exec(MethodContext methodContext) {
54         Map fromMap = null;
55         if (!mapAcsr.isEmpty()) {
56             fromMap = (Map) mapAcsr.get(methodContext);
57
58             if (fromMap == null) {
59                 if (Debug.infoOn()) Debug.logInfo("Map not found with name " + mapAcsr + ", not copying from this map", module);
60                 fromMap = new HashMap();
61                 mapAcsr.put(methodContext, fromMap);
62             }
63         }
64
65         if (!toMapAcsr.isEmpty()) {
66             Map toMap = (Map) toMapAcsr.get(methodContext);
67             if (toMap == null) {
68                 if (Debug.verboseOn()) Debug.logVerbose("Map not found with name " + toMapAcsr + ", creating new map", module);
69                 toMap = new HashMap();
70                 toMapAcsr.put(methodContext, toMap);
71             }
72
73             toMap.putAll(fromMap);
74         } else {
75             methodContext.putAllEnv(fromMap);
76         }
77         return true;
78     }
79
80     public String JavaDoc rawString() {
81         // TODO: something more than the empty tag
82
return "<map-to-map/>";
83     }
84     public String JavaDoc expandedString(MethodContext methodContext) {
85         // TODO: something more than a stub/dummy
86
return this.rawString();
87     }
88 }
89
Popular Tags