EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.sensorframework]

COVERAGE SUMMARY FOR SOURCE FILE [SensorFrameworkDataset.java]

nameclass, %method, %block, %line, %
SensorFrameworkDataset.java100% (1/1)56%  (5/9)22%  (47/211)25%  (12,4/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SensorFrameworkDataset100% (1/1)56%  (5/9)22%  (47/211)25%  (12,4/49)
getDataSourceByID (long): IDAOFactory 0%   (0/1)0%   (0/21)0%   (0/4)
reload (): void 0%   (0/1)0%   (0/53)0%   (0/13)
removeAllDataSources (): void 0%   (0/1)0%   (0/13)0%   (0/3)
removeDataSource (IDAOFactory): void 0%   (0/1)0%   (0/8)0%   (0/3)
addDataSource (IDAOFactory): void 100% (1/1)27%  (25/94)25%  (4,4/18)
<static initializer> 100% (1/1)100% (5/5)100% (2/2)
SensorFrameworkDataset (): void 100% (1/1)100% (11/11)100% (4/4)
getDataSources (): Collection 100% (1/1)100% (4/4)100% (1/1)
singleton (): SensorFrameworkDataset 100% (1/1)100% (2/2)100% (1/1)

1package de.uka.ipd.sdq.sensorframework;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Collections;
6 
7import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory;
8 
9/**
10 * Provides access to the singleton dataset of the SensorFramework. Used to display
11 * all datasources in the SimuBench Perspective.
12 * 
13 * @author Steffen Becker
14 * @author groenda
15 */
16public class SensorFrameworkDataset {
17        private static SensorFrameworkDataset singleton = new SensorFrameworkDataset();//why not final?
18        private ArrayList<IDAOFactory> datasources = new ArrayList<IDAOFactory>();
19        private long nextID = 1;
20 
21        private SensorFrameworkDataset() {
22        }
23 
24        /**
25         * @return the one central instance containing all datasources.
26         */
27        public static SensorFrameworkDataset singleton() {
28                return singleton;
29        }
30 
31        /**
32         * Returns all data sources in the dataset.
33         * 
34         * @return datasources.
35         */
36        public synchronized Collection<IDAOFactory> getDataSources() {
37                return Collections.unmodifiableCollection(datasources);
38        }
39 
40        /**
41         * Retrieve a datasource by its dynamic numeric identifier.
42         * 
43         * @param id
44         *            id of the datasource.
45         * @return datasource.
46         */
47        public synchronized IDAOFactory getDataSourceByID(long id) {
48                for (IDAOFactory f : datasources)
49                        if (f.getID() == id)
50                                return f;
51                return null;
52        }
53 
54        /**
55         * Add a provided datasource.
56         * 
57         * @param dataSource
58         *            the datasource.
59         */
60        public synchronized void addDataSource(IDAOFactory dataSource) {
61                for (IDAOFactory f : datasources) {
62                        if (f.getID() == dataSource.getID())
63                                throw new RuntimeException(
64                                                "Attemped to add Datasource (of a type inherting from IDAOFactory) " +
65                                                "with an ID already existing in the Sensorframework Dataset.");
66                        if (f.getID() == nextID
67                                        && dataSource.getID() == IDAOFactory.ID_NOT_SET){//why is it an "&&"?
68                                throw new RuntimeException(
69                                                "Conflict of IDs occurred when attemping to add a new datasource to the Sensorframework Dataset.");
70                        }
71                }
72 
73                datasources.add(dataSource);
74                if (dataSource.getID() == IDAOFactory.ID_NOT_SET) {
75                        dataSource.setID(nextID);
76                        nextID += 1;
77                } else {
78                        if (dataSource.getID() >= nextID) {
79                                // reset nextID completely
80                                this.nextID = Long.MIN_VALUE;
81                                for (IDAOFactory f : datasources) {
82                                        if (f.getID() >= nextID)
83                                                this.nextID = f.getID() + 1;
84                                }
85                        }
86                }
87        }
88 
89        /**
90         * Removes a datasource from the current Dataset.
91         * 
92         * @param factory
93         *            the datasource itself to remove.
94         */
95        public synchronized void removeDataSource(IDAOFactory factory) {
96                factory.finalizeAndClose();
97                datasources.remove(factory);//this method returns a boolean - the calling method should do so, too
98        }
99 
100        /**
101         * Removes all data sources from the current data set.
102         */
103        public synchronized void removeAllDataSources() {
104                while (datasources.size() > 0) {
105                        removeDataSource(datasources.get(0));
106                }
107        }
108 
109        /**
110         * Reloads all known datasources. Throws runtime exeception if some
111         * datasources are faulty.
112         */
113        public synchronized void reload() {
114                String errorMessage = "";
115                boolean failed = false;
116                for (IDAOFactory f : datasources) {
117                        try {
118                                f.reload();
119                        } catch (Exception e) {
120                                failed = true;
121                                errorMessage += ">" + e.getMessage() + "< ";
122                                this.removeDataSource(f);
123                        }
124                }
125                if (failed) {
126                        throw new RuntimeException(
127                                        "Some Datasources failed to reload. Please see Error Log for details. Details: "
128                                                        + errorMessage);
129                }
130        }
131}

[all classes][de.uka.ipd.sdq.sensorframework]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov