1 package org.andromda.core.cartridge.template;
2
3 import java.io.File;
4 import org.andromda.core.cartridge.Resource;
5 import org.andromda.core.common.XmlObjectFactory;
6 import org.andromda.core.metafacade.MetafacadeConstants;
7 import org.apache.commons.lang.StringUtils;
8
9
10
11
12
13
14
15
16
17
18 public class Template
19 extends Resource
20 {
21
22
23
24 public Template()
25 {
26 this.supportedModelElements = new ModelElements();
27 }
28
29
30
31
32
33 private boolean generateEmptyFiles = false;
34
35
36
37
38
39
40 public void setGenerateEmptyFiles(final boolean generateEmptyFiles)
41 {
42 this.generateEmptyFiles = generateEmptyFiles;
43 }
44
45
46
47
48
49
50 public boolean isGenerateEmptyFiles()
51 {
52 return generateEmptyFiles;
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 public File getOutputLocation(
70 final String metafacadeName,
71 final String packageName,
72 final File directory,
73 String outputPattern)
74 {
75 File file;
76
77 if (StringUtils.isBlank(outputPattern))
78 {
79 outputPattern = this.getOutputPattern();
80 }
81
82
83
84 if (this.isOutputToSingleFile())
85 {
86 file = super.getOutputLocation(
87 new String[] {outputPattern},
88 directory,
89 outputPattern);
90 }
91 else
92 {
93 file =
94 super.getOutputLocation(
95 new String[]
96 {
97 StringUtils.replace(
98 StringUtils.trimToEmpty(packageName),
99 MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR,
100 File.separator), metafacadeName
101 },
102 directory,
103 outputPattern);
104 }
105 return file;
106 }
107
108
109
110
111
112
113
114 public ModelElements getSupportedModeElements()
115 {
116 final String methodName = "Template.getModelElements";
117 if (this.supportedModelElements == null)
118 {
119 throw new TemplateException(methodName + " - supportedModelElements is null!");
120 }
121 return this.supportedModelElements;
122 }
123
124
125
126
127
128
129
130 public void setSupportedModelElements(final ModelElements supportedModelElements)
131 {
132 this.supportedModelElements = supportedModelElements;
133 }
134
135 private boolean outputToSingleFile = false;
136
137
138
139
140
141
142
143 public boolean isOutputToSingleFile()
144 {
145 return outputToSingleFile;
146 }
147
148
149
150
151
152
153 public void setOutputToSingleFile(final boolean outputToSingleFile)
154 {
155 this.outputToSingleFile = outputToSingleFile;
156 }
157
158
159
160
161 private boolean outputOnEmptyElements = true;
162
163
164
165
166
167
168
169
170 public boolean isOutputOnEmptyElements()
171 {
172 return this.outputOnEmptyElements;
173 }
174
175
176
177
178
179
180
181
182
183 public void setOutputOnEmptyElements(final boolean outputOnEmptyElements)
184 {
185 this.outputOnEmptyElements = outputOnEmptyElements;
186 }
187
188
189
190
191 @Override
192 public String toString()
193 {
194 StringBuilder builder = new StringBuilder();
195 builder.append(super.toString());
196 builder.append(" [generateEmptyFiles=").append(this.generateEmptyFiles);
197 builder.append(", outputToSingleFile=").append(this.outputToSingleFile);
198 builder.append(", outputOnEmptyElements=").append(this.outputOnEmptyElements);
199 builder.append(", supportedModelElements=").append(this.supportedModelElements);
200 builder.append("]");
201 return builder.toString();
202 }
203
204
205
206
207 private ModelElements supportedModelElements = null;
208 }