1
2
3
4
5 package org.rcfaces.core.internal.taglib;
6
7 import javax.el.ValueExpression;
8 import javax.faces.component.UIComponent;
9 import javax.faces.context.FacesContext;
10 import javax.faces.webapp.UIComponentELTag;
11 import javax.servlet.jsp.JspException;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.rcfaces.core.internal.capability.IComponentLifeCycle;
16 import org.rcfaces.core.internal.capability.IRCFacesComponent;
17
18
19
20
21
22 public abstract class CameliaTag extends UIComponentELTag {
23 private static final String REVISION = "$Revision: 1.17 $";
24
25 private static final Log LOG = LogFactory.getLog(CameliaTag.class);
26
27 private static final boolean debugEnabled = LOG.isDebugEnabled();
28
29 private ValueExpression myBinding;
30
31 protected static final boolean getBool(String value) {
32 return Boolean.valueOf(value).booleanValue();
33 }
34
35 protected static final Boolean getBoolean(String value) {
36 if (value == null) {
37 return null;
38 }
39
40 return Boolean.valueOf(value);
41 }
42
43 protected static final Integer getInteger(String value) {
44 if (value == null) {
45 return null;
46 }
47
48 return Integer.valueOf(value);
49 }
50
51 protected static final int getInt(String value) {
52 return Integer.parseInt(value);
53 }
54
55 protected static final double getDouble(String value) {
56 return Double.parseDouble(value);
57 }
58
59 public void release() {
60 myBinding = null;
61 super.release();
62 }
63
64 public String getRendererType() {
65 return null;
66 }
67
68 public int doAfterBody() throws JspException {
69 try {
70 return super.doAfterBody();
71
72 } catch (RuntimeException ex) {
73 LOG.error("Can not doAfterBody component '" + getId() + "'.", ex);
74
75 throw ex;
76 }
77 }
78
79 public int doEndTag() throws JspException {
80 try {
81 return super.doEndTag();
82
83 } catch (RuntimeException ex) {
84 LOG.error("Can not doEndTag component '" + getId() + "'.", ex);
85
86 throw ex;
87 }
88 }
89
90 public void doInitBody() throws JspException {
91 try {
92 super.doInitBody();
93
94 } catch (RuntimeException ex) {
95 LOG.error("Can not doInitBody component '" + getId() + "'.", ex);
96
97 throw ex;
98 }
99
100 }
101
102 public int doStartTag() throws JspException {
103 try {
104 return super.doStartTag();
105
106 } catch (RuntimeException ex) {
107 LOG.error("Can not doStartTag component '" + getId() + "'.", ex);
108
109 throw ex;
110 }
111 }
112
113 protected void setProperties(UIComponent component) {
114
115 if (myBinding == null) {
116 if (component instanceof IComponentLifeCycle) {
117 IComponentLifeCycle componentLifeCycle = (IComponentLifeCycle) component;
118
119 componentLifeCycle.initializePhase(getFacesContext(), false);
120 }
121
122 if (debugEnabled) {
123 LOG.debug("Create component for id '" + getId() + "' returns '"
124 + component + "'.");
125 }
126 super.setProperties(component);
127 return;
128 }
129
130 Object bindingValue = myBinding.getValue(getELContext());
131
132 if (component instanceof IComponentLifeCycle) {
133 IComponentLifeCycle componentLifeCycle = (IComponentLifeCycle) component;
134
135 componentLifeCycle.initializePhase(getFacesContext(),
136 bindingValue != null);
137 }
138
139 if (debugEnabled) {
140 LOG.debug("Create component for id '" + getId() + "' returns '"
141 + component + "'.");
142 }
143
144 super.setProperties(component);
145 }
146
147 public void setBinding(ValueExpression binding) throws JspException {
148 this.myBinding = binding;
149
150 super.setBinding(binding);
151 }
152
153 protected UIComponent findComponent(FacesContext context)
154 throws JspException {
155
156 if (debugEnabled) {
157 LOG.debug("Find component '" + getId() + "' ... (current="
158 + getComponentInstance() + ")");
159 }
160
161 UIComponent component = super.findComponent(context);
162
163 if (debugEnabled) {
164 LOG.debug("Find component '" + getId() + "' returns '" + component
165 + "'");
166 }
167
168 return component;
169 }
170
171 }