1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package de.fu_berlin.ties.context.sensor;
23
24 import de.fu_berlin.ties.ProcessingException;
25 import de.fu_berlin.ties.TiesConfiguration;
26 import de.fu_berlin.ties.util.Util;
27
28 /***
29 * Abstract implementation of the
30 * {@link de.fu_berlin.ties.context.sensor.Sensor} interface that stores a
31 * configuration and provides a factory method to initialize a set of sensors.
32 *
33 * @author Christian Siefkes
34 * @version $Revision: 1.2 $, $Date: 2004/07/08 08:45:33 $, $Author: siefkes $
35 */
36 public abstract class BaseSensor implements Sensor {
37
38 /***
39 * Factory method that initializes an array of sensors.
40 *
41 * @param classNames array of fully specified names of classes
42 * implementing the {@link Sensor} interface; each of them must provide
43 * a constructor that accepts a {@link TiesConfiguration} as single argument
44 * @param conf used to configure the sensors
45 * @return an array of newly created sensors
46 * @throws ProcessingException if an error occurred while creating the
47 * classifier
48 */
49 public static Sensor[] createSensors(final String[] classNames,
50 final TiesConfiguration conf) throws ProcessingException {
51 final Sensor[] result = new Sensor[classNames.length];
52
53
54 final Object[] params = new Object[] {conf};
55
56 for (int i = 0; i < result.length; i++) {
57 try {
58 result[i] = (Sensor) Util.createObject(
59 Class.forName(classNames[i]), params,
60 TiesConfiguration.class);
61 } catch (ClassNotFoundException cnfe) {
62
63 throw new ProcessingException(
64 "Cannot initialize sensor " + classNames[i],
65 cnfe);
66 } catch (InstantiationException ie) {
67
68 throw new ProcessingException(
69 "Cannot initialize sensor " + classNames[i],
70 ie);
71 }
72 }
73
74 return result;
75 }
76
77
78 /***
79 * The configuration used by this instance.
80 */
81 private final TiesConfiguration config;
82
83 /***
84 * Creates a new instance.
85 * @param conf the configuration to use
86 */
87 public BaseSensor(final TiesConfiguration conf) {
88 super();
89 config = conf;
90 }
91
92 /***
93 * Returns the configuration used by this instance.
94 * @return the configuration
95 */
96 public TiesConfiguration getConfig() {
97 return config;
98 }
99
100 }