Coverage Report - org.apache.tiles.autotag.model.TemplateClass
 
Classes in this File Line Coverage Branch Coverage Complexity
TemplateClass
100%
30/30
100%
10/10
1.462
 
 1  
 /*
 2  
  * $Id: TemplateClass.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 template class.
 29  
  *
 30  
  * @version $Rev: 1044707 $ $Date: 2010-12-11 21:35:57 +0100 (Sat, 11 Dec 2010) $
 31  
  */
 32  
 public class TemplateClass {
 33  
 
 34  
     /**
 35  
      * The class name.
 36  
      */
 37  
     private String name;
 38  
 
 39  
     /**
 40  
      * The name of the tag.
 41  
      */
 42  
     private String tagName;
 43  
 
 44  
     /**
 45  
      * The prefix of the tag class.
 46  
      */
 47  
     private String tagClassPrefix;
 48  
 
 49  
     /**
 50  
      * Documentation about this tag.
 51  
      */
 52  
     private String documentation;
 53  
 
 54  
     /**
 55  
      * The method that executes the template class.
 56  
      */
 57  
     private TemplateMethod executeMethod;
 58  
 
 59  
     /**
 60  
      * Constructor.
 61  
      *
 62  
      * @param name The name of the template class.
 63  
      */
 64  
     public TemplateClass(String name) {
 65  4
         this(name, null, null, null);
 66  4
     }
 67  
 
 68  
     /**
 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  
      */
 76  
     public TemplateClass(String name, String tagName, String tagClassPrefix,
 77  11
             TemplateMethod executeMethod) {
 78  11
         this.name = name;
 79  11
         this.tagName = tagName;
 80  11
         this.tagClassPrefix = tagClassPrefix;
 81  11
         this.executeMethod = executeMethod;
 82  11
     }
 83  
 
 84  
     /**
 85  
      * The name of the parsed class.
 86  
      *
 87  
      * @return The name of the class.
 88  
      */
 89  
     public String getName() {
 90  8
         return name;
 91  
     }
 92  
 
 93  
     /**
 94  
      * Returns the name of the class, without the package part.
 95  
      *
 96  
      * @return The simple class name.
 97  
      */
 98  
     public String getSimpleName() {
 99  2
         int pos = name.lastIndexOf('.');
 100  2
         if (pos >= 0) {
 101  1
             return name.substring(pos + 1);
 102  
         }
 103  1
         return name;
 104  
     }
 105  
 
 106  
     /**
 107  
      * Returns the tag name.
 108  
      *
 109  
      * @return The tag name.
 110  
      */
 111  
     public String getTagName() {
 112  2
         return tagName;
 113  
     }
 114  
 
 115  
     /**
 116  
      * Returns the tag class prefix.
 117  
      *
 118  
      * @return The tag class prefix.
 119  
      */
 120  
     public String getTagClassPrefix() {
 121  2
         return tagClassPrefix;
 122  
     }
 123  
 
 124  
     /**
 125  
      * Returns the documentation for this class.
 126  
      *
 127  
      * @return The documentation.
 128  
      */
 129  
     public String getDocumentation() {
 130  3
         return documentation;
 131  
     }
 132  
 
 133  
     /**
 134  
      * Sets the documentation for this class.
 135  
      *
 136  
      * @param documentation The documentation.
 137  
      */
 138  
     public void setDocumentation(String documentation) {
 139  4
         this.documentation = documentation;
 140  4
     }
 141  
 
 142  
     /**
 143  
      * Returns the method that execute this class.
 144  
      *
 145  
      * @return The execute method.
 146  
      */
 147  
     public TemplateMethod getExecuteMethod() {
 148  5
         return executeMethod;
 149  
     }
 150  
 
 151  
     /**
 152  
      * Returns the collection of regular parameters (no request, no body)
 153  
      * of the execute method.
 154  
      *
 155  
      * @return The regular parameters.
 156  
      */
 157  
     public Collection<TemplateParameter> getParameters() {
 158  2
         Map<String, TemplateParameter> params = new LinkedHashMap<String, TemplateParameter>();
 159  2
         fillRegularParameters(params, executeMethod);
 160  2
         return params.values();
 161  
     }
 162  
 
 163  
     /**
 164  
      * Indicates that this class needs a tag body.
 165  
      *
 166  
      * @return <code>true</code> if tag body is needed.
 167  
      */
 168  
     public boolean hasBody() {
 169  2
         return executeMethod.hasBody();
 170  
     }
 171  
 
 172  
     @Override
 173  
     public String toString() {
 174  1
         return "TemplateClass [name=" + name + ", tagName=" + tagName
 175  
                 + ", tagClassPrefix=" + tagClassPrefix + ", documentation="
 176  
                 + documentation + ", executeMethod=" + executeMethod + "]";
 177  
     }
 178  
 
 179  
     /**
 180  
      * Creates regular parameters map.
 181  
      *
 182  
      * @param params The map to fill.
 183  
      * @param method The method to analyze.
 184  
      */
 185  
     private void fillRegularParameters(Map<String, TemplateParameter> params,
 186  
             TemplateMethod method) {
 187  2
         if (method != null) {
 188  1
             for (TemplateParameter param : method.getParameters()) {
 189  4
                 if (!param.isRequest() && !param.isBody()) {
 190  2
                     params.put(param.getName(), param);
 191  
                 }
 192  4
             }
 193  
         }
 194  2
     }
 195  
 }