Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ParameterSpecification |
|
| 1.0555555555555556;1.056 |
1 | // Copyright 2004, 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.spec; | |
16 | ||
17 | import java.util.Arrays; | |
18 | import java.util.Collection; | |
19 | import java.util.Collections; | |
20 | ||
21 | import org.apache.hivemind.HiveMind; | |
22 | import org.apache.hivemind.impl.BaseLocatable; | |
23 | import org.apache.hivemind.util.Defense; | |
24 | import org.apache.tapestry.TapestryUtils; | |
25 | ||
26 | /** | |
27 | * Defines a formal parameter to a component. A | |
28 | * <code>IParameterSpecification</code> is contained by a | |
29 | * {@link IComponentSpecification}. | |
30 | * <p> | |
31 | * TBD: Identify arrays in some way. | |
32 | * | |
33 | * @author Howard Lewis Ship | |
34 | */ | |
35 | ||
36 | 0 | public class ParameterSpecification extends BaseLocatable implements |
37 | IParameterSpecification | |
38 | { | |
39 | ||
40 | 0 | private boolean _required = false; |
41 | ||
42 | private String _type; | |
43 | ||
44 | /** @since 1.0.9 */ | |
45 | private String _description; | |
46 | ||
47 | /** @since 2.0.3 */ | |
48 | private String _propertyName; | |
49 | ||
50 | /** @since 3.0 */ | |
51 | private String _defaultValue; | |
52 | ||
53 | /** @since 4.0 */ | |
54 | 0 | private boolean _cache = true; |
55 | ||
56 | /** @since 4.0 */ | |
57 | 0 | private Collection _aliasNames = Collections.EMPTY_LIST; |
58 | ||
59 | /** @since 4.0 */ | |
60 | private String _parameterName; | |
61 | ||
62 | /** @since 4.0 */ | |
63 | 0 | private boolean _deprecated = false; |
64 | ||
65 | /** | |
66 | * Returns the class name of the expected type of the parameter. The default | |
67 | * value is <code>java.lang.Object</code> which matches anything. | |
68 | */ | |
69 | ||
70 | public String getType() | |
71 | { | |
72 | 0 | return _type; |
73 | } | |
74 | ||
75 | /** | |
76 | * Returns true if the parameter is required by the component. The default | |
77 | * is false, meaning the parameter is optional. | |
78 | */ | |
79 | ||
80 | public boolean isRequired() | |
81 | { | |
82 | 0 | return _required; |
83 | } | |
84 | ||
85 | public void setRequired(boolean value) | |
86 | { | |
87 | 0 | _required = value; |
88 | 0 | } |
89 | ||
90 | /** | |
91 | * Sets the type of value expected for the parameter. This can be left blank | |
92 | * to indicate any type. | |
93 | */ | |
94 | ||
95 | public void setType(String value) | |
96 | { | |
97 | 0 | _type = value; |
98 | 0 | } |
99 | ||
100 | /** | |
101 | * Returns the documentation for this parameter. | |
102 | * | |
103 | * @since 1.0.9 | |
104 | */ | |
105 | ||
106 | public String getDescription() | |
107 | { | |
108 | 0 | return _description; |
109 | } | |
110 | ||
111 | /** | |
112 | * Sets the documentation for this parameter. | |
113 | * | |
114 | * @since 1.0.9 | |
115 | */ | |
116 | ||
117 | public void setDescription(String description) | |
118 | { | |
119 | 0 | _description = description; |
120 | 0 | } |
121 | ||
122 | /** | |
123 | * Sets the property name (of the component class) to connect the parameter | |
124 | * to. | |
125 | */ | |
126 | ||
127 | public void setPropertyName(String propertyName) | |
128 | { | |
129 | 0 | _propertyName = propertyName; |
130 | 0 | } |
131 | ||
132 | /** | |
133 | * Returns the name of the JavaBeans property to connect the parameter to. | |
134 | */ | |
135 | ||
136 | public String getPropertyName() | |
137 | { | |
138 | 0 | return _propertyName; |
139 | } | |
140 | ||
141 | /** | |
142 | * @see org.apache.tapestry.spec.IParameterSpecification#getDefaultValue() | |
143 | */ | |
144 | public String getDefaultValue() | |
145 | { | |
146 | 0 | return _defaultValue; |
147 | } | |
148 | ||
149 | /** | |
150 | * @see org.apache.tapestry.spec.IParameterSpecification#setDefaultValue(java.lang.String) | |
151 | */ | |
152 | public void setDefaultValue(String defaultValue) | |
153 | { | |
154 | 0 | _defaultValue = defaultValue; |
155 | 0 | } |
156 | ||
157 | /** @since 4.0 */ | |
158 | public boolean getCache() | |
159 | { | |
160 | 0 | return _cache; |
161 | } | |
162 | ||
163 | /** @since 4.0 */ | |
164 | public void setCache(boolean cache) | |
165 | { | |
166 | 0 | _cache = cache; |
167 | 0 | } |
168 | ||
169 | /** @since 4.0 */ | |
170 | public Collection getAliasNames() | |
171 | { | |
172 | 0 | return _aliasNames; |
173 | } | |
174 | ||
175 | /** @since 4.0 */ | |
176 | public String getParameterName() | |
177 | { | |
178 | 0 | return _parameterName; |
179 | } | |
180 | ||
181 | /** @since 4.0 */ | |
182 | public void setAliases(String nameList) | |
183 | { | |
184 | 0 | if (HiveMind.isNonBlank(nameList)) |
185 | { | |
186 | 0 | String[] names = TapestryUtils.split(nameList); |
187 | ||
188 | 0 | _aliasNames = Arrays.asList(names); |
189 | } | |
190 | 0 | } |
191 | ||
192 | /** @since 4.0 */ | |
193 | public void setParameterName(String name) | |
194 | { | |
195 | 0 | Defense.notNull(name, "name"); |
196 | ||
197 | 0 | _parameterName = name; |
198 | 0 | } |
199 | ||
200 | /** @since 4.0 */ | |
201 | public boolean isDeprecated() | |
202 | { | |
203 | 0 | return _deprecated; |
204 | } | |
205 | ||
206 | /** @since 4.0 */ | |
207 | public void setDeprecated(boolean deprecated) | |
208 | { | |
209 | 0 | _deprecated = deprecated; |
210 | 0 | } |
211 | ||
212 | } |