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:
24: import org.ofbiz.base.util.*;
25: import org.ofbiz.minilang.*;
26: import org.ofbiz.minilang.method.*;
27:
28: /**
29: * Clears the specified field
30: */
31: public class ClearField extends MethodOperation {
32:
33: public static final String module = ClearField.class.getName();
34:
35: ContextAccessor mapAcsr;
36: ContextAccessor fieldAcsr;
37:
38: public ClearField(Element element, SimpleMethod simpleMethod) {
39: super (element, simpleMethod);
40: mapAcsr = new ContextAccessor(element.getAttribute("map-name"));
41: fieldAcsr = new ContextAccessor(element
42: .getAttribute("field-name"));
43: }
44:
45: public boolean exec(MethodContext methodContext) {
46: if (!mapAcsr.isEmpty()) {
47: Map toMap = (Map) mapAcsr.get(methodContext);
48:
49: if (toMap == null) {
50: // it seems silly to create a new map, but necessary since whenever
51: // an env field like a Map or List is referenced it should be created, even if empty
52: if (Debug.verboseOn())
53: Debug.logVerbose("Map not found with name "
54: + mapAcsr + ", creating new map", module);
55: toMap = new HashMap();
56: mapAcsr.put(methodContext, toMap);
57: }
58:
59: fieldAcsr.put(toMap, null, methodContext);
60: } else {
61: fieldAcsr.put(methodContext, null);
62: }
63:
64: return true;
65: }
66:
67: public String rawString() {
68: return "<clear-field field-name=\"" + this .fieldAcsr
69: + "\" map-name=\"" + this .mapAcsr + "\"/>";
70: }
71:
72: public String expandedString(MethodContext methodContext) {
73: // TODO: something more than a stub/dummy
74: return this.rawString();
75: }
76: }
|