1 /*
2 * $Id: TemplateParameter.java 1349964 2012-06-13 17:18:51Z nlebas $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 package org.apache.tiles.autotag.model;
22
23 import org.apache.tiles.autotag.core.runtime.ModelBody;
24
25 /**
26 * It represents a parameter in a method in a parsed template class.
27 *
28 * @version $Rev: 1349964 $ $Date: 2012-06-13 19:18:51 +0200 (Wed, 13 Jun 2012) $
29 */
30 public class TemplateParameter {
31
32 /**
33 * The name of the parameter.
34 */
35 private String name;
36
37 /**
38 * The exported name, i.e. the name of the parameter in created code. Usually
39 * helpful if this exported name is a reserved word.
40 */
41 private String exportedName;
42
43 /**
44 * The parameter documentation.
45 */
46 private String documentation;
47
48 /**
49 * The type of the parameter.
50 */
51 private String type;
52
53 /**
54 * The default value, as it will be written in Java code.
55 */
56 private String defaultValue;
57
58 /**
59 * Indicates that this parameter is required.
60 */
61 private boolean required;
62
63 /**
64 * Indicates that this parameter is the request.
65 */
66 private boolean request;
67
68 /**
69 * Constructor.
70 *
71 * @param name The name of the parameter.
72 * @param exportedName The exported name, i.e. the name of the parameter in created code. Usually
73 * helpful if this exported name is a reserved word.
74 * @param type The type of the parameter.
75 * @param defaultValue The default value, as it will be written in Java code.
76 * @param required Indicates that this parameter is required.
77 */
78 public TemplateParameter(String name, String exportedName, String type, String defaultValue, boolean required, boolean request) {
79 this.name = name;
80 this.exportedName = exportedName;
81 this.type = type;
82 this.defaultValue = defaultValue;
83 this.required = required;
84 this.request = request;
85 }
86
87 /**
88 * Returns the documentation for this parameter.
89 *
90 * @return The documentation.
91 */
92 public String getDocumentation() {
93 return documentation;
94 }
95
96 /**
97 * Sets the documentation for this parameter.
98 *
99 * @param documentation The documentation.
100 */
101 public void setDocumentation(String documentation) {
102 this.documentation = documentation;
103 }
104
105 /**
106 * Returns the name of the parameter.
107 *
108 * @return The name of the parameter.
109 */
110 public String getName() {
111 return name;
112 }
113
114 /**
115 * Returns the exported name, i.e. the name of the parameter in created code. Usually
116 * helpful if this exported name is a reserved word.
117 *
118 * @return The exported name.
119 */
120 public String getExportedName() {
121 return exportedName;
122 }
123
124 /**
125 * Returns the type of the parameter.
126 *
127 * @return The type.
128 */
129 public String getType() {
130 return type;
131 }
132
133 /**
134 * Returns the default value, as it will be written in Java code.
135 *
136 * @return The default value.
137 */
138 public String getDefaultValue() {
139 return defaultValue;
140 }
141
142 /**
143 * Indicates that this parameter is required.
144 *
145 * @return <code>true</code> if the parameter is required.
146 */
147 public boolean isRequired() {
148 return required;
149 }
150
151 /**
152 * Indicates that this parameter implements {@link ModelBody}.
153 *
154 * @return <code>true</code> if the parameter is a body.
155 */
156 public boolean isBody() {
157 return ModelBody.class.getName().equals(type);
158 }
159
160 /**
161 * Indicates that this parameter implements {@link Request}.
162 *
163 * @return <code>true</code> if the parameter is a request.
164 */
165 public boolean isRequest() {
166 return request;
167 }
168
169 /**
170 * Returns the suffix for getter and setter of the property generated by
171 * this parameter.
172 *
173 * @return The getter and setter suffix.
174 */
175 public String getGetterSetterSuffix() {
176 return exportedName.substring(0, 1).toUpperCase() + exportedName.substring(1);
177 }
178
179 @Override
180 public String toString() {
181 return "TemplateParameter [name=" + name + ", exportedName="
182 + exportedName + ", documentation=" + documentation + ", type="
183 + type + ", defaultValue=" + defaultValue + ", required="
184 + required + ", request=" + request + "]";
185 }
186 }