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

COVERAGE SUMMARY FOR SOURCE FILE [ExtensionHelper.java]

nameclass, %method, %block, %line, %
ExtensionHelper.java0%   (0/1)0%   (0/10)0%   (0/252)0%   (0/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ExtensionHelper0%   (0/1)0%   (0/10)0%   (0/252)0%   (0/53)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/3)
ExtensionHelper (): void 0%   (0/1)0%   (0/3)0%   (0/1)
loadAnalysisExtensions (): IExtension [] 0%   (0/1)0%   (0/5)0%   (0/2)
loadAnalysisExtensions (DSEConstantsContainer$QualityAttribute): List 0%   (0/1)0%   (0/37)0%   (0/8)
loadAnalysisExtensions (String): List 0%   (0/1)0%   (0/51)0%   (0/10)
loadExecutableAttribute (IConfigurationElement, String): Object 0%   (0/1)0%   (0/4)0%   (0/1)
loadExtension (String): Collection 0%   (0/1)0%   (0/43)0%   (0/8)
loadQualityAttributeDimension (IExtension): List 0%   (0/1)0%   (0/42)0%   (0/10)
loadStringAttribute (IExtension, String, String): String 0%   (0/1)0%   (0/32)0%   (0/6)
loadSupportedQualityAttributes (IExtension): DSEConstantsContainer$QualityAtt... 0%   (0/1)0%   (0/31)0%   (0/5)

