Coverage Report - org.apache.tiles.autotag.generate.BasicTemplateGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
BasicTemplateGenerator
100%
19/19
100%
6/6
1.3
BasicTemplateGenerator$TCGeneratorDirectoryPair
100%
6/6
N/A
1.3
BasicTemplateGenerator$TSGeneratorDirectoryPair
100%
6/6
N/A
1.3
 
 1  
 /*
 2  
  * $Id: BasicTemplateGenerator.java 1643653 2014-12-07 06:47:59Z 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.generate;
 22  
 
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import org.apache.tiles.autotag.core.OutputLocator;
 27  
 import org.apache.tiles.autotag.model.TemplateClass;
 28  
 import org.apache.tiles.autotag.model.TemplateSuite;
 29  
 
 30  
 /**
 31  
  * The basic template generator. Use {@link TemplateGeneratorBuilder} to
 32  
  * create instances of this class.
 33  
  *
 34  
  * @version $Rev: 1643653 $ $Date: 2014-12-07 07:47:59 +0100 (Sun, 07 Dec 2014) $
 35  
  */
 36  
 class BasicTemplateGenerator implements TemplateGenerator {
 37  
 
 38  
     /**
 39  
      * The template suite generators.
 40  
      */
 41  
     private List<TSGeneratorDirectoryPair> templateSuiteGenerators;
 42  
 
 43  
     /**
 44  
      * The template class generators.
 45  
      */
 46  
     private List<TCGeneratorDirectoryPair> templateClassGenerators;
 47  
 
 48  
     /**
 49  
      * Indicates that this generator generates resources.
 50  
      */
 51  5
     private boolean generatingResources = false;
 52  
 
 53  
     /**
 54  
      * Indicates that this generator generates classes.
 55  
      */
 56  5
     private boolean generatingClasses = false;
 57  
 
 58  
     /**
 59  
      * Constructor.
 60  
      *
 61  
      * @param templateSuiteGenerators The template suite generators.
 62  
      * @param templateClassGenerators The template class generators.
 63  
      * @param generatingClasses Indicates that this generator generates classes.
 64  
      * @param generatingResources Indicates that this generator generates resources.
 65  
      */
 66  
     BasicTemplateGenerator(
 67  
             List<TSGeneratorDirectoryPair> templateSuiteGenerators,
 68  
             List<TCGeneratorDirectoryPair> templateClassGenerators,
 69  5
             boolean generatingClasses, boolean generatingResources) {
 70  5
         this.templateSuiteGenerators = templateSuiteGenerators;
 71  5
         this.templateClassGenerators = templateClassGenerators;
 72  5
         this.generatingClasses = generatingClasses;
 73  5
         this.generatingResources = generatingResources;
 74  5
     }
 75  
 
 76  
 
 77  
 
 78  
     @Override
 79  
     public void generate(String packageName, TemplateSuite suite, Map<String, String> parameters, 
 80  
         String runtimeClass, String requestClass) {
 81  1
         for (TSGeneratorDirectoryPair pair : templateSuiteGenerators) {
 82  1
             pair.getGenerator().generate(pair.getOutputLocator(), packageName, suite, parameters);
 83  1
         }
 84  1
         for (TemplateClass templateClass : suite.getTemplateClasses()) {
 85  1
             for (TCGeneratorDirectoryPair pair : templateClassGenerators) {
 86  1
                 pair.getGenerator().generate(pair.getOutputLocator(), packageName,
 87  
                         suite, templateClass, parameters, runtimeClass, requestClass);
 88  1
             }
 89  1
         }
 90  1
     }
 91  
 
 92  
     /**
 93  
      * A pair of a template suite generator and a directory.
 94  
      *
 95  
      * @version $Rev: 1643653 $ $Date: 2014-12-07 07:47:59 +0100 (Sun, 07 Dec 2014) $
 96  
      */
 97  
     static class TSGeneratorDirectoryPair {
 98  
         /**
 99  
          * The directory where files are generated.
 100  
          */
 101  
         private OutputLocator outputLocator;
 102  
 
 103  
         /**
 104  
          * The generator.
 105  
          */
 106  
         private TemplateSuiteGenerator generator;
 107  
 
 108  
         /**
 109  
          * Constructor.
 110  
          *
 111  
          * @param directory The directory where files are generated.
 112  
          * @param generator The generator.
 113  
          */
 114  
         public TSGeneratorDirectoryPair(OutputLocator outputLocator,
 115  3
                 TemplateSuiteGenerator generator) {
 116  3
             this.outputLocator = outputLocator;
 117  3
             this.generator = generator;
 118  3
         }
 119  
 
 120  
         /**
 121  
          * Returns the directory where files are generated.
 122  
          *
 123  
          * @return The directory where files are generated.
 124  
          */
 125  
         public OutputLocator getOutputLocator() {
 126  1
             return outputLocator;
 127  
         }
 128  
 
 129  
         /**
 130  
          * Returns the generator.
 131  
          *
 132  
          * @return The generator.
 133  
          */
 134  
         public TemplateSuiteGenerator getGenerator() {
 135  1
             return generator;
 136  
         }
 137  
     }
 138  
 
 139  
     /**
 140  
      * A pair of a template class generator and a directory.
 141  
      *
 142  
      * @version $Rev: 1643653 $ $Date: 2014-12-07 07:47:59 +0100 (Sun, 07 Dec 2014) $
 143  
      */
 144  
     static class TCGeneratorDirectoryPair {
 145  
         /**
 146  
          * The directory where files are generated.
 147  
          */
 148  
         private OutputLocator outputLocator;
 149  
 
 150  
         /**
 151  
          * The generator.
 152  
          */
 153  
         private TemplateClassGenerator generator;
 154  
 
 155  
         /**
 156  
          * Constructor.
 157  
          *
 158  
          * @param directory The directory where files are generated.
 159  
          * @param generator The generator.
 160  
          */
 161  
         public TCGeneratorDirectoryPair(OutputLocator outputLocator,
 162  3
                 TemplateClassGenerator generator) {
 163  3
             this.outputLocator = outputLocator;
 164  3
             this.generator = generator;
 165  3
         }
 166  
 
 167  
         /**
 168  
          * Returns the directory where files are generated.
 169  
          *
 170  
          * @return The directory where files are generated.
 171  
          */
 172  
         public OutputLocator getOutputLocator() {
 173  1
             return outputLocator;
 174  
         }
 175  
 
 176  
         /**
 177  
          * Returns the generator.
 178  
          *
 179  
          * @return The generator.
 180  
          */
 181  
         public TemplateClassGenerator getGenerator() {
 182  1
             return generator;
 183  
         }
 184  
     }
 185  
 
 186  
     @Override
 187  
     public boolean isGeneratingResources() {
 188  5
         return generatingResources;
 189  
     }
 190  
 
 191  
     @Override
 192  
     public boolean isGeneratingClasses() {
 193  5
         return generatingClasses;
 194  
     }
 195  
 }