View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  /*
18   * JDORIVersion.java
19   *
20   * Created on December 1, 2000
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"; // NOI18N
42      
43      private final static String  vendor_name_msg     	= "MSG_VendorName"; // NOI18N
44      private final static String  version_number_msg  	= "MSG_VersionNumber"; // NOI18N
45      
46      private final static String  vendor_name     	= "VendorName"; // NOI18N
47      private final static String  version_number  	= "VersionNumber"; // NOI18N
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")) ) { // NOI18N
57              System.out.println( msg.msg("MSG_DisplayVersion", version)); // NOI18N
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 }