1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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 private Properties configuration = null;
64 private String ShoppingTrolleyProp = null;
65 private String ShoppingTrolleyItemProp = null;
66 private static Class clazz;
67 static {
68 try {
69 clazz = Class.forName("org.paneris.jammyjoes.shopping.ShoppingTrolley");
70 } catch (ClassNotFoundException e) {
71 throw new MelatiBugMelatiException("Out of date Class.forName", e);
72 }
73 }
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 public MelatiShoppingConfig() throws ShoppingConfigException {
82
83 String pref = clazz.getName() + ".";
84 ShoppingTrolleyProp = pref + "trolley";
85 ShoppingTrolleyItemProp = pref + "item";
86
87 try {
88 configuration = PropertiesUtils.fromResource(clazz, pref + "properties");
89 } catch (FileNotFoundException e) {
90 System.err.println("Could not find properties file: " + e.toString());
91 configuration = new Properties();
92 } catch (IOException e) {
93 throw new ShoppingConfigException(e.toString());
94 }
95
96 }
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 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 return (ShoppingTrolleyItem) PropertiesUtils.instanceOfNamedClass(
125 configuration,
126 ShoppingTrolleyItemProp,
127 "org.paneris.jammyjoes.shopping.ShoppingTrolleyItem",
128 "org.paneris.jammyjoes.shopping.JammyJoesShoppingTrolley");
129 }
130
131 }