KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > sqlstore > RuntimeVersion


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * RuntimeVersion.java
26  *
27  * Created on March 14, 2000
28  */

29
30 package com.sun.jdo.spi.persistence.support.sqlstore;
31
32 import com.sun.jdo.api.persistence.support.JDOException;
33 import com.sun.jdo.spi.persistence.utility.I18NHelper;
34
35 import java.io.FileNotFoundException JavaDoc;
36 import java.io.InputStream JavaDoc;
37 import java.text.DateFormat JavaDoc;
38 import java.text.SimpleDateFormat JavaDoc;
39 import java.util.Properties JavaDoc;
40 import java.util.ResourceBundle JavaDoc;
41
42 public class RuntimeVersion {
43     private static Properties JavaDoc _properties = new Properties JavaDoc();
44     private final static ResourceBundle JavaDoc vendor_info = I18NHelper.loadBundle(
45             RuntimeVersion.class);
46
47
48     private static String JavaDoc product_version = "product.version.number"; // NOI18N
49
private static String JavaDoc build_time = "product.build.time"; // NOI18N
50
private static String JavaDoc runtime_version = "runtime.version.number"; // NOI18N
51
private static String JavaDoc vendor_name = "VendorName"; // NOI18N
52
private static String JavaDoc version_number = "VersionNumber"; // NOI18N
53
private static String JavaDoc vendor = I18NHelper.getMessage(vendor_info, "vendor"); // NOI18N
54

55     public static void main(String JavaDoc[] args) {
56         if (args == null || args.length == 0 ||
57                 (args.length == 1 && args[0].equals("-version"))) // NOI18N
58
{
59             RuntimeVersion rt = new RuntimeVersion();
60             rt.loadProperties("/com/sun/jdo/spi/persistence/support/sqlstore/sys.properties"); // NOI18N
61
System.out.println(parse_version());
62         }
63         System.exit(0);
64     }
65
66     /**
67      * Constructor without parameters
68      */

69     public RuntimeVersion() {
70     }
71
72     /**
73      * Constructor without parameters
74      */

75     public RuntimeVersion(String JavaDoc fileName) {
76         loadProperties(fileName);
77     }
78
79     /**
80      * Load properties file
81      */

82     public static void loadProperties(String JavaDoc fileName) {
83         try {
84             InputStream JavaDoc in = RuntimeVersion.class.getResourceAsStream(fileName);
85             if (in == null)
86                 throw new FileNotFoundException JavaDoc(fileName);
87
88             _properties.load(in);
89             in.close();
90         } catch (java.io.IOException JavaDoc e) {
91             throw new JDOException(null, e);
92         }
93     }
94
95     /**
96      * Return Vendor properties for a given file name
97      */

98     public static Properties JavaDoc getVendorProperties(String JavaDoc fileName) {
99         loadProperties(fileName);
100         return getVendorProperties();
101     }
102
103     /**
104      * Return Vendor properties
105      */

106     public static Properties JavaDoc getVendorProperties() {
107         if (_properties == null)
108             return null;
109
110         Properties JavaDoc _vendorProperties = new Properties JavaDoc();
111         _vendorProperties.setProperty(vendor_name, vendor);
112         _vendorProperties.setProperty(version_number, parse_version());
113
114         return _vendorProperties;
115     }
116
117     /**
118      * Parse the build date and create a localized version
119      * return version as String
120      */

121     private static String JavaDoc parse_version() {
122         if (_properties == null)
123             return null;
124
125         String JavaDoc majorVersion = _properties.getProperty(product_version);
126         String JavaDoc minorVersion = _properties.getProperty(runtime_version);
127         String JavaDoc buildTime = _properties.getProperty(build_time);
128
129         // Parse the build date and create a localized version
130
String JavaDoc s = null;
131         try {
132             DateFormat JavaDoc dateFormatter = DateFormat.getDateTimeInstance();
133             SimpleDateFormat JavaDoc propertyFormat = new SimpleDateFormat JavaDoc("MM/dd/yy hh:mm:ss"); // NOI18N
134
s = dateFormatter.format(propertyFormat.parse(buildTime));
135         } catch (Exception JavaDoc e) {
136             s = ""; // NOI18N
137
}
138
139         return I18NHelper.getMessage(vendor_info, "fullVersion", majorVersion, minorVersion, s); // NOI18N
140

141     }
142 }
143
Popular Tags