1 23 24 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 ; 36 import java.io.InputStream ; 37 import java.text.DateFormat ; 38 import java.text.SimpleDateFormat ; 39 import java.util.Properties ; 40 import java.util.ResourceBundle ; 41 42 public class RuntimeVersion { 43 private static Properties _properties = new Properties (); 44 private final static ResourceBundle vendor_info = I18NHelper.loadBundle( 45 RuntimeVersion.class); 46 47 48 private static String product_version = "product.version.number"; private static String build_time = "product.build.time"; private static String runtime_version = "runtime.version.number"; private static String vendor_name = "VendorName"; private static String version_number = "VersionNumber"; private static String vendor = I18NHelper.getMessage(vendor_info, "vendor"); 55 public static void main(String [] args) { 56 if (args == null || args.length == 0 || 57 (args.length == 1 && args[0].equals("-version"))) { 59 RuntimeVersion rt = new RuntimeVersion(); 60 rt.loadProperties("/com/sun/jdo/spi/persistence/support/sqlstore/sys.properties"); System.out.println(parse_version()); 62 } 63 System.exit(0); 64 } 65 66 69 public RuntimeVersion() { 70 } 71 72 75 public RuntimeVersion(String fileName) { 76 loadProperties(fileName); 77 } 78 79 82 public static void loadProperties(String fileName) { 83 try { 84 InputStream in = RuntimeVersion.class.getResourceAsStream(fileName); 85 if (in == null) 86 throw new FileNotFoundException (fileName); 87 88 _properties.load(in); 89 in.close(); 90 } catch (java.io.IOException e) { 91 throw new JDOException(null, e); 92 } 93 } 94 95 98 public static Properties getVendorProperties(String fileName) { 99 loadProperties(fileName); 100 return getVendorProperties(); 101 } 102 103 106 public static Properties getVendorProperties() { 107 if (_properties == null) 108 return null; 109 110 Properties _vendorProperties = new Properties (); 111 _vendorProperties.setProperty(vendor_name, vendor); 112 _vendorProperties.setProperty(version_number, parse_version()); 113 114 return _vendorProperties; 115 } 116 117 121 private static String parse_version() { 122 if (_properties == null) 123 return null; 124 125 String majorVersion = _properties.getProperty(product_version); 126 String minorVersion = _properties.getProperty(runtime_version); 127 String buildTime = _properties.getProperty(build_time); 128 129 String s = null; 131 try { 132 DateFormat dateFormatter = DateFormat.getDateTimeInstance(); 133 SimpleDateFormat propertyFormat = new SimpleDateFormat ("MM/dd/yy hh:mm:ss"); s = dateFormatter.format(propertyFormat.parse(buildTime)); 135 } catch (Exception e) { 136 s = ""; } 138 139 return I18NHelper.getMessage(vendor_info, "fullVersion", majorVersion, minorVersion, s); 141 } 142 } 143 | Popular Tags |