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