1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.shared.util.el;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.Map;
26 import java.util.Set;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public abstract class ActionsMap implements Map
46 {
47
48 private Set keys;
49
50 public ActionsMap()
51 {
52
53 }
54
55 public ActionsMap(Set keys)
56 {
57 this.keys = keys;
58 }
59
60
61
62
63 public abstract void performAction(String command);
64
65 public int size()
66 {
67 return keys.size();
68 }
69
70 public boolean isEmpty()
71 {
72 return keys.isEmpty();
73 }
74
75 public boolean containsKey(Object key)
76 {
77 return keys.contains( key );
78 }
79
80 public boolean containsValue(Object value)
81 {
82 if( ! (value instanceof Boolean) )
83 {
84 return false;
85 }
86 return ((Boolean)value).booleanValue();
87 }
88
89 public Object get( Object key)
90 {
91 return Boolean.FALSE;
92 }
93
94 public Boolean put(String key, Boolean value)
95 {
96 if( value!=null && value.booleanValue() )
97 {
98 performAction(key);
99 }
100 return Boolean.FALSE;
101 }
102
103 public Object remove(Object key)
104 {
105 if( keys.remove( key ) )
106 {
107 return Boolean.FALSE;
108 }
109 return null;
110 }
111
112 public void putAll(Map map)
113 {
114 Iterator it = map.entrySet().iterator();
115
116 while (it.hasNext())
117 {
118 Entry entry = (Entry) it.next();
119 Object obj = entry.getValue();
120 if( (obj instanceof Boolean) && ((Boolean) obj).booleanValue() )
121 {
122 performAction((String) entry.getKey());
123 }
124 }
125 }
126
127 public void clear()
128 {
129 keys.clear();
130 }
131
132 public Set keySet()
133 {
134 return keys;
135 }
136
137 public Collection values()
138 {
139 return Collections.nCopies(keys.size(), Boolean.FALSE);
140 }
141
142 public Set entrySet()
143 {
144 Set set = new HashSet( keys.size() );
145
146 Iterator it = keys.iterator();
147
148 while (it.hasNext())
149 {
150 String command = (String) it.next();
151 set.add( new CommandEntry(command) );
152 }
153
154 return set;
155 }
156
157 private class CommandEntry implements Entry
158 {
159
160 private final String command;
161 private boolean commandPerformed = false;
162
163 public CommandEntry(String command)
164 {
165 this.command = command;
166 }
167
168 public Object getKey()
169 {
170 return command;
171 }
172
173 public Object getValue()
174 {
175 return Boolean.valueOf(commandPerformed);
176 }
177
178 public Object setValue(Object performCommand)
179 {
180 if( (performCommand instanceof Boolean) && ((Boolean)performCommand).booleanValue() )
181 {
182 performAction( command );
183 commandPerformed = true;
184 }
185 return Boolean.valueOf(commandPerformed);
186 }
187 }
188 }
189