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

COVERAGE SUMMARY FOR SOURCE FILE [QMLDimensionReader.java]

nameclass, %method, %block, %line, %
QMLDimensionReader.java0%   (0/1)0%   (0/3)0%   (0/114)0%   (0/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class QMLDimensionReader0%   (0/1)0%   (0/3)0%   (0/114)0%   (0/25)
QMLDimensionReader (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getDimension (String): Dimension 0%   (0/1)0%   (0/83)0%   (0/20)
getDimensions (String []): List 0%   (0/1)0%   (0/28)0%   (0/4)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.dsexplore.qml.reader;
5 
6import java.io.File;
7import java.util.List;
8import java.util.ArrayList;
9 
10import org.eclipse.emf.common.util.Diagnostic;
11import org.eclipse.emf.common.util.URI;
12import org.eclipse.emf.ecore.EObject;
13import org.eclipse.emf.ecore.resource.Resource;
14import org.eclipse.emf.ecore.resource.ResourceSet;
15import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
16import org.eclipse.emf.ecore.util.Diagnostician;
17import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
18 
19import de.uka.ipd.sdq.dsexplore.qml.contracttype.QMLContractType.Dimension;
20import de.uka.ipd.sdq.dsexplore.qml.declarations.QMLDeclarations.QMLDeclarationsPackage;
21 
22/**
23 * Reads the Dimension defined in the file. Be sure the definition 
24 * does not contain multiple dimension definitions.  
25 * 
26 * @author noorshams
27 *
28 */
29public class QMLDimensionReader {
30        
31        public List<Dimension> getDimensions(String[] dimensionPaths) {
32                List<Dimension> dimensions = new ArrayList<Dimension>();
33                for (String dimensionPath : dimensionPaths) {
34                        dimensions.add(this.getDimension(dimensionPath));
35                }
36                return dimensions;
37        }
38        
39        public Dimension getDimension(String dimensionPath) {
40                // Create a resource set to hold the resources.
41                //
42                ResourceSet resourceSet = new ResourceSetImpl();
43 
44                // Register the appropriate resource factory to handle all file
45                // extensions.
46                //
47                resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
48                                .put(Resource.Factory.Registry.DEFAULT_EXTENSION,
49                                                new XMIResourceFactoryImpl());
50 
51                // Register the package to ensure it is available during loading.
52                //
53                resourceSet.getPackageRegistry().put(QMLDeclarationsPackage.eNS_URI,
54                                QMLDeclarationsPackage.eINSTANCE);
55 
56                // Construct the URI for the instance file.
57                // The argument is treated as a file path only if it denotes an existing
58                // file.
59                // Otherwise, it's directly treated as a URL.
60                //
61                File file = new File(dimensionPath);
62                URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath())
63                                : URI.createURI(dimensionPath);
64 
65                // Demand load resource for this file.
66                //
67                Resource resource = resourceSet.getResource(uri, true);
68 
69                // Validate the contents of the loaded resource.
70                //
71                
72                Dimension dimension = null;
73                
74                for (EObject eObject : resource.getContents()) {
75                        Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
76                        if (diagnostic.getSeverity() != Diagnostic.OK) {
77                                new QMLDeclarationsReader().printDiagnostic(diagnostic, "");
78                                throw new RuntimeException("QML validation failed!");
79                        }
80                        if(!(eObject instanceof Dimension)) {
81                                throw new RuntimeException("Check QML definition! Dimension expected!");
82                        }
83                        dimension = ((Dimension)eObject);
84                        //XXX: first dimension found will be returned
85                        break;
86                }
87                return dimension;
88        }
89        
90}

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