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

COVERAGE SUMMARY FOR SOURCE FILE [ConfigEditorInputFactory.java]

nameclass, %method, %block, %line, %
ConfigEditorInputFactory.java0%   (0/1)0%   (0/9)0%   (0/174)0%   (0/45)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ConfigEditorInputFactory0%   (0/1)0%   (0/9)0%   (0/174)0%   (0/45)
ConfigEditorInputFactory (): void 0%   (0/1)0%   (0/3)0%   (0/1)
createElement (IMemento): IAdaptable 0%   (0/1)0%   (0/30)0%   (0/9)
getAdapterFactoryID (IMemento): String 0%   (0/1)0%   (0/4)0%   (0/1)
getDatasource (IMemento): IDAOFactory 0%   (0/1)0%   (0/15)0%   (0/6)
getExperiment (IMemento): Experiment 0%   (0/1)0%   (0/18)0%   (0/5)
getExperimentRun (IMemento): ExperimentRun 0%   (0/1)0%   (0/18)0%   (0/5)
getFactoryId (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getSensor (IMemento): Sensor 0%   (0/1)0%   (0/18)0%   (0/5)
saveState (IMemento, ConfigEditorInput): void 0%   (0/1)0%   (0/66)0%   (0/12)

1package de.uka.ipd.sdq.sensorframework.visualisation.editor;
2 
3import org.eclipse.core.runtime.IAdaptable;
4import org.eclipse.ui.IElementFactory;
5import org.eclipse.ui.IMemento;
6 
7import de.uka.ipd.sdq.sensorframework.SensorFrameworkDataset;
8import de.uka.ipd.sdq.sensorframework.entities.Experiment;
9import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun;
10import de.uka.ipd.sdq.sensorframework.entities.Sensor;
11import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory;
12 
13/**
14 * @author roman
15 *
16 */
17public class ConfigEditorInputFactory implements IElementFactory {
18 
19        /**
20         * Factory id. The workbench plug-in registers a factory by this name with
21         * the "org.eclipse.ui.elementFactories" extension point.
22         */
23        private static final String ID_FACTORY = "de.uka.ipd.sdq.sensorframework.visualisation.configEditorInputFactory"; 
24        
25        /** Tags */
26    private static final String DATASOURCE = "Datasource"; //$NON-NLS-1$
27    private static final String EXPERIMENT = "Experiment"; //$NON-NLS-1$
28    private static final String EXPERIMENT_RUN = "ExperimentRun"; //$NON-NLS-1$
29    private static final String SENSOR_NAME = "SensorName"; //$NON-NLS-1$
30    private static final String SENSOR_ID = "SensorId"; //$NON-NLS-1$
31 
32        private static final String ADAPTER_FACTORY_ID_ID = "AdpaterFactoryIDID";
33        
34        /* (non-Javadoc)
35         * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
36         */
37        public IAdaptable createElement(IMemento memento) {
38                ConfigEntry configEntry = null;
39                try
40                {
41                        configEntry =new ConfigEntry(
42                                getDatasource(memento),
43                                getExperimentRun(memento),
44                                getExperiment(memento), 
45                                getSensor(memento));
46                } catch(Exception e) {
47                        return null;
48                }
49                return new ConfigEditorInput(getAdapterFactoryID(memento),configEntry);
50        }
51 
52         private String getAdapterFactoryID(IMemento memento) {
53                // TODO Auto-generated method stub
54                return memento.getString(ADAPTER_FACTORY_ID_ID);
55        }
56 
57        /**
58     * Returns the element factory id for this class.
59     * 
60     * @return the element factory id
61     */
62    public static String getFactoryId() {
63        return ID_FACTORY;
64    }
65 
66    /**
67     * Saves the state of the given file editor input into the given memento.
68     *
69     * @param memento the storage area for element state
70     * @param input the file editor input
71     */
72    public static void saveState(IMemento memento, ConfigEditorInput input) {
73                for (ConfigEntry entry : input.getConfigEntrys()) {
74                        memento.putString(DATASOURCE, Long.toString(entry.getDatasource().
75                                        getID()));
76                        memento.putString(EXPERIMENT, Long.toString(entry.getExperiment()
77                                        .getExperimentID()));
78                        memento.putString(EXPERIMENT_RUN, Long.toString(entry.getExperimentRun()
79                                        .getExperimentRunID()));
80                        for (Sensor sensor : entry.getSensors()) {
81                                memento.putString(SENSOR_NAME, sensor.getSensorName());
82                                memento.putString(SENSOR_ID, sensor.getSensorID() + "");
83                        }
84                }
85                memento.putString(ADAPTER_FACTORY_ID_ID, input.getAdapterFactoryID());
86        }
87        
88    private Sensor getSensor(IMemento memento) {
89                String sensorId = memento.getString(SENSOR_ID);
90                if (sensorId == null)
91                        return null;
92 
93                IDAOFactory data = getDatasource(memento);
94                return data.createSensorDAO().get(Long.parseLong(sensorId));
95        }
96    
97    private ExperimentRun getExperimentRun(IMemento memento) {
98                String experimentRun = memento.getString(EXPERIMENT_RUN);
99                if (experimentRun == null)
100                        return null;
101                IDAOFactory data = getDatasource(memento);
102                return data.createExperimentRunDAO().get(Long.parseLong(experimentRun));
103        }
104 
105    private IDAOFactory getDatasource(IMemento memento) {
106                String datasource = memento.getString(DATASOURCE);
107                if (datasource == null)
108                        return null;
109                IDAOFactory data = SensorFrameworkDataset
110                                .singleton().getDataSourceByID(Long.parseLong(datasource));
111                return data;
112        }
113    
114    private Experiment getExperiment(IMemento memento) {
115                String experiment = memento.getString(EXPERIMENT);
116                if (experiment == null)
117                        return null;
118                IDAOFactory data = getDatasource(memento);
119                return data.createExperimentDAO().get(Long.parseLong(experiment));
120        }
121}

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