KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > display > HashMapModel


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: HashMapModel.java,v 1.3 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.display;
21
22
23 import java.util.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27 import org.enhydra.barracuda.core.comp.*;
28 import org.enhydra.barracuda.core.forms.*;
29 import org.enhydra.barracuda.core.comp.model.*;
30
31 public class HashMapModel extends AbstractTemplateModel implements LightweightTemplateModel {
32
33     protected Map values;
34     protected String JavaDoc modelName;
35
36     public String JavaDoc getName()
37     {
38         return modelName;
39     }
40
41     //csc_030703.1 - added
42
public Object JavaDoc getItem(TemplateDirective td) {
43         return getItem(td.getKeyName());
44     }
45
46
47     public Object JavaDoc getItem(String JavaDoc key) {
48         if(values != null && values.containsKey(key)) {
49             return values.get(key);
50         }
51         return super.getItem(key);
52     }
53
54     public void setName(String JavaDoc name)
55     {
56         modelName = name;
57     }
58
59     public HashMapModel() {
60         this(null, null);
61     }
62
63     public HashMapModel(String JavaDoc name, Map mp) {
64         modelName = name;
65         if(mp != null) {
66             values = mp;
67         } else {
68             values = new HashMap();
69         }
70     }
71
72     public HashMapModel(String JavaDoc name) {
73         this(name, null);
74     }
75
76
77     public HashMapModel(Map mp) {
78         this(null, mp);
79     }
80
81
82
83     public void setItem(String JavaDoc key, Object JavaDoc value) {
84         values.put(key, value);
85     }
86
87
88     public Map getItems() {
89         return values;
90     }
91
92     public void setItems(Map v) {
93         values = v;
94     }
95
96     public void clear() {
97         values.clear();
98     }
99
100     public Set keySet() {
101         return values.keySet();
102     }
103 }
104
Popular Tags