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

COVERAGE SUMMARY FOR SOURCE FILE [SensorFrameworkPluginActivator.java]

nameclass, %method, %block, %line, %
SensorFrameworkPluginActivator.java100% (1/1)80%  (4/5)67%  (150/225)70%  (39/56)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SensorFrameworkPluginActivator100% (1/1)80%  (4/5)67%  (150/225)70%  (39/56)
getDefault (): SensorFrameworkPluginActivator 0%   (0/1)0%   (0/2)0%   (0/1)
start (BundleContext): void 100% (1/1)60%  (80/134)66%  (21/32)
stop (BundleContext): void 100% (1/1)74%  (54/73)72%  (13/18)
SensorFrameworkPluginActivator (): void 100% (1/1)100% (3/3)100% (2/2)
log (int, String, Throwable): void 100% (1/1)100% (13/13)100% (3/3)

1package de.uka.ipd.sdq.sensorframework;
2 
3 
4import java.io.DataInputStream;
5import java.io.DataOutputStream;
6import java.io.File;
7import java.io.FileInputStream;
8import java.io.FileOutputStream;
9import java.util.Collection;
10 
11import org.eclipse.core.runtime.IConfigurationElement;
12import org.eclipse.core.runtime.IExtensionRegistry;
13import org.eclipse.core.runtime.IStatus;
14import org.eclipse.core.runtime.Platform;
15import org.eclipse.core.runtime.Plugin;
16import org.eclipse.core.runtime.Status;
17import org.osgi.framework.BundleContext;
18 
19import de.uka.ipd.sdq.sensorframework.adapter.AdapterRegistry;
20import de.uka.ipd.sdq.sensorframework.adapter.IAdapterFactory;
21import de.uka.ipd.sdq.sensorframework.dao.memory.MemoryDAOFactory;
22import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory;
23import de.uka.ipd.sdq.sensorframework.filter.FilteredCollectionRegistry;
24import de.uka.ipd.sdq.sensorframework.filter.IFilteredCollectionFactory;
25 
26/**
27 * The activator class controls the plug-in life cycle
28 * @author Roman Andrej
29 * @author Steffen Becker
30 
31 */
32public class SensorFrameworkPluginActivator extends Plugin {
33 
34        /** The plug-in ID. */
35        public static final String PLUGIN_ID = "de.uka.ipd.sdq.sensorframework";
36        
37        /** EPID - Filter extension Point ID. */
38        private static final String ADAPTER_EPID = "de.uka.ipd.sdq.sensorframework.adapter";
39        
40        /** EPID - Filter extension Point ID. */
41        private static final String FILTER_EPID = "de.uka.ipd.sdq.sensorframework.filter";
42 
43        /** The shared instance. */
44        private static SensorFrameworkPluginActivator plugin;
45        
46        /** The constructor. */
47        public SensorFrameworkPluginActivator() {
48        }
49 
50        /* (non-Javadoc)
51         * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
52         */
53        @Override
54        public void start(BundleContext context) throws Exception {
55                super.start(context);
56                plugin = this;
57                IExtensionRegistry registry = Platform.getExtensionRegistry();
58 
59                for (IConfigurationElement configurationElement : registry
60                                .getConfigurationElementsFor(ADAPTER_EPID)) {
61 
62                        IAdapterFactory factory = (IAdapterFactory) configurationElement
63                                        .createExecutableExtension("class");
64                        AdapterRegistry.singleton().addAdapterFactory(factory);
65                }
66 
67                for (IConfigurationElement configurationElement : registry
68                                .getConfigurationElementsFor(FILTER_EPID)) {
69 
70                        IFilteredCollectionFactory factory = (IFilteredCollectionFactory) configurationElement
71                                        .createExecutableExtension("class");
72                        String filterName = configurationElement
73                                        .getAttribute("displayName");
74                        FilteredCollectionRegistry.singleton().addFilteredCollectionFactory(filterName, factory);
75                }
76 
77                try {
78                        File file = context.getDataFile(PLUGIN_ID);
79                        FileInputStream fis = new FileInputStream(file);
80                        DataInputStream dos = new DataInputStream(fis);
81                        while (fis.available() > 0) {
82                                long id = dos.readLong();
83                                String className = dos.readUTF();
84                                String config = dos.readUTF();
85 
86                                IDAOFactory factory = (IDAOFactory) Class.forName(className)
87                                                .getConstructor(String.class).newInstance(config);
88                                factory.setID((int) id);
89                                SensorFrameworkDataset.singleton().addDataSource(factory);
90                        }
91                } catch (Exception e) {
92                        log(IStatus.ERROR, "Restoring Dataset Configuration failed. Resetting configuration...", e);
93                        if (SensorFrameworkDataset.singleton().getDataSources().size() == 0)
94                                SensorFrameworkDataset.singleton().addDataSource(
95                                                new MemoryDAOFactory(0));
96                }
97        }
98 
99        /* (non-Javadoc)
100         * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
101         */
102        @Override
103        public void stop(BundleContext context) throws Exception {
104                plugin = null;
105                File f = context.getDataFile("de.uka.ipd.sdq.sensorframework");
106                try {
107                        f.delete();
108                        DataOutputStream dos = new DataOutputStream(new FileOutputStream(f));
109                        Collection<IDAOFactory> sources = SensorFrameworkDataset.singleton().getDataSources();
110                        for (IDAOFactory source : sources) {
111                                try {
112                                        source.finalizeAndClose();
113                                } catch (Exception e) {
114                                        log(IStatus.ERROR, "Failed to close datasource with ID "+source.getID(),e);
115                                }
116                                dos.writeLong(source.getID());
117                                dos.writeUTF(source.getClass().getName());
118                                 dos.writeUTF(source.getPersistendInfo());
119                        }
120                        dos.close();
121                } catch (Exception e) {
122                        log(IStatus.ERROR, "Saving Dataset Configuration failed.",e);
123                        f.deleteOnExit();
124                }
125                super.stop(context);
126        }
127        
128        /**
129         * Returns the shared instance
130         *
131         * @return the shared instance
132         */
133        public static SensorFrameworkPluginActivator getDefault() {
134                return plugin;
135        }
136        
137        public static void log(int severity, String message, Throwable t) {
138                if (plugin != null) {
139                        plugin.getLog().log(new Status(severity,PLUGIN_ID,message,t));
140                }
141        }
142}

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