1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view; |
20 | |
|
21 | |
import java.util.Collection; |
22 | |
import java.util.HashMap; |
23 | |
import java.util.Map; |
24 | |
import java.util.Set; |
25 | |
import javax.faces.component.StateHolder; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
import javax.faces.event.PreDestroyViewMapEvent; |
28 | |
import org.apache.myfaces.spi.ViewScopeProvider; |
29 | |
import org.apache.myfaces.spi.ViewScopeProviderFactory; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class ViewScopeProxyMap implements Map<String, Object>, StateHolder |
44 | |
{ |
45 | |
private String _viewScopeId; |
46 | |
|
47 | |
private transient Map<String, Object> _delegate; |
48 | |
|
49 | |
public ViewScopeProxyMap() |
50 | 0 | { |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
public String getViewScopeId() |
55 | |
{ |
56 | 0 | return _viewScopeId; |
57 | |
} |
58 | |
|
59 | |
public void forceCreateWrappedMap(FacesContext facesContext) |
60 | |
{ |
61 | 0 | getWrapped(); |
62 | 0 | } |
63 | |
|
64 | |
public Map<String, Object> getWrapped() |
65 | |
{ |
66 | 0 | if (_delegate == null) |
67 | |
{ |
68 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
69 | |
|
70 | 0 | if (facesContext != null) |
71 | |
{ |
72 | 0 | ViewScopeProviderFactory factory = ViewScopeProviderFactory.getViewScopeHandlerFactory( |
73 | |
facesContext.getExternalContext()); |
74 | |
|
75 | 0 | ViewScopeProvider handler = factory.getViewScopeHandler(facesContext.getExternalContext()); |
76 | |
|
77 | 0 | if (_viewScopeId == null) |
78 | |
{ |
79 | 0 | _viewScopeId = handler.generateViewScopeId(facesContext); |
80 | 0 | _delegate = handler.createViewScopeMap(facesContext, _viewScopeId); |
81 | |
} |
82 | |
else |
83 | |
{ |
84 | 0 | _delegate = handler.restoreViewScopeMap(facesContext, _viewScopeId); |
85 | |
} |
86 | 0 | } |
87 | |
else |
88 | |
{ |
89 | |
|
90 | |
|
91 | 0 | _delegate = new ViewScope(); |
92 | |
} |
93 | |
} |
94 | 0 | return _delegate; |
95 | |
} |
96 | |
|
97 | |
public int size() |
98 | |
{ |
99 | 0 | return getWrapped().size(); |
100 | |
} |
101 | |
|
102 | |
public boolean isEmpty() |
103 | |
{ |
104 | 0 | return getWrapped().isEmpty(); |
105 | |
} |
106 | |
|
107 | |
public boolean containsKey(Object key) |
108 | |
{ |
109 | 0 | return getWrapped().containsKey(key); |
110 | |
} |
111 | |
|
112 | |
public boolean containsValue(Object value) |
113 | |
{ |
114 | 0 | return getWrapped().containsValue(value); |
115 | |
} |
116 | |
|
117 | |
public Object get(Object key) |
118 | |
{ |
119 | 0 | return getWrapped().get(key); |
120 | |
} |
121 | |
|
122 | |
public Object put(String key, Object value) |
123 | |
{ |
124 | 0 | return getWrapped().put(key, value); |
125 | |
} |
126 | |
|
127 | |
public Object remove(Object key) |
128 | |
{ |
129 | 0 | return getWrapped().remove(key); |
130 | |
} |
131 | |
|
132 | |
public void putAll(Map<? extends String, ? extends Object> m) |
133 | |
{ |
134 | 0 | getWrapped().putAll(m); |
135 | 0 | } |
136 | |
|
137 | |
public void clear() |
138 | |
{ |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
145 | 0 | facesContext.getApplication().publishEvent(facesContext, |
146 | |
PreDestroyViewMapEvent.class, facesContext.getViewRoot()); |
147 | |
|
148 | 0 | getWrapped().clear(); |
149 | 0 | } |
150 | |
|
151 | |
public Set<String> keySet() |
152 | |
{ |
153 | 0 | return getWrapped().keySet(); |
154 | |
} |
155 | |
|
156 | |
public Collection<Object> values() |
157 | |
{ |
158 | 0 | return getWrapped().values(); |
159 | |
} |
160 | |
|
161 | |
public Set<Entry<String, Object>> entrySet() |
162 | |
{ |
163 | 0 | return getWrapped().entrySet(); |
164 | |
} |
165 | |
|
166 | |
public void restoreState(FacesContext context, Object state) |
167 | |
{ |
168 | 0 | _viewScopeId = (String) state; |
169 | 0 | } |
170 | |
|
171 | |
public Object saveState(FacesContext context) |
172 | |
{ |
173 | 0 | return _viewScopeId; |
174 | |
} |
175 | |
|
176 | |
public boolean isTransient() |
177 | |
{ |
178 | 0 | return false; |
179 | |
} |
180 | |
|
181 | |
public void setTransient(boolean newTransientValue) |
182 | |
{ |
183 | 0 | } |
184 | |
|
185 | 0 | private static class ViewScope extends HashMap<String, Object> |
186 | |
{ |
187 | |
|
188 | |
private static final long serialVersionUID = -1088293802269478164L; |
189 | |
|
190 | |
@Override |
191 | |
public void clear() |
192 | |
{ |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
199 | 0 | facesContext.getApplication().publishEvent(facesContext, |
200 | |
PreDestroyViewMapEvent.class, facesContext.getViewRoot()); |
201 | |
|
202 | 0 | super.clear(); |
203 | 0 | } |
204 | |
|
205 | |
} |
206 | |
|
207 | |
} |