01: /*
02: * Copyright 2002,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.commons.jelly;
18:
19: import java.util.HashMap;
20:
21: import java.util.Map;
22:
23: /**
24: * <p><code>MapTag</code> is a DynaTag implementation which uses a Map
25: * to store its attribute values in. Derived tags can then process this
26: * Map, change values, add or remove attributes or perform some other form
27: * of processsing pretty easily.
28: * </p>
29: *
30: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
31: * @version $Revision: 155420 $
32: */
33:
34: public abstract class MapTagSupport extends DynaTagSupport {
35:
36: private Map map;
37:
38: /** Sets an attribute value of this tag before the tag is invoked
39: */
40: public void setAttribute(String name, Object value) {
41: getAttributes().put(name, value);
42: }
43:
44: /**
45: * Helper method which allows derived tags to access the attributes
46: * associated with this tag
47: */
48: protected Map getAttributes() {
49: if (map == null) {
50: map = createAttributes();
51: }
52: return map;
53: }
54:
55: /**
56: * A Factory Method which allows derived tags to overload the Map
57: * implementation used by this tag
58: */
59:
60: protected Map createAttributes() {
61: return new HashMap();
62: }
63:
64: }
|