1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.sensorframework.dao.file; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.Collection; |
8 | import java.util.Collections; |
9 | |
10 | import de.uka.ipd.sdq.sensorframework.dao.file.entities.ScalabilitySensorImpl; |
11 | import de.uka.ipd.sdq.sensorframework.dao.file.entities.StateSensorImpl; |
12 | import de.uka.ipd.sdq.sensorframework.dao.file.entities.TimeSpanSensorImpl; |
13 | import de.uka.ipd.sdq.sensorframework.entities.ScalabilitySensor; |
14 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
15 | import de.uka.ipd.sdq.sensorframework.entities.State; |
16 | import de.uka.ipd.sdq.sensorframework.entities.StateSensor; |
17 | import de.uka.ipd.sdq.sensorframework.entities.TimeSpanSensor; |
18 | import de.uka.ipd.sdq.sensorframework.entities.dao.ISensorDAO; |
19 | |
20 | /** |
21 | * @author Ihssane El-Oudghiri |
22 | * @author Steffen Becker |
23 | * |
24 | * Data Access Object (DAO) for persistence of Sensor Objects. |
25 | * |
26 | */ |
27 | public class FileSensorDAO extends AbstractFileDAO<Sensor> implements ISensorDAO { |
28 | |
29 | public FileSensorDAO(FileDAOFactory factory, IDGenerator idGen) { |
30 | super(factory,idGen,FileDAOFactory.SENSOR_FILE_NAME_PREFIX); |
31 | } |
32 | |
33 | public StateSensor addStateSensor(State p_initialstate, String p_sensorname) { |
34 | StateSensor stsen = new StateSensorImpl(factory); |
35 | stsen.setInitialState(p_initialstate); |
36 | stsen.setSensorName(p_sensorname); |
37 | stsen.setSensorID(idGen.getNextSensorID()); |
38 | |
39 | this.putEntity(stsen); |
40 | |
41 | return stsen; |
42 | } |
43 | |
44 | public TimeSpanSensor addTimeSpanSensor(String p_sensorname) { |
45 | TimeSpanSensor result = new TimeSpanSensorImpl(factory); |
46 | result.setSensorID(idGen.getNextSensorID()); |
47 | result.setSensorName(p_sensorname); |
48 | |
49 | this.putEntity(result); |
50 | |
51 | return result; |
52 | } |
53 | |
54 | public ScalabilitySensor addScalabilitySensor(String p_sensorname) { |
55 | ScalabilitySensor result = new ScalabilitySensorImpl(factory); |
56 | result.setSensorID(idGen.getNextSensorID()); |
57 | result.setSensorName(p_sensorname); |
58 | |
59 | this.putEntity(result); |
60 | |
61 | return result; |
62 | } |
63 | |
64 | public Collection<Sensor> findBySensorName(String searchKey) { |
65 | Collection<Sensor> result = new ArrayList<Sensor>(); |
66 | for (Sensor sen : getAllEntities()) |
67 | if (sen.getSensorName().equals(searchKey)) |
68 | result.add(sen); |
69 | |
70 | return Collections.unmodifiableCollection(result); |
71 | } |
72 | |
73 | public Collection<Sensor> getSensors() { |
74 | return this.getAllEntities(); |
75 | } |
76 | |
77 | public void removeSensor(Sensor sensor, boolean doCascade) { |
78 | this.removeEntity(sensor, doCascade); |
79 | } |
80 | |
81 | |
82 | } |