1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
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 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public class TemplateGeneratorBuilder { |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
private List<TSGeneratorDirectoryPair> templateSuiteGenerators; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
private List<TCGeneratorDirectoryPair> templateClassGenerators; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 8 | private boolean generatingResources = false; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 8 | private boolean generatingClasses = false; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private OutputLocator classesOutputLocator; |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
private OutputLocator resourcesOutputLocator; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 8 | private TemplateGeneratorBuilder() { |
71 | 8 | templateSuiteGenerators = new ArrayList<BasicTemplateGenerator.TSGeneratorDirectoryPair>(); |
72 | 8 | templateClassGenerators = new ArrayList<BasicTemplateGenerator.TCGeneratorDirectoryPair>(); |
73 | 8 | } |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public static TemplateGeneratorBuilder createNewInstance() { |
81 | 8 | return new TemplateGeneratorBuilder(); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public TemplateGeneratorBuilder setClassesOutputLocator(OutputLocator classesOutputLocator) { |
91 | 2 | this.classesOutputLocator = classesOutputLocator; |
92 | 2 | return this; |
93 | |
} |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public TemplateGeneratorBuilder setResourcesOutputLocator(OutputLocator resourcesOutputLocator) { |
102 | 2 | this.resourcesOutputLocator = resourcesOutputLocator; |
103 | 2 | return this; |
104 | |
} |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
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 | |
|
125 | |
|
126 | |
|
127 | |
|
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 | |
|
142 | |
|
143 | |
|
144 | |
|
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 | |
|
159 | |
|
160 | |
|
161 | |
|
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 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public TemplateGenerator build() { |
180 | 4 | return new BasicTemplateGenerator(templateSuiteGenerators, |
181 | |
templateClassGenerators, generatingClasses, generatingResources); |
182 | |
} |
183 | |
|
184 | |
} |