1 /* 2 * $Id: TemplateMethod.java 1044707 2010-12-11 20:35:57Z apetrelli $ 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 java.util.Collection; 24 import java.util.LinkedHashMap; 25 import java.util.Map; 26 27 /** 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 */ 32 public class TemplateMethod { 33 34 /** 35 * The name of the method. 36 */ 37 private String name; 38 39 /** 40 * Documentation about the method. 41 */ 42 private String documentation; 43 44 /** 45 * The map of parameters. 46 */ 47 private Map<String, TemplateParameter> parameters; 48 49 /** 50 * Constructor. 51 * 52 * @param name The name of the method. 53 * @param parameters The map of parameters. 54 */ 55 public TemplateMethod(String name, 56 Iterable<? extends TemplateParameter> parameters) { 57 this.name = name; 58 this.parameters = new LinkedHashMap<String, TemplateParameter>(); 59 for (TemplateParameter parameter : parameters) { 60 this.parameters.put(parameter.getName(), parameter); 61 } 62 } 63 64 /** 65 * Returns the name of the method. 66 * 67 * @return The name of the method. 68 */ 69 public String getName() { 70 return name; 71 } 72 73 /** 74 * Returns the documentation for this method. 75 * 76 * @return The documentation. 77 */ 78 public String getDocumentation() { 79 return documentation; 80 } 81 82 /** 83 * Sets the documentation for this method. 84 * 85 * @param documentation The documentation. 86 */ 87 public void setDocumentation(String documentation) { 88 this.documentation = documentation; 89 } 90 91 /** 92 * Returns the parameters of this method. 93 * 94 * @return The parameters. 95 */ 96 public Collection<TemplateParameter> getParameters() { 97 return parameters.values(); 98 } 99 100 /** 101 * Returns a parameter given its name. 102 * 103 * @param name The name of the parameter. 104 * @return The parameter. 105 */ 106 public TemplateParameter getParameterByName(String name) { 107 return parameters.get(name); 108 } 109 110 /** 111 * Indicates that this method needs a tag body. 112 * 113 * @return <code>true</code> if tag body is needed. 114 */ 115 public boolean hasBody() { 116 if (parameters.size() >= 2) { 117 for (TemplateParameter param : parameters.values()) { 118 if (param.isBody()) { 119 return true; 120 } 121 } 122 } 123 return false; 124 } 125 126 @Override 127 public String toString() { 128 return "TemplateMethod [name=" + name + ", documentation=" 129 + documentation + ", parameters=" + parameters + "]"; 130 } 131 }