Coverage Report - org.apache.tiles.autotag.generate.TemplateGeneratorBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
TemplateGeneratorBuilder
100%
32/32
100%
8/8
1.889
 
 1  
 /*
 2  
  * $Id: TemplateGeneratorBuilder.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.ArrayList;
 24  
 import java.util.List;
 25  
 
 26  
 import org.apache.tiles.autotag.core.OutputLocator;
 27  
 import org.apache.tiles.autotag.generate.BasicTemplateGenerator.TCGeneratorDirectoryPair;
 28  
 import org.apache.tiles.autotag.generate.BasicTemplateGenerator.TSGeneratorDirectoryPair;
 29  
 
 30  
 /**
 31  
  * Builds a {@link TemplateGenerator}.
 32  
  *
 33  
  * @version $Rev: 1643653 $ $Date: 2014-12-07 07:47:59 +0100 (Sun, 07 Dec 2014) $
 34  
  */
 35  
 public class TemplateGeneratorBuilder {
 36  
 
 37  
     /**
 38  
      * The template suite generators.
 39  
      */
 40  
     private List<TSGeneratorDirectoryPair> templateSuiteGenerators;
 41  
 
 42  
     /**
 43  
      * The template class generators.
 44  
      */
 45  
     private List<TCGeneratorDirectoryPair> templateClassGenerators;
 46  
 
 47  
     /**
 48  
      * Indicates that this generator generates resources.
 49  
      */
 50  8
     private boolean generatingResources = false;
 51  
 
 52  
     /**
 53  
      * Indicates that this generator generates classes.
 54  
      */
 55  8
     private boolean generatingClasses = false;
 56  
 
 57  
     /**
 58  
      * The classes output directory.
 59  
      */
 60  
     private OutputLocator classesOutputLocator;
 61  
 
 62  
     /**
 63  
      * The resources output directory.
 64  
      */
 65  
     private OutputLocator resourcesOutputLocator;
 66  
 
 67  
     /**
 68  
      * Constructor.
 69  
      */
 70  8
     private TemplateGeneratorBuilder() {
 71  8
         templateSuiteGenerators = new ArrayList<BasicTemplateGenerator.TSGeneratorDirectoryPair>();
 72  8
         templateClassGenerators = new ArrayList<BasicTemplateGenerator.TCGeneratorDirectoryPair>();
 73  8
     }
 74  
 
 75  
     /**
 76  
      * Creates a new instance of the builder.
 77  
      *
 78  
      * @return A new instance of the builder.
 79  
      */
 80  
     public static TemplateGeneratorBuilder createNewInstance() {
 81  8
         return new TemplateGeneratorBuilder();
 82  
     }
 83  
 
 84  
     /**
 85  
      * Sets the classes output directory.
 86  
      *
 87  
      * @param classesOutputDirectory The classes output directory.
 88  
      * @return This instance.
 89  
      */
 90  
     public TemplateGeneratorBuilder setClassesOutputLocator(OutputLocator classesOutputLocator) {
 91  2
         this.classesOutputLocator = classesOutputLocator;
 92  2
         return this;
 93  
     }
 94  
 
 95  
     /**
 96  
      * Sets the resources output directory.
 97  
      *
 98  
      * @param resourcesOutputDirectory The resources output directory.
 99  
      * @return This instance.
 100  
      */
 101  
     public TemplateGeneratorBuilder setResourcesOutputLocator(OutputLocator resourcesOutputLocator) {
 102  2
         this.resourcesOutputLocator = resourcesOutputLocator;
 103  2
         return this;
 104  
     }
 105  
 
 106  
     /**
 107  
      * Adds a new template suite generator to generate classes.
 108  
      *
 109  
      * @param generator The generator to add.
 110  
      * @return This instance.
 111  
      */
 112  
     public TemplateGeneratorBuilder addClassesTemplateSuiteGenerator(TemplateSuiteGenerator generator) {
 113  2
         if (classesOutputLocator == null) {
 114  1
             throw new NullPointerException(
 115  
                     "Classes output locator not specified, call 'setClassesOutputLocator' first");
 116  
         }
 117  1
         templateSuiteGenerators.add(new TSGeneratorDirectoryPair(
 118  
                 classesOutputLocator, generator));
 119  1
         generatingClasses = true;
 120  1
         return this;
 121  
     }
 122  
 
 123  
     /**
 124  
      * Adds a new template class generator to generate classes.
 125  
      *
 126  
      * @param generator The generator to add.
 127  
      * @return This instance.
 128  
      */
 129  
     public TemplateGeneratorBuilder addClassesTemplateClassGenerator(TemplateClassGenerator generator) {
 130  2
         if (classesOutputLocator == null) {
 131  1
             throw new NullPointerException(
 132  
                     "Classes output locator not specified, call 'setClassesOutputLocator' first");
 133  
         }
 134  1
         templateClassGenerators.add(new TCGeneratorDirectoryPair(
 135  
                 classesOutputLocator, generator));
 136  1
         generatingClasses = true;
 137  1
         return this;
 138  
     }
 139  
 
 140  
     /**
 141  
      * Adds a new template suite generator to generate resources.
 142  
      *
 143  
      * @param generator The generator to add.
 144  
      * @return This instance.
 145  
      */
 146  
     public TemplateGeneratorBuilder addResourcesTemplateSuiteGenerator(TemplateSuiteGenerator generator) {
 147  2
         if (resourcesOutputLocator == null) {
 148  1
             throw new NullPointerException(
 149  
                     "Resources output locator not specified, call 'setClassesOutputLocator' first");
 150  
         }
 151  1
         templateSuiteGenerators.add(new TSGeneratorDirectoryPair(
 152  
                 resourcesOutputLocator, generator));
 153  1
         generatingResources = true;
 154  1
         return this;
 155  
     }
 156  
 
 157  
     /**
 158  
      * Adds a new template class generator to generate resources.
 159  
      *
 160  
      * @param generator The generator to add.
 161  
      * @return This instance.
 162  
      */
 163  
     public TemplateGeneratorBuilder addResourcesTemplateClassGenerator(TemplateClassGenerator generator) {
 164  2
         if (resourcesOutputLocator == null) {
 165  1
             throw new NullPointerException(
 166  
                     "Resources output locator not specified, call 'setClassesOutputLocator' first");
 167  
         }
 168  1
         templateClassGenerators.add(new TCGeneratorDirectoryPair(
 169  
                         resourcesOutputLocator, generator));
 170  1
         generatingResources = true;
 171  1
         return this;
 172  
     }
 173  
 
 174  
     /**
 175  
      * Builds and returns a new template generator.
 176  
      *
 177  
      * @return The new template generator.
 178  
      */
 179  
     public TemplateGenerator build() {
 180  4
         return new BasicTemplateGenerator(templateSuiteGenerators,
 181  
                 templateClassGenerators, generatingClasses, generatingResources);
 182  
     }
 183  
 
 184  
 }