1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.geronimo.ews.ws4j2ee.toWs;
18
19 import java.io.File;
20 import java.io.FileInputStream;
21 import java.io.InputStream;
22 import java.util.ArrayList;
23 import java.util.Properties;
24
25 /***
26 * @author hemapani@opensource.lk
27 */
28 public class Ws4J2eeProperties {
29 private Properties properties;
30 /***
31 * these a properties of the files or dir
32 * they are checked are they really exists
33 */
34 private ArrayList properitesToCheck;
35
36 public Ws4J2eeProperties() {
37 properties = new Properties();
38 properitesToCheck = new ArrayList();
39 properitesToCheck.add(GenerationConstants.AXIS_WEBAPPS_LIB);
40 properitesToCheck.add(GenerationConstants.EJB_DEPLOY_DIR);
41 properitesToCheck.add(GenerationConstants.MAVEN_LOCAL_REPOSITARY);
42 loadProperties();
43 checkProperties();
44 }
45
46 public String getProperty(String key) {
47 return properties.getProperty(key);
48 }
49
50 private void checkProperties() {
51 for (int i = 0; i < properitesToCheck.size(); i++) {
52 String key = (String) properitesToCheck.get(i);
53 String value = properties.getProperty(key);
54 if (value != null) {
55 File file = new File(value);
56 if (!file.exists()) {
57 properties.remove(key);
58 }
59 }
60 }
61 }
62
63 private void loadProperties() {
64 InputStream proIn = null;
65 proIn = GenerationConstants.class.getResourceAsStream(GenerationConstants.WS4J2EE_PROPERTY_FILE);
66 try {
67 if (proIn == null) {
68 File file = new File("conf/" + GenerationConstants.WS4J2EE_PROPERTY_FILE);
69 if (file.exists()) {
70 proIn = new FileInputStream(file);
71 }
72 }
73 if (proIn == null) {
74 proIn = GenerationConstants.class.getResourceAsStream("META-INF/" + GenerationConstants.WS4J2EE_PROPERTY_FILE);
75 }
76 if (proIn == null) {
77 proIn = new FileInputStream(GenerationConstants.WS4J2EE_PROPERTY_FILE);
78 }
79 if (proIn != null) {
80 properties.load(proIn);
81 }
82 } catch (Exception e) {
83 throw new UnrecoverableGenerationFault(e);
84 }
85 }
86
87 }