1package de.uka.ipd.sdq.dsexplore.helper;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6import java.util.Vector;
7 
8import org.apache.log4j.Logger;
9import org.eclipse.core.runtime.CoreException;
10import org.eclipse.core.runtime.IConfigurationElement;
11import org.eclipse.core.runtime.IExtension;
12import org.eclipse.core.runtime.Platform;
13 
14import de.uka.ipd.sdq.dsexplore.analysis.IAnalysisQualityAttributeDeclaration;
15import de.uka.ipd.sdq.dsexplore.launch.DSEConstantsContainer.QualityAttribute;
16import de.uka.ipd.sdq.dsexplore.qml.contracttype.QMLContractType.Dimension;
17 
18public class ExtensionHelper {
19        
20        /** Logger for log4j. */
21        private static Logger logger = 
22                Logger.getLogger("de.uka.ipd.sdq.dsexplore");
23        
24        /**
25         * returns all found extensions for this id. 
26         * @param id
27         * @return
28         * @throws CoreException
29         */
30        public static Collection<Object> loadExtension(String id) throws CoreException {
31                /* To load an extension, you just need to access the registry (through an instance of IExtensionRegistry) from the platform (through the aptly name Platform object), then inquire for the extension points that the plug-in is interested in. The platform returns an IExtensionPoint object.
32 
33                IExtensionPoint returns an array of IConfigurationElement objects, which represent the extension tags in plugin.xml. For each plug-in that implements the extension point, you'll receive an IConfigurationElement. IConfigurationElement offers methods such as getChildren() and getAttribute(), to retrieve the data from the XML markup. Last but not least, createExecutableExtension() returns a Java class that implements the extension. It takes the name of the Java class from an attribute in the XML markup.
34                */
35                IConfigurationElement[] ep = Platform.getExtensionRegistry().getConfigurationElementsFor(id);
36                
37                Collection<Object> result = null;
38                
39                if (ep.length == 0){
40                        //Error: No extension found
41                        logger.error("Error: No Extension "+id+" found");
42                } else {
43                        result = new Vector<Object>();
44                        for (int i = 0; i < ep.length; i++) {
45                                result.add(ep[i].createExecutableExtension("delegate"));
46                        }
47                }
48                return result;
49        }
50        
51        /**
52         * Loads all extensions which extends the
53         * "de.uka.ipd.sdq.dsexplore.analysis" extension point.
54         * 
55         * @return all analysis method extensions
56         */
57        public static IExtension[] loadAnalysisExtensions() {
58                return Platform.getExtensionRegistry().getExtensionPoint(
59                                "de.uka.ipd.sdq.dsexplore.analysis").getExtensions();
60        }
61        
62 
63        /**
64         * Given an {@link IExtension}, this methods returns the content of the
65         * specified String attribute.
66         * 
67         * @param extension
68         * @param configurationElement
69         * @param attributeName
70         * @return the attribute content; null if the specified attribute does not
71         *         exist.
72         */
73        public static String loadStringAttribute(IExtension extension,
74                        String configurationElement, String attributeName) {
75                IConfigurationElement[] elements = extension.getConfigurationElements();
76                for (IConfigurationElement element : elements) {
77                        if (element.getName().equals(configurationElement)) {
78                                String attribute = element.getAttribute(attributeName);
79                                return attribute;
80                        }
81                }
82 
83                return null;
84        }
85        
86        /**
87         * TODO: Method obsolete!?
88         * 
89         * Given an {@link IExtension}, this method returns an new instance of the
90         * executable extension identified by the specified attribute.
91         * 
92         * @param extension
93         * @param configurationElement
94         * @param attributeName
95         * @return a class instance; null if the passed attribute does not exist.
96         * @throws CoreException
97         */
98        public static Object loadExecutableAttribute(IConfigurationElement element,
99                        String attributeName) throws CoreException {
100 
101                return element.createExecutableExtension(attributeName);
102        }
103 
104        /**
105         * Loads all extensions which extends the
106         * "de.uka.ipd.sdq.dsexplore.analysis" extension point and which specify the given quality attribute.
107         * 
108         * @return all analysis method extensions
109         */
110        public static List<IExtension> loadAnalysisExtensions(QualityAttribute attribute) {
111                IExtension[] exts = Platform.getExtensionRegistry().getExtensionPoint(
112                "de.uka.ipd.sdq.dsexplore.analysis").getExtensions();
113                
114                List<IExtension> results = new ArrayList<IExtension>();
115                
116                for (IExtension iExtension : exts) {
117                        QualityAttribute supportedQA = loadSupportedQualityAttributes(iExtension);
118                        if (supportedQA == attribute){
119                                results.add(iExtension);
120                        }
121                        
122                }
123                return results;
124        }
125        
126        private static QualityAttribute loadSupportedQualityAttributes(
127                        IExtension extension) {
128                IConfigurationElement[] elements = extension.getConfigurationElements();
129                for (IConfigurationElement element : elements) {
130                        if (element.getName().equals("analysis")) {
131                                return QualityAttribute.getQualityAttribute(element.getAttribute("qualityAttribute"));
132                        }
133                }
134                
135                return null;
136        }
137 
138        public static List<IExtension> loadAnalysisExtensions(String  dimensionId) {
139                IExtension[] exts = Platform.getExtensionRegistry().getExtensionPoint(
140                "de.uka.ipd.sdq.dsexplore.analysis").getExtensions();
141                
142                List<IExtension> results = new ArrayList<IExtension>();
143                
144                for (IExtension extension : exts) {
145                        List<Dimension> dimensions = loadQualityAttributeDimension(extension);
146                        
147                        for (Dimension dimension : dimensions) {
148                                if (dimensionId.equals(dimension.getId())){
149                                        results.add(extension);
150                                        break;
151                                }
152                        }
153                }
154                
155                return results;
156        }
157        
158        /**
159         * Loads the dimensions of a single analysis method represented by the passed
160         * extension.
161         * 
162         * @param extension
163         * @return the analysis method's dimension; null if the passed extension is not
164         *         an analysis extension or the attribute is not set.
165         */
166        private static List<Dimension> loadQualityAttributeDimension(IExtension extension) {
167                IConfigurationElement[] elements = extension.getConfigurationElements();
168                for (IConfigurationElement element : elements) {
169                        if (element.getName().equals("analysis")) {
170                                //return element.getAttribute("qualityAttribute");
171                                try {
172                                        IAnalysisQualityAttributeDeclaration attribute = (IAnalysisQualityAttributeDeclaration)element.createExecutableExtension("qualityAttributeHandler");
173                                        return attribute.getDimensions();
174                                } catch (CoreException e) {
175                                        logger.error("Error when querying analysis extension:");
176                                        e.printStackTrace();
177                                        return null;
178                                }
179                        }
180                }
181                
182                return null;
183        }
184 
185}

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