1/*2 * $Id: TemplateClass.java 1044707 2010-12-11 20:35:57Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */21package org.apache.tiles.autotag.model;
2223import java.util.Collection;
24import java.util.LinkedHashMap;
25import java.util.Map;
2627/**28 * It represents a parsed template class.29 *30 * @version $Rev: 1044707 $ $Date: 2010-12-11 21:35:57 +0100 (Sat, 11 Dec 2010) $31 */32publicclassTemplateClass {
3334/**35 * The class name.36 */37private String name;
3839/**40 * The name of the tag.41 */42private String tagName;
4344/**45 * The prefix of the tag class.46 */47private String tagClassPrefix;
4849/**50 * Documentation about this tag.51 */52private String documentation;
5354/**55 * The method that executes the template class.56 */57privateTemplateMethod executeMethod;
5859/**60 * Constructor.61 *62 * @param name The name of the template class.63 */64publicTemplateClass(String name) {
65this(name, null, null, null);
66 }
6768/**69 * Constructor.70 *71 * @param name The name of the template class.72 * @param tagName The name of the tag.73 * @param tagClassPrefix The tag class prefix.74 * @param executeMethod The method that executes the template class.75 */76publicTemplateClass(String name, String tagName, String tagClassPrefix,
77TemplateMethod executeMethod) {
78this.name = name;
79this.tagName = tagName;
80this.tagClassPrefix = tagClassPrefix;
81this.executeMethod = executeMethod;
82 }
8384/**85 * The name of the parsed class.86 *87 * @return The name of the class.88 */89public String getName() {
90return name;
91 }
9293/**94 * Returns the name of the class, without the package part.95 *96 * @return The simple class name.97 */98public String getSimpleName() {
99int pos = name.lastIndexOf('.');
100if (pos >= 0) {
101return name.substring(pos + 1);
102 }
103return name;
104 }
105106/**107 * Returns the tag name.108 *109 * @return The tag name.110 */111public String getTagName() {
112return tagName;
113 }
114115/**116 * Returns the tag class prefix.117 *118 * @return The tag class prefix.119 */120public String getTagClassPrefix() {
121return tagClassPrefix;
122 }
123124/**125 * Returns the documentation for this class.126 *127 * @return The documentation.128 */129public String getDocumentation() {
130return documentation;
131 }
132133/**134 * Sets the documentation for this class.135 *136 * @param documentation The documentation.137 */138publicvoid setDocumentation(String documentation) {
139this.documentation = documentation;
140 }
141142/**143 * Returns the method that execute this class.144 *145 * @return The execute method.146 */147publicTemplateMethod getExecuteMethod() {
148return executeMethod;
149 }
150151/**152 * Returns the collection of regular parameters (no request, no body)153 * of the execute method.154 *155 * @return The regular parameters.156 */157public Collection<TemplateParameter> getParameters() {
158 Map<String, TemplateParameter> params = new LinkedHashMap<String, TemplateParameter>();
159 fillRegularParameters(params, executeMethod);
160return params.values();
161 }
162163/**164 * Indicates that this class needs a tag body.165 *166 * @return <code>true</code> if tag body is needed.167 */168publicboolean hasBody() {
169return executeMethod.hasBody();
170 }
171172 @Override
173public String toString() {
174return"TemplateClass [name=" + name + ", tagName=" + tagName
175 + ", tagClassPrefix=" + tagClassPrefix + ", documentation="176 + documentation + ", executeMethod=" + executeMethod + "]";
177 }
178179/**180 * Creates regular parameters map.181 *182 * @param params The map to fill.183 * @param method The method to analyze.184 */185privatevoid fillRegularParameters(Map<String, TemplateParameter> params,
186TemplateMethod method) {
187if (method != null) {
188for (TemplateParameter param : method.getParameters()) {
189if (!param.isRequest() && !param.isBody()) {
190 params.put(param.getName(), param);
191 }
192 }
193 }
194 }
195 }