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.util.HashMap;
22 import java.util.Map;
23
24 import javax.faces.application.ResourceDependency;
25 import javax.faces.component.UIViewRoot;
26 import javax.faces.context.FacesContext;
27
28
29
30
31
32
33
34 public class RequestViewContext
35 {
36
37 public static final String VIEW_CONTEXT_KEY = "oam.VIEW_CONTEXT";
38
39 private Map<ResourceDependency, Boolean> addedResources;
40
41
42 private Map<Class<?>, Boolean> processedClasses = new HashMap<Class<?>,Boolean>();
43
44 private Map<String, Boolean> renderTargetMap = null;
45
46 static public RequestViewContext getCurrentInstance()
47 {
48 FacesContext ctx = FacesContext.getCurrentInstance();
49 return getCurrentInstance(ctx);
50 }
51
52 static public RequestViewContext getCurrentInstance(FacesContext ctx)
53 {
54 return getCurrentInstance(ctx, ctx.getViewRoot());
55 }
56
57 @SuppressWarnings("unchecked")
58 static public RequestViewContext getCurrentInstance(FacesContext ctx, UIViewRoot root)
59 {
60 Map<UIViewRoot, RequestViewContext> map
61 = (Map<UIViewRoot, RequestViewContext>) ctx.getAttributes().get(VIEW_CONTEXT_KEY);
62 RequestViewContext rvc = null;
63 if (map == null)
64 {
65 map = new HashMap<UIViewRoot, RequestViewContext>();
66 rvc = new RequestViewContext();
67 map.put(root, rvc);
68 ctx.getAttributes().put(VIEW_CONTEXT_KEY, map);
69 return rvc;
70 }
71 else
72 {
73 rvc = map.get(root);
74 if (rvc == null)
75 {
76 rvc = new RequestViewContext();
77 map.put(root, rvc);
78 }
79 return rvc;
80 }
81 }
82
83 public boolean isResourceDependencyAlreadyProcessed(ResourceDependency dependency)
84 {
85 if (addedResources == null)
86 {
87 return false;
88 }
89 return addedResources.containsKey(dependency);
90 }
91
92 public void setResourceDependencyAsProcessed(ResourceDependency dependency)
93 {
94 if (addedResources == null)
95 {
96 addedResources = new HashMap<ResourceDependency,Boolean>();
97 }
98 addedResources.put(dependency, true);
99 }
100
101 public boolean isClassAlreadyProcessed(Class<?> inspectedClass)
102 {
103 return processedClasses.containsKey(inspectedClass);
104 }
105
106 public void setClassProcessed(Class<?> inspectedClass)
107 {
108 processedClasses.put(inspectedClass, Boolean.TRUE);
109 }
110
111 public boolean isRenderTarget(String target)
112 {
113 if (renderTargetMap != null)
114 {
115 return Boolean.TRUE.equals(renderTargetMap.get(target));
116 }
117 return false;
118 }
119
120 public void setRenderTarget(String target, boolean value)
121 {
122 if (renderTargetMap == null)
123 {
124 renderTargetMap = new HashMap<String, Boolean>(8);
125 }
126 renderTargetMap.put(target, value);
127 }
128 }