1 package pt.digitalis.maven.ormgenerator;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import pt.digitalis.maven.ormgenerator.utils.FileUtils;
7 import pt.digitalis.maven.ormgenerator.utils.FreemarkerExecutor;
8 import freemarker.template.Configuration;
9
10
11
12
13
14 public abstract class BaseExecutor {
15
16
17
18
19
20 public static final String PROPERTIES_EXTENSION = ".properties";
21
22
23
24
25 public static final String AUTO_PACKAGE = ".auto";
26
27
28
29
30 public static final String DAO_PACKAGE = ".dao";
31
32
33
34
35 public static final String AUTO_PREFFIX = "Auto";
36
37
38
39
40 public static final String JAVA_EXTENSION = ".java";
41
42
43
44
45 public static final String DAO_SUFFIX = "DAO";
46
47
48
49
50
51 public static final String INTERFACE_PREFFIX = "I";
52
53
54
55
56 public static final String IMPL_FILE_SUFFIX = "Impl";
57
58
59
60
61 public static final String IMPL_PACKAGE_SUFFIX = ".impl";
62
63
64
65
66
67 private Configuration freemarkerConfig = null;
68
69
70
71
72 private String destinationDir = null;
73
74
75
76
77 private String templateDir = null;
78
79
80
81
82 private String packageName = null;
83
84
85
86
87 @SuppressWarnings("unused")
88 private BaseExecutor() {
89 }
90
91
92
93
94
95
96
97
98
99
100
101 public BaseExecutor(String packageName, String templateDir, String destinationDir) {
102 this.setDestinationDir(destinationDir);
103 this.setPackageName(packageName);
104 this.setTemplateDir(templateDir);
105 }
106
107
108
109
110
111
112
113 public void prepareExecutor(String templateDir) {
114 try {
115 this.setFreemarkerConfig(FreemarkerExecutor.prepareFreemarker(this.getTemplateDir(), this.getClass()));
116 } catch (IOException e) {
117 this.setFreemarkerConfig(null);
118 }
119 }
120
121
122
123
124
125
126 public abstract boolean execute();
127
128
129
130
131
132
133
134
135
136
137 public static String obtainPath(String baseDir, String packageName) {
138 String pathName = baseDir + File.separator + FileUtils.dotNotation2PathNotation(packageName);
139 File f = new File(pathName);
140 if (!f.exists())
141 f.mkdirs();
142 return pathName;
143 }
144
145
146
147
148 protected String getDestinationDir() {
149 return destinationDir;
150 }
151
152
153
154
155
156 private void setDestinationDir(String destinationDir) {
157 this.destinationDir = destinationDir;
158 }
159
160
161
162
163 protected String getPackageName() {
164 return packageName;
165 }
166
167
168
169
170
171 private void setPackageName(String packageName) {
172 this.packageName = packageName;
173 }
174
175
176
177
178 protected Configuration getFreemarkerConfig() {
179 return freemarkerConfig;
180 }
181
182
183
184
185
186 private void setFreemarkerConfig(Configuration freemarkerConfig) {
187 this.freemarkerConfig = freemarkerConfig;
188 }
189
190
191
192
193 protected String getTemplateDir() {
194 return templateDir;
195 }
196
197
198
199
200
201 private void setTemplateDir(String templateDir) {
202 this.templateDir = templateDir;
203 }
204
205 }