| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MelatiShoppingConfig |
|
| 2.0;2 |
| 1 | /* | |
| 2 | * $Source: /usr/cvsroot/MelatiShopping/src/main/java/org/paneris/melati/shopping/MelatiShoppingConfig.java,v $ | |
| 3 | * $Revision: 1.9 $ | |
| 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 if you would like | |
| 30 | * 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/~timj/ | |
| 43 | * 68 Sandbanks Rd, Poole, Dorset. BH14 8BY. UK | |
| 44 | */ | |
| 45 | ||
| 46 | package org.paneris.melati.shopping; | |
| 47 | ||
| 48 | import java.io.FileNotFoundException; | |
| 49 | import java.io.IOException; | |
| 50 | import java.util.Properties; | |
| 51 | ||
| 52 | import org.melati.util.MelatiBugMelatiException; | |
| 53 | import org.melati.util.PropertiesUtils; | |
| 54 | import org.melati.util.InstantiationPropertyException; | |
| 55 | ||
| 56 | ||
| 57 | /** | |
| 58 | * The MelatiShoppingConfig provides configuration information for the Melati | |
| 59 | * Shopping Interface. | |
| 60 | */ | |
| 61 | ||
| 62 | public class MelatiShoppingConfig { | |
| 63 | ||
| 64 | 0 | private Properties configuration = null; |
| 65 | 0 | private String ShoppingTrolleyProp = null; |
| 66 | 0 | private String ShoppingTrolleyItemProp = null; |
| 67 | private static Class clazz; | |
| 68 | static { | |
| 69 | try { | |
| 70 | 0 | clazz = Class.forName("org.paneris.melati.shopping.ShoppingTrolley"); |
| 71 | } | |
| 72 | 0 | catch (ClassNotFoundException e) { |
| 73 | 0 | throw new MelatiBugMelatiException("Out of date Class.forName", e); |
| 74 | 0 | } |
| 75 | 0 | } |
| 76 | ||
| 77 | /** | |
| 78 | * Construct a MelatiShoppingConfig object. | |
| 79 | * If the propeties file is not found default properties will be used. | |
| 80 | * | |
| 81 | * @throws ShoppingConfigException - if there is an error loading the file | |
| 82 | */ | |
| 83 | 0 | public MelatiShoppingConfig() throws ShoppingConfigException { |
| 84 | ||
| 85 | 0 | String pref = clazz.getName() + "."; |
| 86 | 0 | ShoppingTrolleyProp = pref + "trolley"; |
| 87 | 0 | ShoppingTrolleyItemProp = pref + "item"; |
| 88 | ||
| 89 | try { | |
| 90 | 0 | configuration = |
| 91 | PropertiesUtils.fromResource(clazz, pref + "properties"); | |
| 92 | } | |
| 93 | 0 | catch (FileNotFoundException e) { |
| 94 | 0 | System.err.println("Could not find properties file: " + e.toString()); |
| 95 | 0 | configuration = new Properties(); |
| 96 | } | |
| 97 | 0 | catch (IOException e) { |
| 98 | 0 | throw new ShoppingConfigException(e.toString()); |
| 99 | 0 | } |
| 100 | ||
| 101 | 0 | } |
| 102 | ||
| 103 | /** | |
| 104 | * Get a ShoppingTrolley Object as defined in the properties file. | |
| 105 | * If no definition is found, a default DefaultShoppingTrolley | |
| 106 | * will be returned. | |
| 107 | * | |
| 108 | * @return - a shopping trolley object as defined in the properties file | |
| 109 | * | |
| 110 | * @throws InstantiationPropertyException if we cannot instantiate the object | |
| 111 | */ | |
| 112 | public org.paneris.melati.shopping.ShoppingTrolley getShoppingTrolley() | |
| 113 | throws InstantiationPropertyException { | |
| 114 | 0 | return (org.paneris.melati.shopping.ShoppingTrolley) |
| 115 | PropertiesUtils.instanceOfNamedClass( | |
| 116 | configuration, ShoppingTrolleyProp, | |
| 117 | "org.paneris.melati.shopping.ShoppingTrolley", | |
| 118 | "org.paneris.melati.shopping.DefaultShoppingTrolley"); | |
| 119 | } | |
| 120 | ||
| 121 | ||
| 122 | /** | |
| 123 | * Get a ShoppingTrolleyItem Object as defined in the properties file. | |
| 124 | * If no definition is found, a default DefaultShoppingTrolleyItem will be | |
| 125 | * returned | |
| 126 | * | |
| 127 | * @return - a shopping trolley item object as defined in the properties file | |
| 128 | * | |
| 129 | * @throws InstantiationPropertyException if we cannot instantiate the object | |
| 130 | */ | |
| 131 | public org.paneris.melati.shopping.ShoppingTrolleyItem | |
| 132 | getShoppingTrolleyItem() | |
| 133 | throws InstantiationPropertyException { | |
| 134 | 0 | return (org.paneris.melati.shopping.ShoppingTrolleyItem) |
| 135 | PropertiesUtils.instanceOfNamedClass( | |
| 136 | configuration, ShoppingTrolleyItemProp, | |
| 137 | "org.paneris.melati.shopping.ShoppingTrolleyItem", | |
| 138 | "org.paneris.melati.shopping.DefaultShoppingTrolleyItem"); | |
| 139 | } | |
| 140 | ||
| 141 | } |