1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.jdo.util;
24
25 import java.util.Locale;
26 import java.util.ResourceBundle;
27 import java.util.Hashtable;
28 import java.util.Properties;
29 import java.io.InputStream;
30 import java.io.FileNotFoundException;
31 import java.text.DateFormat;
32 import java.text.SimpleDateFormat;
33
34 /***
35 * Helper class to handle properties object with version number and vendor name.
36 *
37 * @author Marina Vatkina
38 */
39 public class JDORIVersion {
40 private static Properties _properties = null;
41 private final static String default_bundle = "org.apache.jdo.util.Bundle";
42
43 private final static String vendor_name_msg = "MSG_VendorName";
44 private final static String version_number_msg = "MSG_VersionNumber";
45
46 private final static String vendor_name = "VendorName";
47 private final static String version_number = "VersionNumber";
48
49 private final static I18NHelper msg = I18NHelper.getInstance(default_bundle);
50
51 private final static String vendor = msg.msg(vendor_name_msg);
52 private final static String version = msg.msg(version_number_msg);
53
54 public static void main(String[] args) {
55 if (args == null || args.length == 0 ||
56 (args.length == 1 && args[0].equals("-version")) ) {
57 System.out.println( msg.msg("MSG_DisplayVersion", version));
58 }
59 System.exit(0);
60 }
61
62 /***
63 * Constructor without parameters
64 */
65 public JDORIVersion() {
66 loadProperties();
67 }
68
69 /***
70 * Constructor without parameters
71 */
72 public JDORIVersion(String fileName) {
73 loadProperties(fileName);
74 }
75
76 /***
77 * Load default properties
78 */
79 private static void loadProperties() {
80 _properties = new Properties();
81 _properties.setProperty(vendor_name, vendor);
82 _properties.setProperty(version_number, version);
83 }
84
85 /***
86 * Load specific properties file
87 */
88 private static void loadProperties(String fileName) {
89 Properties temp_properties = new Properties();
90 try {
91 InputStream in = JDORIVersion.class.getResourceAsStream(fileName);
92 if (in == null)
93 throw new java.io.FileNotFoundException(fileName);
94
95 temp_properties.load(in);
96 in.close();
97 } catch (java.io.IOException e) {
98 throw new RuntimeException(e.toString());
99 }
100
101 _properties = new Properties();
102 _properties.setProperty(vendor_name, temp_properties.getProperty(vendor_name));
103 _properties.setProperty(version_number, temp_properties.getProperty(version_number));
104 }
105
106 /***
107 * Return Vendor properties for a given file name
108 */
109 public static Properties getVendorProperties(String fileName) {
110 loadProperties(fileName);
111 return getVendorProperties();
112 }
113
114 /***
115 * Return Vendor properties
116 */
117 public synchronized static Properties getVendorProperties() {
118 if (_properties == null) {
119 loadProperties();
120 }
121 return _properties;
122 }
123
124 }