| 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.StateImpl; |
| 11 | import de.uka.ipd.sdq.sensorframework.entities.State; |
| 12 | import de.uka.ipd.sdq.sensorframework.entities.dao.IStateDAO; |
| 13 | |
| 14 | /** |
| 15 | * @author Ihssane El-Oudghiri |
| 16 | * @author Steffen Becker |
| 17 | * |
| 18 | * Data Access Object (DAO) for persistence of State Objects. |
| 19 | * |
| 20 | */ |
| 21 | public class FileStateDAO extends AbstractFileDAO<State> implements IStateDAO { |
| 22 | |
| 23 | public FileStateDAO(FileDAOFactory factory, IDGenerator idGen) { |
| 24 | super(factory,idGen,FileDAOFactory.STATE_FILE_NAME_PREFIX); |
| 25 | } |
| 26 | |
| 27 | public State addState(String p_stateliteral) { |
| 28 | State state = new StateImpl(this.factory); |
| 29 | state.setStateID(idGen.getNextStateID()); |
| 30 | state.setStateLiteral(p_stateliteral); |
| 31 | |
| 32 | this.putEntity(state); |
| 33 | |
| 34 | return state; |
| 35 | } |
| 36 | |
| 37 | public Collection<State> findByStateLiteral(String searchKey) { |
| 38 | Collection<State> result = new ArrayList<State>(); |
| 39 | for (State state : getAllEntities()) |
| 40 | if (state.getStateLiteral().equals(searchKey)) |
| 41 | result.add(state); |
| 42 | return Collections.unmodifiableCollection(result); |
| 43 | } |
| 44 | |
| 45 | public Collection<State> getStates() { |
| 46 | return Collections.unmodifiableCollection(getAllEntities()); |
| 47 | } |
| 48 | |
| 49 | public void removeState(State state, boolean doCascade) { |
| 50 | this.removeEntity(state, doCascade); |
| 51 | } |
| 52 | } |