1/*2 * $Id: TemplateGeneratorBuilder.java 1643653 2014-12-07 06:47:59Z nlebas $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.generate;
2223import java.util.ArrayList;
24import java.util.List;
2526import org.apache.tiles.autotag.core.OutputLocator;
27import org.apache.tiles.autotag.generate.BasicTemplateGenerator.TCGeneratorDirectoryPair;
28import org.apache.tiles.autotag.generate.BasicTemplateGenerator.TSGeneratorDirectoryPair;
2930/**31 * Builds a {@link TemplateGenerator}.32 *33 * @version $Rev: 1643653 $ $Date: 2014-12-07 07:47:59 +0100 (Sun, 07 Dec 2014) $34 */35publicclassTemplateGeneratorBuilder {
3637/**38 * The template suite generators.39 */40private List<TSGeneratorDirectoryPair> templateSuiteGenerators;
4142/**43 * The template class generators.44 */45private List<TCGeneratorDirectoryPair> templateClassGenerators;
4647/**48 * Indicates that this generator generates resources.49 */50privateboolean generatingResources = false;
5152/**53 * Indicates that this generator generates classes.54 */55privateboolean generatingClasses = false;
5657/**58 * The classes output directory.59 */60privateOutputLocator classesOutputLocator;
6162/**63 * The resources output directory.64 */65privateOutputLocator resourcesOutputLocator;
6667/**68 * Constructor.69 */70privateTemplateGeneratorBuilder() {
71 templateSuiteGenerators = new ArrayList<BasicTemplateGenerator.TSGeneratorDirectoryPair>();
72 templateClassGenerators = new ArrayList<BasicTemplateGenerator.TCGeneratorDirectoryPair>();
73 }
7475/**76 * Creates a new instance of the builder.77 *78 * @return A new instance of the builder.79 */80publicstaticTemplateGeneratorBuilder createNewInstance() {
81returnnewTemplateGeneratorBuilder();
82 }
8384/**85 * Sets the classes output directory.86 *87 * @param classesOutputDirectory The classes output directory.88 * @return This instance.89 */90publicTemplateGeneratorBuilder setClassesOutputLocator(OutputLocator classesOutputLocator) {
91this.classesOutputLocator = classesOutputLocator;
92returnthis;
93 }
9495/**96 * Sets the resources output directory.97 *98 * @param resourcesOutputDirectory The resources output directory.99 * @return This instance.100 */101publicTemplateGeneratorBuilder setResourcesOutputLocator(OutputLocator resourcesOutputLocator) {
102this.resourcesOutputLocator = resourcesOutputLocator;
103returnthis;
104 }
105106/**107 * Adds a new template suite generator to generate classes.108 *109 * @param generator The generator to add.110 * @return This instance.111 */112publicTemplateGeneratorBuilder addClassesTemplateSuiteGenerator(TemplateSuiteGenerator generator) {
113if (classesOutputLocator == null) {
114thrownew NullPointerException(
115"Classes output locator not specified, call 'setClassesOutputLocator' first");
116 }
117 templateSuiteGenerators.add(newTSGeneratorDirectoryPair(
118 classesOutputLocator, generator));
119 generatingClasses = true;
120returnthis;
121 }
122123/**124 * Adds a new template class generator to generate classes.125 *126 * @param generator The generator to add.127 * @return This instance.128 */129publicTemplateGeneratorBuilder addClassesTemplateClassGenerator(TemplateClassGenerator generator) {
130if (classesOutputLocator == null) {
131thrownew NullPointerException(
132"Classes output locator not specified, call 'setClassesOutputLocator' first");
133 }
134 templateClassGenerators.add(newTCGeneratorDirectoryPair(
135 classesOutputLocator, generator));
136 generatingClasses = true;
137returnthis;
138 }
139140/**141 * Adds a new template suite generator to generate resources.142 *143 * @param generator The generator to add.144 * @return This instance.145 */146publicTemplateGeneratorBuilder addResourcesTemplateSuiteGenerator(TemplateSuiteGenerator generator) {
147if (resourcesOutputLocator == null) {
148thrownew NullPointerException(
149"Resources output locator not specified, call 'setClassesOutputLocator' first");
150 }
151 templateSuiteGenerators.add(newTSGeneratorDirectoryPair(
152 resourcesOutputLocator, generator));
153 generatingResources = true;
154returnthis;
155 }
156157/**158 * Adds a new template class generator to generate resources.159 *160 * @param generator The generator to add.161 * @return This instance.162 */163publicTemplateGeneratorBuilder addResourcesTemplateClassGenerator(TemplateClassGenerator generator) {
164if (resourcesOutputLocator == null) {
165thrownew NullPointerException(
166"Resources output locator not specified, call 'setClassesOutputLocator' first");
167 }
168 templateClassGenerators.add(newTCGeneratorDirectoryPair(
169 resourcesOutputLocator, generator));
170 generatingResources = true;
171returnthis;
172 }
173174/**175 * Builds and returns a new template generator.176 *177 * @return The new template generator.178 */179publicTemplateGenerator build() {
180returnnewBasicTemplateGenerator(templateSuiteGenerators,
181 templateClassGenerators, generatingClasses, generatingResources);
182 }
183184 }