001 package dk.deepthought.sidious.supportsystem;
002
003 import java.io.FileInputStream;
004 import java.io.IOException;
005 import java.util.Properties;
006
007 import org.apache.commons.logging.Log;
008 import org.apache.commons.logging.LogFactory;
009
010 /**
011 * This class represent systemwide constants. All constants can supposably be
012 * collected from a properties file.
013 * <p>
014 * This implementation facilitates the replacement of specific sensor id's for
015 * testing purposes.
016 *
017 * @author Deepthought
018 *
019 */
020 public final class SystemSettings {
021
022 private static final Properties properties = readProperties();
023
024 /**
025 * Logger for this class
026 */
027 private static final Log logger = LogFactory.getLog(SystemSettings.class);
028
029 /**
030 * The <code>SuperLinkID</code> of the CO2 sensor
031 */
032 private static SuperLinkID co2ID = new SuperLinkID(properties.getProperty("co2"));
033
034 /**
035 * The <code>SuperLinkID</code> of the humidity sensor
036 */
037 private static SuperLinkID humidityID = new SuperLinkID(properties.getProperty("humidity"));
038
039 /**
040 * The <code>SuperLinkID</code> of the light irradiance sensor
041 */
042 private static SuperLinkID irradianceID = new SuperLinkID(properties.getProperty("irradiance"));
043
044 /**
045 * The <code>SuperLinkID</code> of the outside humidity sensor
046 */
047 private static SuperLinkID outsideHumidityID = new SuperLinkID(properties.getProperty("outsidehumidity"));
048
049 /**
050 * The <code>SuperLinkID</code> of the outside temperature sensor
051 */
052 private static SuperLinkID outsideTemperatureID = new SuperLinkID(
053 properties.getProperty("outsidetemperature"));
054
055 /**
056 * The <code>SuperLinkID</code> of the temperature sensor
057 */
058 private static SuperLinkID temperatureID = new SuperLinkID(properties.getProperty("temperature"));
059
060 /**
061 * The <code>SuperLinkID</code> of the time sensor
062 */
063 private static SuperLinkID timeID = new SuperLinkID(properties.getProperty("time"));
064
065 /**
066 * The systemwide timestep in minutes
067 */
068 private static int TIMESTEP = Integer.parseInt(properties.getProperty("TIMESTEP"));
069
070 /**
071 * Used when system is set to debug mode
072 */
073 private static boolean testMode = false;
074
075 /**
076 * Returns the <code>SuperLinkID</code> of the CO2 sensor.
077 *
078 * @return id of the CO2 sensor
079 */
080 public static SuperLinkID getCO2ID() {
081 return co2ID;
082 }
083
084 /**
085 * Returns the id of the CO2 setpoint.
086 *
087 * @return the CO2 setpoint id
088 */
089 public static SuperLinkID getCO2SetPointID() {
090 return new SuperLinkID(properties.getProperty("co2_setpoint"));
091 }
092
093 /**
094 * Returns the id of the heater setpoint.
095 *
096 * @return the heater setpoint id
097 */
098 public static SuperLinkID getHeaterSetPointID() {
099 return new SuperLinkID(properties.getProperty("heater_setpoint"));
100 }
101
102 /**
103 * Returns the <code>SuperLinkID</code> of the humidity sensor.
104 *
105 * @return id of the humidity sensor
106 */
107 public static SuperLinkID getHumidityID() {
108 return humidityID;
109 }
110
111 /**
112 * Returns the <code>SuperLinkID</code> of the light irradiance sensor.
113 *
114 * @return id of the outside irradiance sensor
115 */
116 public static SuperLinkID getIrradianceID() {
117 return irradianceID;
118 }
119
120 /**
121 * Returns the <code>SuperLinkID</code> of the outside humidity sensor.
122 *
123 * @return id of the outside humidity sensor
124 */
125 public static SuperLinkID getOutsideHumidityID() {
126 return outsideHumidityID;
127 }
128
129 /**
130 * Returns the <code>SuperLinkID</code> of the outside temperature sensor.
131 *
132 * @return id of the outside temperature sensor
133 */
134 public static SuperLinkID getOutsideTemperatureID() {
135 return outsideTemperatureID;
136 }
137
138 /**
139 * Returns the id of the screen setpoint.
140 *
141 * @return the screen setpoint id
142 */
143 public static SuperLinkID getScreenSetPointID() {
144 return new SuperLinkID(properties.getProperty("screen_setpoint"));
145 }
146
147 /**
148 * Returns the <code>SuperLinkID</code> of the temperature sensor.
149 *
150 * @return id of the temperature sensor
151 */
152 public static SuperLinkID getTemperatureID() {
153 return temperatureID;
154 }
155
156 /**
157 * @return the timeID
158 */
159 public static SuperLinkID getTimeID() {
160 return timeID;
161 }
162
163 /**
164 * Returns the systemwide time step.
165 *
166 * @return the timestep
167 */
168 public static int getTimestep() {
169 return TIMESTEP;
170 }
171
172 /**
173 * Returns the id of the window setpoint.
174 *
175 * @return the window setpoint id
176 */
177 public static SuperLinkID getWindowSetPointID() {
178 return new SuperLinkID(properties.getProperty("window_setpoint"));
179 }
180
181 /**
182 * @param co2ID
183 * the co2ID to set
184 */
185 public static void setCO2ID(SuperLinkID co2ID) {
186 SystemSettings.co2ID = co2ID;
187 }
188
189 /**
190 * @param humidityID
191 * the humidityID to set
192 */
193 public static void setHumidityID(SuperLinkID humidityID) {
194 SystemSettings.humidityID = humidityID;
195 }
196
197 /**
198 * @param irradianceID
199 * the irradianceID to set
200 */
201 public static void setIrradianceID(SuperLinkID irradianceID) {
202 SystemSettings.irradianceID = irradianceID;
203 }
204
205 /**
206 * @param outsideHumidityID
207 * the outsideHumidityID to set
208 */
209 public static void setOutsideHumidityID(SuperLinkID outsideHumidityID) {
210 SystemSettings.outsideHumidityID = outsideHumidityID;
211 }
212
213 /**
214 * @param outsideTemperatureID
215 * the outsideTemperatureID to set
216 */
217 public static void setOutsideTemperatureID(SuperLinkID outsideTemperatureID) {
218 SystemSettings.outsideTemperatureID = outsideTemperatureID;
219 }
220
221 /**
222 * @param temperatureID
223 * the temperatureID to set
224 */
225 public static void setTemperatureID(SuperLinkID temperatureID) {
226 SystemSettings.temperatureID = temperatureID;
227 }
228
229 /**
230 * @param timeID
231 * the timeID to set
232 */
233 public static void setTimeID(SuperLinkID timeID) {
234 SystemSettings.timeID = timeID;
235 }
236
237 /**
238 * Tells whether or not the system is in testMode.
239 * @return <code>true</code> if system is in test mode.
240 */
241 public static boolean isTestMode() {
242 return testMode;
243 }
244
245 /**
246 * Sets whether or not test mode is enabled.
247 * @param testMode true to enable test mode
248 */
249 public static void setTestMode(boolean testMode) {
250 SystemSettings.testMode = testMode;
251 }
252
253
254 /**
255 * Method returns the <code>Properties</code> object of this.
256 *
257 * @return the properties of this
258 */
259 private static Properties readProperties() {
260 String propertiesFileName = "system.properties";
261 Properties properties = new Properties();
262 try {
263 FileInputStream in = new FileInputStream(propertiesFileName);
264 properties.load(in);
265 in.close();
266 } catch (IOException e) {
267 logger.error("readProperties(String prefixName=" + propertiesFileName
268 + ") - IOException, properties not read", e);
269 if (logger.isDebugEnabled()) {
270 logger.debug("Empty properties returned");
271 }
272 }
273 return properties;
274 }
275
276 }
|