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 java.io.File;
25 import java.io.IOException;
26
27 import de.fu_berlin.ties.ProcessingException;
28 import de.fu_berlin.ties.TiesConfiguration;
29 import de.fu_berlin.ties.text.TokenizerFactory;
30 import de.fu_berlin.ties.util.Util;
31
32 /***
33 * Abstract implementation of the
34 * {@link de.fu_berlin.ties.context.sensor.Sensor} interface that stores a
35 * configuration and provides a factory method to initialize a set of sensors.
36 *
37 * @author Christian Siefkes
38 * @version $Revision: 1.7 $, $Date: 2006/10/21 16:04:06 $, $Author: siefkes $
39 */
40 public abstract class BaseSensor implements Sensor {
41
42 /***
43 * Factory method that initializes an array of sensors.
44 *
45 * @param classNames array of fully specified names of classes
46 * implementing the {@link Sensor} interface; each of them must provide
47 * a constructor that accepts a {@link TiesConfiguration} as single argument
48 * @param conf used to configure the sensors
49 * @return an array of newly created sensors
50 * @throws ProcessingException if an error occurred while creating the
51 * classifier
52 */
53 public static Sensor[] createSensors(final String[] classNames,
54 final TiesConfiguration conf) throws ProcessingException {
55 final Sensor[] result = new Sensor[classNames.length];
56
57
58 final Object[] params = new Object[] {conf};
59
60 for (int i = 0; i < result.length; i++) {
61 try {
62 result[i] = (Sensor) Util.createObject(
63 Class.forName(classNames[i]), params,
64 TiesConfiguration.class);
65 } catch (ClassNotFoundException cnfe) {
66
67 throw new ProcessingException(
68 "Cannot initialize sensor " + classNames[i],
69 cnfe);
70 } catch (InstantiationException ie) {
71
72 throw new ProcessingException(
73 "Cannot initialize sensor " + classNames[i],
74 ie);
75 }
76 }
77
78 return result;
79 }
80
81
82 /***
83 * The configuration used by this instance.
84 */
85 private final TiesConfiguration config;
86
87 /***
88 * Creates a new instance.
89 * @param conf the configuration to use
90 */
91 public BaseSensor(final TiesConfiguration conf) {
92 super();
93 config = conf;
94 }
95
96 /***
97 * Returns the configuration used by this instance.
98 * @return the configuration
99 */
100 public TiesConfiguration getConfig() {
101 return config;
102 }
103
104 /***
105 * {@inheritDoc} The default implementation does nothing.
106 */
107 public void initDocument(final File filename,
108 final TokenizerFactory tFactory)
109 throws ProcessingException, IOException {
110
111 }
112
113 }