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