1/*2 * $Id: TemplateMethod.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 method in a parsed template class.29 *30 * @version $Rev: 1044707 $ $Date: 2010-12-11 21:35:57 +0100 (Sat, 11 Dec 2010) $31 */32publicclassTemplateMethod {
3334/**35 * The name of the method.36 */37private String name;
3839/**40 * Documentation about the method.41 */42private String documentation;
4344/**45 * The map of parameters.46 */47private Map<String, TemplateParameter> parameters;
4849/**50 * Constructor.51 *52 * @param name The name of the method.53 * @param parameters The map of parameters.54 */55publicTemplateMethod(String name,
56 Iterable<? extends TemplateParameter> parameters) {
57this.name = name;
58this.parameters = new LinkedHashMap<String, TemplateParameter>();
59for (TemplateParameter parameter : parameters) {
60this.parameters.put(parameter.getName(), parameter);
61 }
62 }
6364/**65 * Returns the name of the method.66 *67 * @return The name of the method.68 */69public String getName() {
70return name;
71 }
7273/**74 * Returns the documentation for this method.75 *76 * @return The documentation.77 */78public String getDocumentation() {
79return documentation;
80 }
8182/**83 * Sets the documentation for this method.84 *85 * @param documentation The documentation.86 */87publicvoid setDocumentation(String documentation) {
88this.documentation = documentation;
89 }
9091/**92 * Returns the parameters of this method.93 *94 * @return The parameters.95 */96public Collection<TemplateParameter> getParameters() {
97return parameters.values();
98 }
99100/**101 * Returns a parameter given its name.102 *103 * @param name The name of the parameter.104 * @return The parameter.105 */106publicTemplateParameter getParameterByName(String name) {
107return parameters.get(name);
108 }
109110/**111 * Indicates that this method needs a tag body.112 *113 * @return <code>true</code> if tag body is needed.114 */115publicboolean hasBody() {
116if (parameters.size() >= 2) {
117for (TemplateParameter param : parameters.values()) {
118if (param.isBody()) {
119returntrue;
120 }
121 }
122 }
123return false;
124 }
125126 @Override
127public String toString() {
128return"TemplateMethod [name=" + name + ", documentation="129 + documentation + ", parameters=" + parameters + "]";
130 }
131 }