package com.etretatlogiciels.dvdcatalog.util;

import java.io.*;
import java.util.Properties;

public class DvdCatalogProperties extends Properties
{
   static final long             serialVersionUID = 20051222;
   static DvdCatalogProperties   properties = null;
   static Object                 lock = new Object();
   
   private DvdCatalogProperties()
   {
      super();
      SetProperties();
   }

   public static DvdCatalogProperties getInstance()
   {
      synchronized(lock)
      {
         if (properties == null)
            properties = new DvdCatalogProperties();
      }
      
      return properties;
   }

   public void SetProperties()
   {
      /*
      ** defaultProperties defines those properties to use if a
      ** a .properties file is not found in the directory to 
      ** specify these values.
      */
      Properties  defaultProperties = new DvdCatalogProperties();

      defaultProperties.put("dbserver",   "localhost");
      defaultProperties.put("database",   "dvdlist");
      defaultProperties.put("dbuser",     "j2ee");
      defaultProperties.put("dbpassword", "stivell");
      defaultProperties.put("dvdtable",   "dvdlist");

      /*
      ** Instantiate the static Properties object, giving it the default
      ** properties.
      **
      ** Attempt to load the 'dvdapp.properties' file from the current
      ** directory. Any properties in this file will override the default
      ** properties.
      */
      try { properties.load(new FileInputStream("dvdapp.properties")); } 
      catch (Exception e) { ; }
   }
}
