Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ClayTag |
|
| 1.6666666666666667;1.667 |
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | ||
18 | /* |
|
19 | * $Id: ClayTag.java 464373 2006-10-16 04:21:54Z rahul $ |
|
20 | */ |
|
21 | package org.apache.shale.clay.taglib; |
|
22 | ||
23 | import javax.faces.component.UIComponent; |
|
24 | import javax.faces.context.FacesContext; |
|
25 | import javax.faces.el.ValueBinding; |
|
26 | import javax.faces.webapp.UIComponentBodyTag; |
|
27 | ||
28 | import org.apache.shale.clay.component.Clay; |
|
29 | ||
30 | /** |
|
31 | * <p>JSP Tag for the {@link org.apache.shale.clay.component.Clay} component.</p> |
|
32 | * |
|
33 | */ |
|
34 | 0 | public class ClayTag extends UIComponentBodyTag { |
35 | ||
36 | /** |
|
37 | * <p>Represents the meta-component to build the subtree on.</p> |
|
38 | */ |
|
39 | 0 | private String jsfid = null; |
40 | ||
41 | /** |
|
42 | * <p>The name of the managed bean instance in the faces configuration file that |
|
43 | * should be bound to this view composition. The literal "@managed-bean-name" |
|
44 | * in the component metadata will be replaced with this value before the |
|
45 | * binding of the expression is created. |
|
46 | * </p> |
|
47 | */ |
|
48 | 0 | private String managedBeanName = null; |
49 | ||
50 | /** |
|
51 | * <p>A method event that conforms to the standard <code>validator</code> |
|
52 | * attribute. This event will get fired before the sub component tree is |
|
53 | * build. |
|
54 | * </p> |
|
55 | */ |
|
56 | 0 | private String shapeValidator = null; |
57 | ||
58 | /** |
|
59 | * <p>Returns the expression literal defining the validator event method |
|
60 | * binding. |
|
61 | * </p> |
|
62 | * |
|
63 | * @return method binding expression |
|
64 | */ |
|
65 | public String getShapeValidator() { |
|
66 | 0 | return shapeValidator; |
67 | } |
|
68 | ||
69 | /** |
|
70 | * <p>Sets the expression literal defining the validator event method binding. |
|
71 | * </p> |
|
72 | * |
|
73 | * @param shapeValidator <code>String</code> validator binding expression |
|
74 | */ |
|
75 | public void setShapeValidator(String shapeValidator) { |
|
76 | 0 | this.shapeValidator = shapeValidator; |
77 | 0 | } |
78 | ||
79 | ||
80 | /** |
|
81 | * <p>Gets the display Element identifier to be rendered.</p> |
|
82 | * |
|
83 | * @return jsfid |
|
84 | */ |
|
85 | public String getJsfid() { |
|
86 | 0 | return jsfid; |
87 | } |
|
88 | ||
89 | /** |
|
90 | * <p>Sets the identifier defining component metadata. |
|
91 | * </p> |
|
92 | * |
|
93 | * @param jsfid <code>String</code> sets the component element to be rendered |
|
94 | */ |
|
95 | public void setJsfid(String jsfid) { |
|
96 | 0 | this.jsfid = jsfid; |
97 | 0 | } |
98 | ||
99 | /** |
|
100 | * <p>Gets the name of the managed bean that is dynamically resolved |
|
101 | * using a token replacement before binding the value expression. |
|
102 | * If not explicitly set, it will default to the literal <code>UNKNOWN</code> |
|
103 | * </p> |
|
104 | * |
|
105 | * @return managed bean name symbol |
|
106 | */ |
|
107 | public String getManagedBeanName() { |
|
108 | 0 | if (managedBeanName == null || managedBeanName.length() == 0) { |
109 | 0 | return "UNKNOWN"; |
110 | } |
|
111 | ||
112 | 0 | return managedBeanName; |
113 | } |
|
114 | ||
115 | /** |
|
116 | * <p> Name of the managed bean that is dynamically resolved. The literal |
|
117 | * string "managed-bean-name" is replaced with the value of this |
|
118 | * property. |
|
119 | * </p> |
|
120 | * |
|
121 | * @param managedBeanName <code>String</code> |
|
122 | */ |
|
123 | public void setManagedBeanName(String managedBeanName) { |
|
124 | 0 | this.managedBeanName = managedBeanName; |
125 | 0 | } |
126 | ||
127 | ||
128 | /** |
|
129 | * <p> Returns the logical component name registered in the faces config |
|
130 | * for the {@link org.apache.shale.clay.component.Clay} component. |
|
131 | * </p> |
|
132 | * |
|
133 | * @return component type |
|
134 | * @see javax.faces.webapp.UIComponentTag#getComponentType() |
|
135 | */ |
|
136 | public String getComponentType() { |
|
137 | 0 | return "org.apache.shale.clay.component.Clay"; |
138 | } |
|
139 | ||
140 | /** |
|
141 | * <p>Returns the render registered for the component. The |
|
142 | * {@link org.apache.shale.clay.component.Clay} component doesn't |
|
143 | * have a render because the component invokes the rendering of |
|
144 | * it's children. |
|
145 | * </p> |
|
146 | * |
|
147 | * @return <code>null</code> |
|
148 | * @see javax.faces.webapp.UIComponentTag#getRendererType() |
|
149 | */ |
|
150 | public String getRendererType() { |
|
151 | 0 | return null; |
152 | } |
|
153 | ||
154 | /** |
|
155 | * <p>This method is invoked by the super and its purpose it |
|
156 | * to push tag attributes to corresponding component property |
|
157 | * values. |
|
158 | * </p> |
|
159 | * |
|
160 | * @param component {@link UIComponent} instance of {@link org.apache.shale.clay.component.Clay} |
|
161 | */ |
|
162 | protected void setProperties(UIComponent component) { |
|
163 | 0 | super.setProperties(component); |
164 | ||
165 | 0 | Clay c = (Clay) component; |
166 | 0 | FacesContext facesContext = getFacesContext(); |
167 | ||
168 | 0 | if (getJsfid() != null) { |
169 | ||
170 | 0 | c.setJsfid(getJsfid()); |
171 | ||
172 | } |
|
173 | ||
174 | ||
175 | 0 | if (getManagedBeanName() != null) { |
176 | 0 | c.setManagedBeanName(getManagedBeanName()); |
177 | ||
178 | 0 | if (isValueReference(getManagedBeanName())) { |
179 | 0 | ValueBinding valueBinding = facesContext.getApplication().createValueBinding(getManagedBeanName()); |
180 | 0 | Object value = valueBinding.getValue(facesContext); |
181 | 0 | c.setManagedBeanName((value != null) ? value.toString() : null); |
182 | ||
183 | 0 | } else { |
184 | 0 | c.setManagedBeanName(getManagedBeanName()); |
185 | } |
|
186 | ||
187 | } |
|
188 | ||
189 | ||
190 | 0 | if (getShapeValidator() != null) { |
191 | 0 | c.setShapeValidator(getShapeValidator()); |
192 | } |
|
193 | ||
194 | 0 | } |
195 | } |