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 | 0 | { |
52 | |
|
53 | 0 | } |
54 | |
|
55 | |
public ActionsMap(Set keys) |
56 | 0 | { |
57 | 0 | this.keys = keys; |
58 | 0 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public abstract void performAction(String command); |
64 | |
|
65 | |
public int size() |
66 | |
{ |
67 | 0 | return keys.size(); |
68 | |
} |
69 | |
|
70 | |
public boolean isEmpty() |
71 | |
{ |
72 | 0 | return keys.isEmpty(); |
73 | |
} |
74 | |
|
75 | |
public boolean containsKey(Object key) |
76 | |
{ |
77 | 0 | return keys.contains( key ); |
78 | |
} |
79 | |
|
80 | |
public boolean containsValue(Object value) |
81 | |
{ |
82 | 0 | if( ! (value instanceof Boolean) ) |
83 | |
{ |
84 | 0 | return false; |
85 | |
} |
86 | 0 | return ((Boolean)value).booleanValue(); |
87 | |
} |
88 | |
|
89 | |
public Object get( Object key) |
90 | |
{ |
91 | 0 | return Boolean.FALSE; |
92 | |
} |
93 | |
|
94 | |
public Boolean put(String key, Boolean value) |
95 | |
{ |
96 | 0 | if( value!=null && value.booleanValue() ) |
97 | |
{ |
98 | 0 | performAction(key); |
99 | |
} |
100 | 0 | return Boolean.FALSE; |
101 | |
} |
102 | |
|
103 | |
public Object remove(Object key) |
104 | |
{ |
105 | 0 | if( keys.remove( key ) ) |
106 | |
{ |
107 | 0 | return Boolean.FALSE; |
108 | |
} |
109 | 0 | return null; |
110 | |
} |
111 | |
|
112 | |
public void putAll(Map map) |
113 | |
{ |
114 | 0 | Iterator it = map.entrySet().iterator(); |
115 | |
|
116 | 0 | while (it.hasNext()) |
117 | |
{ |
118 | 0 | Entry entry = (Entry) it.next(); |
119 | 0 | Object obj = entry.getValue(); |
120 | 0 | if( (obj instanceof Boolean) && ((Boolean) obj).booleanValue() ) |
121 | |
{ |
122 | 0 | performAction((String) entry.getKey()); |
123 | |
} |
124 | 0 | } |
125 | 0 | } |
126 | |
|
127 | |
public void clear() |
128 | |
{ |
129 | 0 | keys.clear(); |
130 | 0 | } |
131 | |
|
132 | |
public Set keySet() |
133 | |
{ |
134 | 0 | return keys; |
135 | |
} |
136 | |
|
137 | |
public Collection values() |
138 | |
{ |
139 | 0 | return Collections.nCopies(keys.size(), Boolean.FALSE); |
140 | |
} |
141 | |
|
142 | |
public Set entrySet() |
143 | |
{ |
144 | 0 | Set set = new HashSet( keys.size() ); |
145 | |
|
146 | 0 | Iterator it = keys.iterator(); |
147 | |
|
148 | 0 | while (it.hasNext()) |
149 | |
{ |
150 | 0 | String command = (String) it.next(); |
151 | 0 | set.add( new CommandEntry(command) ); |
152 | 0 | } |
153 | |
|
154 | 0 | return set; |
155 | |
} |
156 | |
|
157 | |
private class CommandEntry implements Entry |
158 | |
{ |
159 | |
|
160 | |
private final String command; |
161 | 0 | private boolean commandPerformed = false; |
162 | |
|
163 | |
public CommandEntry(String command) |
164 | 0 | { |
165 | 0 | this.command = command; |
166 | 0 | } |
167 | |
|
168 | |
public Object getKey() |
169 | |
{ |
170 | 0 | return command; |
171 | |
} |
172 | |
|
173 | |
public Object getValue() |
174 | |
{ |
175 | 0 | return Boolean.valueOf(commandPerformed); |
176 | |
} |
177 | |
|
178 | |
public Object setValue(Object performCommand) |
179 | |
{ |
180 | 0 | if( (performCommand instanceof Boolean) && ((Boolean)performCommand).booleanValue() ) |
181 | |
{ |
182 | 0 | performAction( command ); |
183 | 0 | commandPerformed = true; |
184 | |
} |
185 | 0 | return Boolean.valueOf(commandPerformed); |
186 | |
} |
187 | |
} |
188 | |
} |
189 | |
|