01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.minilang.method.envops;
19:
20: import java.util.*;
21:
22: import org.w3c.dom.*;
23: import org.ofbiz.base.util.*;
24: import org.ofbiz.minilang.*;
25: import org.ofbiz.minilang.method.*;
26:
27: /**
28: * Copies a map field to a map field
29: */
30: public class MapToMap extends MethodOperation {
31:
32: public static final String module = MapToMap.class.getName();
33:
34: ContextAccessor mapAcsr;
35: ContextAccessor toMapAcsr;
36:
37: public MapToMap(Element element, SimpleMethod simpleMethod) {
38: super (element, simpleMethod);
39: mapAcsr = new ContextAccessor(element.getAttribute("map-name"));
40: toMapAcsr = new ContextAccessor(element
41: .getAttribute("to-map-name"));
42: }
43:
44: public boolean exec(MethodContext methodContext) {
45: Map fromMap = null;
46: if (!mapAcsr.isEmpty()) {
47: fromMap = (Map) mapAcsr.get(methodContext);
48:
49: if (fromMap == null) {
50: if (Debug.infoOn())
51: Debug.logInfo("Map not found with name " + mapAcsr
52: + ", not copying from this map", module);
53: fromMap = new HashMap();
54: mapAcsr.put(methodContext, fromMap);
55: }
56: }
57:
58: if (!toMapAcsr.isEmpty()) {
59: Map toMap = (Map) toMapAcsr.get(methodContext);
60: if (toMap == null) {
61: if (Debug.verboseOn())
62: Debug.logVerbose("Map not found with name "
63: + toMapAcsr + ", creating new map", module);
64: toMap = new HashMap();
65: toMapAcsr.put(methodContext, toMap);
66: }
67:
68: toMap.putAll(fromMap);
69: } else {
70: methodContext.putAllEnv(fromMap);
71: }
72: return true;
73: }
74:
75: public String rawString() {
76: // TODO: something more than the empty tag
77: return "<map-to-map/>";
78: }
79:
80: public String expandedString(MethodContext methodContext) {
81: // TODO: something more than a stub/dummy
82: return this.rawString();
83: }
84: }
|