View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2009 Ordina and committers to Mod4j
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *     Ordina - initial implementation
10   *******************************************************************************/
11  package org.mod4j.dslcommon.generator.helpers;
12  
13  import java.io.FileInputStream;
14  import java.io.FileNotFoundException;
15  import java.io.IOException;
16  import java.util.Properties;
17  
18  import org.eclipse.emf.common.util.URI;
19  import org.eclipse.emf.ecore.EObject;
20  
21  public class ProjectProperties {
22  
23      public static void setPropertiesFile(String filename) {
24          System.err.println("PROPERTIES [" + filename + "]");
25          propertyFile = filename;
26          readAllProperties();
27      }
28  
29      private static void readAllProperties() {
30          Properties properties = new Properties();
31  
32          try {
33              properties.load(new FileInputStream(propertyFile));
34          } catch (FileNotFoundException e) {
35              System.err.println("PropjectProperties: cannot find properties file [" + propertyFile + "]");
36              e.printStackTrace();
37          } catch (IOException e) {
38              System.err.println("PropjectProperties: cannot read properties file [" + propertyFile + "]");
39              e.printStackTrace();
40          }
41  
42          applicationName = properties.getProperty("applicationName");
43          applicationVersion = properties.getProperty("applicationVersion");
44          applicationPath = properties.getProperty("applicationPath");
45          dslModelsModuleName = properties.getProperty("dslModelsModuleName");
46          domainModuleName = properties.getProperty("domainModuleName");
47          dataModuleName = properties.getProperty("dataModuleName");
48          businessModuleName = properties.getProperty("businessModuleName");
49          serviceModuleName = properties.getProperty("serviceModuleName");
50          presentationModuleName = properties.getProperty("presentationModuleName");
51          rootPackage = properties.getProperty("rootPackage");
52          businessRootPackage = properties.getProperty("businessRootPackage");
53          serviceRootPackage = properties.getProperty("serviceRootPackage");
54          domainRootPackage = properties.getProperty("domainRootPackage");
55          dataRootPackage = properties.getProperty("dataRootPackage");
56          presentationRootPackage = properties.getProperty("presentationRootPackage");
57          srcGenPath = properties.getProperty("srcGenPath");
58          resourceGenPath = properties.getProperty("resourceGenPath");
59          srcManPath = properties.getProperty("srcManPath");
60          resourceManPath = properties.getProperty("resourceManPath");
61          webAppPath = properties.getProperty("webAppPath");
62          //environmentPropertiesFileName = properties.getProperty("environmentPropertiesFileName");
63          fileEncoding = properties.getProperty("fileEncoding");
64          hibernate_hbm2ddl_auto = properties.getProperty("hibernate.hbm2ddl.auto");
65          hibernate_mapping_class_id_generator_class = properties
66                  .getProperty("hibernate-mapping.class.id.generator.class");
67          hibernate_mapping_inheritance_strategy = properties.getProperty("hibernate-mapping.inheritance.strategy");
68  
69      }
70  
71      private static String propertyFile = "DEFAULT";
72  
73      private static String applicationVersion = "DEFAULT";
74  
75      private static String applicationName = "DEFAULT";
76  
77      private static String applicationPath = "DEFAULT";
78  
79      private static String dslModelsModuleName = "dslModels";
80  
81      private static final String SRC_MODEL_PATH = "src/model";
82  
83      private static String dataModuleName = "DEFAULT";
84  
85      private static String businessModuleName = "DEFAULT";
86  
87      private static String serviceModuleName = "DEFAULT";
88  
89      private static String domainModuleName = "DEFAULT";
90      
91      private static String presentationModuleName = "DEFAULT";
92  
93      private static String rootPackage = "DEFAULT";
94  
95      private static String businessRootPackage = "DEFAULT";
96  
97      private static String serviceRootPackage = "DEFAULT";
98      
99      private static String presentationRootPackage = "DEFAULT";
100 
101     private static String domainRootPackage = "DEFAULT";
102 
103     private static String dataRootPackage = "DEFAULT";
104 
105     private static String srcGenPath = "DEFAULT";
106 
107     private static String resourceGenPath = "DEFAULT";
108 
109     private static String srcManPath = "DEFAULT";
110     
111     private static String webAppPath = "src/main/webapp";
112 
113     private static String resourceManPath = "DEFAULT";
114     
115     private static final String environmentPropertiesFileName = "environment.properties";
116 
117     private static String fileEncoding = "UTF-8";
118 
119     public static final String IMPLBASE_SUFFIX = "ImplBase";
120 
121     public static final String DAO_PACKAGE = "";
122 
123     public static final String DAO_IMPL_PACKAGE = ".hibernate.spring";
124 
125     public static final String DTO_PACKAGE = ".dto";
126 
127     public static final String TRANSLATORS_PACKAGE = ".translators";
128 
129     private static String workDir = "/";
130 
131     private static String hibernate_hbm2ddl_auto = "update";
132 
133     private static String hibernate_mapping_class_id_generator_class = "native";
134 
135     private static String hibernate_mapping_inheritance_strategy = "table.per.concrete.class";
136     
137 
138     public static void setWorkDir(String dir) {
139         workDir = dir;
140     }
141 
142     public static String getApplicationName() {
143         return applicationName;
144     }
145 
146     public static String getApplicationVersion() {
147         return applicationVersion;
148     }
149 
150     public static String getApplicationPath() {
151     	if( applicationPath != null ){
152 	    	if( applicationPath.startsWith("..")){
153 	    		if( applicationPath.equals("..")) {
154              		int last = workDir.lastIndexOf("/");
155              		if( last == -1 ){
156                  		last = workDir.lastIndexOf("\\");
157              		}
158 	            	if( last > -1){
159 	            		return workDir.substring(0, last)  ;
160 	            	}
161 	    		} else {
162 	        		int last = workDir.lastIndexOf("/");
163 	        		return workDir.substring(0, last) + applicationPath.substring(2) ;
164 	    		}
165 	    	}
166     	}
167         return workDir + "/" + applicationPath;
168     }
169 
170     public static String getDslModelsModulePath() {
171         return getApplicationPath() + "/" + getDslModelsModuleName();
172     }
173 
174     public static String getDslModelsModuleName() {
175         return dslModelsModuleName;
176     }
177 
178     public static String getDomainModulePath() {
179         return getApplicationPath() + "/" + getDomainModuleName();
180     }
181 
182     public static String getDomainModuleName() {
183         return domainModuleName;
184     }
185 
186     public static String getBusinessModuleName() {
187         return businessModuleName;
188     }
189     
190     public static String getPresentationModuleName(String targetPlatform) {
191         return presentationModuleName ; //+ (targetPlatform != null ? "-" + targetPlatform : "");
192     }
193 
194     public static String getServiceModuleName() {
195         return serviceModuleName;
196     }
197 
198     public static String getPresentationModulePath(String targetPlatform) {
199         return getApplicationPath() + "/" + getPresentationModuleName(targetPlatform);
200     }
201 
202     public static String getServiceModulePath() {
203         return getApplicationPath() + "/" + getServiceModuleName();
204     }
205 
206     public static String getBusinessModulePath() {
207         return getApplicationPath() + "/" + getBusinessModuleName();
208     }
209 
210     public static String getDataModulePath() {
211         return getApplicationPath() + "/" + getDataModuleName();
212     }
213 
214     public static String getDataModuleName() {
215         return dataModuleName;
216     }
217 
218     public static String getRootPackage() {
219         return rootPackage;
220     }
221 
222     public static String getBusinessRootPackage() {
223         return businessRootPackage;
224     }
225 
226     public static String getBusinessRootPackageAsPath() {
227         return getBusinessRootPackage().replaceAll("\\.", "/");
228     }
229 
230     public static String getServiceRootPackage() {
231         return serviceRootPackage;
232     }
233 
234     public static String getServiceRootPackageAsPath() {
235         return getServiceRootPackage().replaceAll("\\.", "/");
236     }
237     
238     public static String getPresentationRootPackage() {
239         return presentationRootPackage;
240     }
241 
242     public static String getPresentationCommonPackage() {
243         return "org.mod4j.common.wicket";
244     }
245 
246     public static String getPresentationCommonPackageAsPath() {
247         return getPresentationCommonPackage().replaceAll("\\.", "/");
248     }
249 
250     public static String getPresentationRootPackageAsPath() {
251         return getPresentationRootPackage().replaceAll("\\.", "/");
252     }
253 
254     public static String getDomainRootPackage() {
255         return domainRootPackage;
256     }
257 
258     public static String getDomainRootPackageAsPath() {
259         return getDomainRootPackage().replaceAll("\\.", "/");
260     }
261 
262     public static String getDataRootPackage() {
263         return dataRootPackage;
264     }
265 
266     public static String getDataRootPackageAsPath() {
267         return getDataRootPackage().replaceAll("\\.", "/");
268     }
269 
270     public static String getDaoPackage() {
271         return getDataRootPackage() + DAO_PACKAGE;
272     }
273 
274     public static String getDaoPackageAsPath() {
275         return getDaoPackage().replaceAll("\\.", "/");
276     }
277 
278     public static String getDaoImplPackage() {
279         return getDataRootPackage() + DAO_IMPL_PACKAGE;
280     }
281 
282     public static String getDaoImplPackageAsPath() {
283         return getDaoPackage().replaceAll("\\.", "/");
284     }
285 
286     public static String getDtoPackage() {
287         return getServiceRootPackage() + DTO_PACKAGE;
288     }
289 
290     public static String getTranslatorsPackage() {
291         return getDtoPackage() + TRANSLATORS_PACKAGE;
292     }
293 
294     public static String getSrcModelPath() {
295         return SRC_MODEL_PATH;
296     }
297 
298     public static String getSrcGenPath() {
299         return srcGenPath;
300     }
301 
302     public static String getResourceGenPath() {
303         return resourceGenPath;
304     }
305 
306     public static String getSrcManPath() {
307         return srcManPath;
308     }
309 
310     public static String getResourceManPath() {
311         return resourceManPath;
312     }
313     
314     public static String getWebAppPath() {
315         return webAppPath;
316     }
317     
318     public static String getEnvPropFileName() {
319         return environmentPropertiesFileName;
320     }
321 
322     public static String getFileEncoding() {
323         return fileEncoding;
324     }
325 
326     public static String getHibernate_hbm2ddl_auto() {
327         return hibernate_hbm2ddl_auto;
328     }
329 
330     public static String getHibernate_mapping_class_id_generator_class() {
331         return hibernate_mapping_class_id_generator_class;
332     }
333 
334     public static String getHibernate_InheritanceMappingStrategy() {
335         return hibernate_mapping_inheritance_strategy;
336     }
337 
338     private static String project = "/";
339 
340     public static String getProject() {
341         return project;
342     }
343 
344     public static String getProjectForEObject(EObject object) {
345         if( project.equals("/") ){ 
346             URI uri = object.eResource().getURI();
347             return uri.segment(1);
348         } else {
349             return project;
350         }
351     }
352     
353     public static void setProject(String project) {
354         ProjectProperties.project = project;
355     }
356 }