Save This Page
Home » jdo2-util-2.3-ea-src » org.apache.jdo.util » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software 
   12    * distributed under the License is distributed on an "AS IS" BASIS, 
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
   14    * See the License for the specific language governing permissions and 
   15    * limitations under the License.
   16    */
   17   
   18   /*
   19    * JDORIVersion.java
   20    *
   21    * Created on December 1, 2000
   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"; // NOI18N
   43       
   44       private final static String  vendor_name_msg     	= "MSG_VendorName"; // NOI18N
   45       private final static String  version_number_msg  	= "MSG_VersionNumber"; // NOI18N
   46       
   47       private final static String  vendor_name     	= "VendorName"; // NOI18N
   48       private final static String  version_number  	= "VersionNumber"; // NOI18N
   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")) ) { // NOI18N
   58               System.out.println( msg.msg("MSG_DisplayVersion", version)); // NOI18N
   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   }

Save This Page
Home » jdo2-util-2.3-ea-src » org.apache.jdo.util » [javadoc | source]