Coverage Report - org.paneris.jammyjoes.shopping.MelatiShoppingConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
MelatiShoppingConfig
0%
0/22
N/A
2
 
 1  
 /*
 2  
  * $Source: /usr/cvsroot/org/paneris/melati/shopping/MelatiShoppingConfig.java,v $
 3  
  * $Revision: 1.3 $
 4  
  *
 5  
  * Copyright (C) 2000 Tim Joyce
 6  
  *
 7  
  * Part of Melati (http://melati.org), a framework for the rapid
 8  
  * development of clean, maintainable web applications.
 9  
  *
 10  
  * Melati is free software; Permission is granted to copy, distribute
 11  
  * and/or modify this software under the terms either:
 12  
  *
 13  
  * a) the GNU General Public License as published by the Free Software
 14  
  *    Foundation; either version 2 of the License, or (at your option)
 15  
  *    any later version,
 16  
  *
 17  
  *    or
 18  
  *
 19  
  * b) any version of the Melati Software License, as published
 20  
  *    at http://melati.org
 21  
  *
 22  
  * You should have received a copy of the GNU General Public License and
 23  
  * the Melati Software License along with this program;
 24  
  * if not, write to the Free Software Foundation, Inc.,
 25  
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
 26  
  * GNU General Public License and visit http://melati.org to obtain the
 27  
  * Melati Software License.
 28  
  *
 29  
  * Feel free to contact the Developers of Melati (http://melati.org),
 30  
  * if you would like to work out a different arrangement than the options
 31  
  * outlined here.  It is our intention to allow Melati to be used by as
 32  
  * wide an audience as possible.
 33  
  *
 34  
  * This program is distributed in the hope that it will be useful,
 35  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 36  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 37  
  * GNU General Public License for more details.
 38  
  *
 39  
  * Contact details for copyright holder:
 40  
  *
 41  
  *     Tim Joyce <timj@paneris.org>
 42  
  *     http://paneris.org/
 43  
  *     68 Sandbanks Rd, Poole, Dorset. BH14 8BY. UK
 44  
  */
 45  
 
 46  
 package org.paneris.jammyjoes.shopping;
 47  
 
 48  
 import java.io.FileNotFoundException;
 49  
 import java.io.IOException;
 50  
 import java.util.Properties;
 51  
 
 52  
 import org.melati.util.InstantiationPropertyException;
 53  
 import org.melati.util.MelatiBugMelatiException;
 54  
 import org.melati.util.PropertiesUtils;
 55  
 
 56  
 /** 
 57  
  * The MelatiShoppingConfig provides configuration information for the Melati 
 58  
  * Shopping Interface 
 59  
  */
 60  
 
 61  
 public class MelatiShoppingConfig {
 62  
 
 63  0
   private Properties configuration = null;
 64  0
   private String ShoppingTrolleyProp = null;
 65  0
   private String ShoppingTrolleyItemProp = null;
 66  
   private static Class clazz;
 67  
   static {
 68  
     try {
 69  0
       clazz = Class.forName("org.paneris.jammyjoes.shopping.ShoppingTrolley");
 70  0
     } catch (ClassNotFoundException e) {
 71  0
       throw new MelatiBugMelatiException("Out of date Class.forName", e);
 72  0
     }
 73  0
   }
 74  
 
 75  
   /** 
 76  
    * Construct a MelatiShoppingConfig object.  if the propeties file is not found
 77  
    * default properties will be used
 78  
    *
 79  
    * @throws ShoppingConfigException - if there is an error loading the file
 80  
    */
 81  0
   public MelatiShoppingConfig() throws ShoppingConfigException {
 82  
 
 83  0
     String pref = clazz.getName() + ".";
 84  0
     ShoppingTrolleyProp = pref + "trolley";
 85  0
     ShoppingTrolleyItemProp = pref + "item";
 86  
 
 87  
     try {
 88  0
       configuration = PropertiesUtils.fromResource(clazz, pref + "properties");
 89  0
     } catch (FileNotFoundException e) {
 90  0
       System.err.println("Could not find properties file: " + e.toString());
 91  0
       configuration = new Properties();
 92  0
     } catch (IOException e) {
 93  0
       throw new ShoppingConfigException(e.toString());
 94  0
     }
 95  
 
 96  0
   }
 97  
 
 98  
   /** 
 99  
    * get a ShoppingTrolley Object as defined in the properties file 
 100  
    * if no definition is found, a default DefaultShoppingTrolley will be returned
 101  
    *
 102  
    * @return - a shopping trolley object as defined in the properties file 
 103  
    *
 104  
    * @throws InstantiationPropertyException - if we cannot instantiate the object
 105  
    */
 106  
   public ShoppingTrolley getShoppingTrolley() throws InstantiationPropertyException {
 107  0
     return (ShoppingTrolley) PropertiesUtils.instanceOfNamedClass(
 108  
       configuration,
 109  
       ShoppingTrolleyProp,
 110  
       "org.paneris.jammyjoes.shopping.ShoppingTrolley",
 111  
       "org.paneris.jammyjoes.shopping.JammyJoesShoppingTrolley");
 112  
   }
 113  
 
 114  
   /** 
 115  
    * get a ShoppingTrolleyItem Object as defined in the properties file 
 116  
    * if no definition is found, a default DefaultShoppingTrolleyItem will be 
 117  
    * returned
 118  
    *
 119  
    * @return - a shopping trolley item object as defined in the properties file 
 120  
    *
 121  
    * @throws InstantiationPropertyException - if we cannot instantiate the object
 122  
    */
 123  
   public ShoppingTrolleyItem getShoppingTrolleyItem() throws InstantiationPropertyException {
 124  0
     return (ShoppingTrolleyItem) PropertiesUtils.instanceOfNamedClass(
 125  
       configuration,
 126  
       ShoppingTrolleyItemProp,
 127  
       "org.paneris.jammyjoes.shopping.ShoppingTrolleyItem",
 128  
       "org.paneris.jammyjoes.shopping.JammyJoesShoppingTrolley");
 129  
   }
 130  
 
 131  
 }