1/*2 * $Id: BasicTemplateGenerator.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.List;
24import java.util.Map;
2526import org.apache.tiles.autotag.core.OutputLocator;
27import org.apache.tiles.autotag.model.TemplateClass;
28import org.apache.tiles.autotag.model.TemplateSuite;
2930/**31 * The basic template generator. Use {@link TemplateGeneratorBuilder} to32 * create instances of this class.33 *34 * @version $Rev: 1643653 $ $Date: 2014-12-07 07:47:59 +0100 (Sun, 07 Dec 2014) $35 */36classBasicTemplateGeneratorimplementsTemplateGenerator {
3738/**39 * The template suite generators.40 */41private List<TSGeneratorDirectoryPair> templateSuiteGenerators;
4243/**44 * The template class generators.45 */46private List<TCGeneratorDirectoryPair> templateClassGenerators;
4748/**49 * Indicates that this generator generates resources.50 */51privateboolean generatingResources = false;
5253/**54 * Indicates that this generator generates classes.55 */56privateboolean generatingClasses = false;
5758/**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 */66BasicTemplateGenerator(
67 List<TSGeneratorDirectoryPair> templateSuiteGenerators,
68 List<TCGeneratorDirectoryPair> templateClassGenerators,
69boolean generatingClasses, boolean generatingResources) {
70this.templateSuiteGenerators = templateSuiteGenerators;
71this.templateClassGenerators = templateClassGenerators;
72this.generatingClasses = generatingClasses;
73this.generatingResources = generatingResources;
74 }
75767778 @Override
79publicvoid generate(String packageName, TemplateSuite suite, Map<String, String> parameters,
80 String runtimeClass, String requestClass) {
81for (TSGeneratorDirectoryPair pair : templateSuiteGenerators) {
82 pair.getGenerator().generate(pair.getOutputLocator(), packageName, suite, parameters);
83 }
84for (TemplateClass templateClass : suite.getTemplateClasses()) {
85for (TCGeneratorDirectoryPair pair : templateClassGenerators) {
86 pair.getGenerator().generate(pair.getOutputLocator(), packageName,
87 suite, templateClass, parameters, runtimeClass, requestClass);
88 }
89 }
90 }
9192/**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 */97staticclassTSGeneratorDirectoryPair {
98/**99 * The directory where files are generated.100 */101privateOutputLocator outputLocator;
102103/**104 * The generator.105 */106privateTemplateSuiteGenerator generator;
107108/**109 * Constructor.110 *111 * @param directory The directory where files are generated.112 * @param generator The generator.113 */114publicTSGeneratorDirectoryPair(OutputLocator outputLocator,
115TemplateSuiteGenerator generator) {
116this.outputLocator = outputLocator;
117this.generator = generator;
118 }
119120/**121 * Returns the directory where files are generated.122 *123 * @return The directory where files are generated.124 */125publicOutputLocator getOutputLocator() {
126return outputLocator;
127 }
128129/**130 * Returns the generator.131 *132 * @return The generator.133 */134publicTemplateSuiteGenerator getGenerator() {
135return generator;
136 }
137 }
138139/**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 */144staticclassTCGeneratorDirectoryPair {
145/**146 * The directory where files are generated.147 */148privateOutputLocator outputLocator;
149150/**151 * The generator.152 */153privateTemplateClassGenerator generator;
154155/**156 * Constructor.157 *158 * @param directory The directory where files are generated.159 * @param generator The generator.160 */161publicTCGeneratorDirectoryPair(OutputLocator outputLocator,
162TemplateClassGenerator generator) {
163this.outputLocator = outputLocator;
164this.generator = generator;
165 }
166167/**168 * Returns the directory where files are generated.169 *170 * @return The directory where files are generated.171 */172publicOutputLocator getOutputLocator() {
173return outputLocator;
174 }
175176/**177 * Returns the generator.178 *179 * @return The generator.180 */181publicTemplateClassGenerator getGenerator() {
182return generator;
183 }
184 }
185186 @Override
187publicboolean isGeneratingResources() {
188return generatingResources;
189 }
190191 @Override
192publicboolean isGeneratingClasses() {
193return generatingClasses;
194 }
195 }