1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.context; |
20 | |
|
21 | |
import java.io.Serializable; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collections; |
24 | |
import java.util.HashMap; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
import javax.faces.application.ResourceDependency; |
28 | |
import javax.faces.context.FacesContext; |
29 | |
import org.apache.myfaces.view.facelets.el.ELText; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class RequestViewMetadata implements Serializable |
36 | |
{ |
37 | |
public static final String RESOURCE_DEPENDENCY_KEY = "oam.component.resource.RDK"; |
38 | |
|
39 | |
|
40 | 0 | private Map<Class<?>, Boolean> processedClasses = new HashMap<Class<?>,Boolean>(); |
41 | |
|
42 | |
private Map<ResourceDependency, Boolean> addedResources; |
43 | |
|
44 | |
private Map<Class<?>, Boolean> initialProcessedClasses; |
45 | |
private Map<ResourceDependency, Boolean> initialAddedResources; |
46 | |
|
47 | |
public RequestViewMetadata() |
48 | 0 | { |
49 | 0 | initialProcessedClasses = null; |
50 | 0 | initialAddedResources = null; |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public RequestViewMetadata cloneInstance() |
60 | |
{ |
61 | 0 | RequestViewMetadata rvm = new RequestViewMetadata(); |
62 | 0 | rvm.initialProcessedClasses = new HashMap<Class<?>, Boolean>( |
63 | |
this.initialProcessedClasses != null ? |
64 | |
this.initialProcessedClasses : this.processedClasses); |
65 | 0 | if (this.initialAddedResources != null) |
66 | |
{ |
67 | 0 | rvm.initialAddedResources = new HashMap<ResourceDependency, Boolean>( |
68 | |
this.initialAddedResources); |
69 | |
} |
70 | 0 | else if (this.addedResources != null) |
71 | |
{ |
72 | 0 | rvm.initialAddedResources = new HashMap<ResourceDependency, Boolean>( |
73 | |
this.addedResources); |
74 | |
} |
75 | 0 | return rvm; |
76 | |
} |
77 | |
|
78 | |
public boolean isResourceDependencyAlreadyProcessed(ResourceDependency dependency) |
79 | |
{ |
80 | 0 | if (initialAddedResources != null) |
81 | |
{ |
82 | 0 | if (initialAddedResources.containsKey(dependency)) |
83 | |
{ |
84 | 0 | return true; |
85 | |
} |
86 | |
} |
87 | 0 | if (addedResources == null) |
88 | |
{ |
89 | 0 | return false; |
90 | |
} |
91 | 0 | return addedResources.containsKey(dependency); |
92 | |
} |
93 | |
|
94 | |
public void setResourceDependencyAsProcessed(ResourceDependency dependency) |
95 | |
{ |
96 | 0 | if (addedResources == null) |
97 | |
{ |
98 | 0 | addedResources = new HashMap<ResourceDependency,Boolean>(); |
99 | |
} |
100 | 0 | addedResources.put(dependency, true); |
101 | 0 | } |
102 | |
|
103 | |
public boolean isClassAlreadyProcessed(Class<?> inspectedClass) |
104 | |
{ |
105 | 0 | if (initialProcessedClasses != null) |
106 | |
{ |
107 | 0 | if (initialProcessedClasses.containsKey(inspectedClass)) |
108 | |
{ |
109 | 0 | return true; |
110 | |
} |
111 | |
} |
112 | 0 | return processedClasses.containsKey(inspectedClass); |
113 | |
} |
114 | |
|
115 | |
public void setClassProcessed(Class<?> inspectedClass) |
116 | |
{ |
117 | 0 | processedClasses.put(inspectedClass, Boolean.TRUE); |
118 | 0 | } |
119 | |
|
120 | |
public Map<String, List<ResourceDependency>> getResourceDependencyAnnotations(FacesContext context) |
121 | |
{ |
122 | 0 | if (initialAddedResources == null && addedResources == null) |
123 | |
{ |
124 | 0 | return Collections.emptyMap(); |
125 | |
} |
126 | 0 | Map<String, List<ResourceDependency>> map = new HashMap<String, List<ResourceDependency>>(); |
127 | |
|
128 | 0 | if (initialAddedResources != null) |
129 | |
{ |
130 | 0 | for (ResourceDependency annotation : initialAddedResources.keySet()) |
131 | |
{ |
132 | 0 | String target = annotation.target(); |
133 | 0 | if (target != null && target.length() > 0) |
134 | |
{ |
135 | 0 | target = ELText.parse(context.getApplication().getExpressionFactory(), |
136 | |
context.getELContext(), target).toString(context.getELContext()); |
137 | |
} |
138 | |
else |
139 | |
{ |
140 | 0 | target = "head"; |
141 | |
} |
142 | 0 | List<ResourceDependency> list = map.get(target); |
143 | 0 | if (list == null) |
144 | |
{ |
145 | 0 | list = new ArrayList<ResourceDependency>(); |
146 | 0 | map.put(target, list); |
147 | |
} |
148 | 0 | list.add(annotation); |
149 | 0 | } |
150 | |
} |
151 | 0 | if (addedResources != null) |
152 | |
{ |
153 | 0 | for (ResourceDependency annotation : addedResources.keySet()) |
154 | |
{ |
155 | 0 | String target = annotation.target(); |
156 | 0 | if (target != null && target.length() > 0) |
157 | |
{ |
158 | 0 | target = ELText.parse(context.getApplication().getExpressionFactory(), |
159 | |
context.getELContext(), target).toString(context.getELContext()); |
160 | |
} |
161 | |
else |
162 | |
{ |
163 | 0 | target = "head"; |
164 | |
} |
165 | 0 | List<ResourceDependency> list = map.get(target); |
166 | 0 | if (list == null) |
167 | |
{ |
168 | 0 | list = new ArrayList<ResourceDependency>(); |
169 | 0 | map.put(target, list); |
170 | |
} |
171 | 0 | list.add(annotation); |
172 | 0 | } |
173 | |
} |
174 | 0 | return map; |
175 | |
} |
176 | |
} |