1
2
3
4 package org.rcfaces.core.internal.renderkit;
5
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import javax.faces.component.UIComponent;
10 import javax.faces.context.FacesContext;
11
12 import org.rcfaces.core.internal.manager.ITransientAttributesManager;
13
14
15
16
17
18 public abstract class AbstractComponentRenderContext implements
19 IComponentRenderContext {
20 private static final String REVISION = "$Revision: 1.18 $";
21
22 private static final String ATTRIBUTES_MAP = "org.rcfaces.core.RENDER_CONTEXT_ATTRIBUTES";
23
24 private static final boolean PUT_ATTRIBUTES_MAP_INTO_COMPONENT = false;
25
26 private final UIComponent component;
27
28 private final String componentClientId;
29
30 private FacesContext facesContext;
31
32 private Map attributes;
33
34 private boolean componentVisible = true;
35
36 protected AbstractComponentRenderContext(FacesContext facesContext,
37 UIComponent component, String componentClientId) {
38 this.facesContext = facesContext;
39 this.component = component;
40 this.componentClientId = componentClientId;
41
42 if (PUT_ATTRIBUTES_MAP_INTO_COMPONENT) {
43 if (component instanceof ITransientAttributesManager) {
44 attributes = (Map) ((ITransientAttributesManager) component)
45 .getTransientAttribute(ATTRIBUTES_MAP);
46 }
47 }
48 }
49
50 public final FacesContext getFacesContext() {
51 if (facesContext == null) {
52 facesContext = FacesContext.getCurrentInstance();
53 }
54 return facesContext;
55 }
56
57 public final UIComponent getComponent() {
58 return component;
59 }
60
61 public final String getComponentClientId() {
62 return componentClientId;
63 }
64
65 public Object getAttribute(String key) {
66 if (attributes == null) {
67 return null;
68 }
69
70 return attributes.get(key);
71 }
72
73 public boolean containsAttribute(String key) {
74 if (attributes == null) {
75 return false;
76 }
77
78 return attributes.containsKey(key);
79 }
80
81 public Object setAttribute(String key, Object value) {
82 if (attributes == null) {
83 attributes = new HashMap();
84
85 if (PUT_ATTRIBUTES_MAP_INTO_COMPONENT) {
86 if (component instanceof ITransientAttributesManager) {
87 ((ITransientAttributesManager) component)
88 .setTransientAttribute(ATTRIBUTES_MAP, attributes);
89 }
90 }
91 }
92
93 return attributes.put(key, value);
94 }
95
96 public Object removeAttribute(String key) {
97 if (attributes == null) {
98 return null;
99 }
100
101 return attributes.remove(key);
102 }
103
104 public boolean isComponentVisible() {
105 return componentVisible;
106 }
107
108 public void setComponentHidden() {
109 componentVisible = false;
110 }
111 }