1 package org.andromda.core.cartridge;
2
3 import java.io.File;
4 import java.text.MessageFormat;
5 import org.andromda.core.configuration.NamespaceProperties;
6 import org.andromda.core.configuration.Namespaces;
7 import org.andromda.core.configuration.Property;
8 import org.apache.commons.lang.StringUtils;
9
10
11
12
13
14
15
16
17
18 public class Resource
19 {
20
21
22
23 private String outlet;
24
25
26
27
28
29
30 public String getOutlet()
31 {
32 return outlet;
33 }
34
35
36
37
38
39
40 public void setOutlet(final String outlet)
41 {
42 this.outlet = outlet;
43 }
44
45
46
47
48 private String outputCondition;
49
50
51
52
53
54
55 public void setOutputCondition(final String outputCondition)
56 {
57 this.outputCondition = outputCondition;
58 }
59
60
61
62
63
64
65 public String getOutputCondition()
66 {
67 return this.outputCondition;
68 }
69
70
71
72
73
74
75
76
77
78
79 public File getOutputLocation(
80 final Object[] arguments,
81 final File directory,
82 String outputPattern)
83 {
84 File file = null;
85
86
87 if (directory != null && arguments != null && arguments.length > 0)
88 {
89 for (int ctr = 0; ctr < arguments.length; ctr++)
90 {
91 arguments[ctr] = StringUtils.trimToEmpty(String.valueOf(arguments[ctr]));
92 }
93 if (StringUtils.isBlank(outputPattern))
94 {
95 outputPattern = this.getOutputPattern();
96 }
97 String outputFileName;
98 try
99 {
100 outputFileName = MessageFormat.format(
101 outputPattern,
102 arguments);
103 }
104 catch (final Exception exception)
105 {
106
107
108 outputFileName = outputPattern;
109 }
110 file = new File(
111 directory,
112 outputFileName);
113 }
114 return file;
115 }
116
117
118
119
120 private boolean overwrite = false;
121
122
123
124
125
126
127
128
129 public boolean isOverwrite()
130 {
131 final Property property =
132 Namespaces.instance().getProperty(
133 this.getCartridge().getNamespace(),
134 NamespaceProperties.OVERWRITE,
135 false);
136 if (property != null)
137 {
138 this.overwrite = Boolean.valueOf(property.getValue());
139 }
140 return this.overwrite;
141 }
142
143
144
145
146
147
148 public void setOverwrite(final boolean overwrite)
149 {
150 this.overwrite = overwrite;
151 }
152
153
154
155
156 private boolean lastModifiedCheck;
157
158
159
160
161
162
163 public void setLastModifiedCheck(final boolean lastModifiedCheck)
164 {
165 this.lastModifiedCheck = lastModifiedCheck;
166 }
167
168
169
170
171
172
173 public boolean isLastModifiedCheck()
174 {
175 return this.lastModifiedCheck;
176 }
177
178
179
180
181 private String path;
182
183
184
185
186
187
188 public String getPath()
189 {
190 return this.path;
191 }
192
193
194
195
196
197
198 public void setPath(final String path)
199 {
200 this.path = path;
201 }
202
203
204
205
206 private Cartridge cartridge;
207
208
209
210
211
212
213 public Cartridge getCartridge()
214 {
215 return this.cartridge;
216 }
217
218
219
220
221
222
223 public void setCartridge(final Cartridge cartridge)
224 {
225 this.cartridge = cartridge;
226 }
227
228
229
230
231 private String outputPattern;
232
233
234
235
236
237
238 public void setOutputPattern(final String outputPattern)
239 {
240 this.outputPattern = outputPattern;
241 }
242
243
244
245
246
247
248 public String getOutputPattern()
249 {
250 return StringUtils.trimToEmpty(this.outputPattern);
251 }
252
253
254
255
256 @Override
257 public String toString()
258 {
259 StringBuilder builder = new StringBuilder();
260 builder.append(super.toString());
261 builder.append(" [outlet=").append(this.outlet);
262 builder.append(", outputCondition=").append(this.outputCondition);
263 builder.append(", overwrite=").append(this.overwrite);
264 builder.append(", lastModifiedCheck=").append(this.lastModifiedCheck);
265 builder.append(", path=").append(this.path);
266 builder.append(", cartridge=").append(this.cartridge);
267 builder.append(", outputPattern=").append(this.outputPattern).append("]");
268 return builder.toString();
269 }
270 }