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 [QMLDeclarationsReader.java]

nameclass, %method, %block, %line, %
QMLDeclarationsReader.java0%   (0/1)0%   (0/8)0%   (0/274)0%   (0/61)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class QMLDeclarationsReader0%   (0/1)0%   (0/8)0%   (0/274)0%   (0/61)
QMLDeclarationsReader (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getQMLContractTypes (QMLDeclarations): List 0%   (0/1)0%   (0/30)0%   (0/7)
getQMLDeclarations (String): QMLDeclarations 0%   (0/1)0%   (0/90)0%   (0/20)
getRefinedQMLContracts (QMLDeclarations): List 0%   (0/1)0%   (0/30)0%   (0/7)
getRefinedQMLProfiles (QMLDeclarations): List 0%   (0/1)0%   (0/30)0%   (0/7)
getSimpleQMLContracts (QMLDeclarations): List 0%   (0/1)0%   (0/30)0%   (0/7)
getSimpleQMLProfiles (QMLDeclarations): List 0%   (0/1)0%   (0/30)0%   (0/7)
printDiagnostic (Diagnostic, String): void 0%   (0/1)0%   (0/31)0%   (0/5)

1/**
2 * <copyright>
3 * </copyright>
4 *
5 * $Id$
6 */
7package de.uka.ipd.sdq.dsexplore.qml.reader;
8 
9import java.io.File;
10import java.util.ArrayList;
11import java.util.List;
12 
13import org.eclipse.emf.common.util.Diagnostic;
14import org.eclipse.emf.common.util.URI;
15import org.eclipse.emf.ecore.EObject;
16import org.eclipse.emf.ecore.resource.Resource;
17import org.eclipse.emf.ecore.resource.ResourceSet;
18import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
19import org.eclipse.emf.ecore.util.Diagnostician;
20import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
21 
22import de.uka.ipd.sdq.dsexplore.qml.contract.QMLContract.RefinedQMLContract;
23import de.uka.ipd.sdq.dsexplore.qml.contract.QMLContract.SimpleQMLContract;
24import de.uka.ipd.sdq.dsexplore.qml.contracttype.QMLContractType.QMLContractType;
25import de.uka.ipd.sdq.dsexplore.qml.declarations.QMLDeclarations.QMLDeclaration;
26import de.uka.ipd.sdq.dsexplore.qml.declarations.QMLDeclarations.QMLDeclarations;
27import de.uka.ipd.sdq.dsexplore.qml.declarations.QMLDeclarations.QMLDeclarationsPackage;
28import de.uka.ipd.sdq.dsexplore.qml.profile.QMLProfile.RefinedQMLProfile;
29import de.uka.ipd.sdq.dsexplore.qml.profile.QMLProfile.SimpleQMLProfile;
30 
31/**
32 * Basic class for reading qml definitions.
33 * 
34 * @author noorshams
35 */
36public class QMLDeclarationsReader {
37        /**
38         * Assumes 1 QML declaration in the file
39         * @param path
40         *            the file path or URI.
41         */
42        public QMLDeclarations getQMLDeclarations(String QMLDeclarationsPath) {
43                // Create a resource set to hold the resources.
44                //
45                ResourceSet resourceSet = new ResourceSetImpl();
46 
47                // Register the appropriate resource factory to handle all file
48                // extensions.
49                //
50                resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
51                                .put(Resource.Factory.Registry.DEFAULT_EXTENSION,
52                                                new XMIResourceFactoryImpl());
53 
54                // Register the package to ensure it is available during loading.
55                //
56                resourceSet.getPackageRegistry().put(QMLDeclarationsPackage.eNS_URI,
57                                QMLDeclarationsPackage.eINSTANCE);
58 
59                // Construct the URI for the instance file.
60                // The argument is treated as a file path only if it denotes an existing
61                // file.
62                // Otherwise, it's directly treated as a URL.
63                //
64                File file = new File(QMLDeclarationsPath);
65                URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath())
66                                : URI.createURI(QMLDeclarationsPath);
67 
68                // Demand load resource for this file.
69                //
70                Resource resource = resourceSet.getResource(uri, true);
71 
72                // Validate the contents of the loaded resource.
73                //
74                
75                //List<QMLDeclarations> declarationsList = new ArrayList<QMLDeclarations>();
76                QMLDeclarations returnDeclaration = null;
77                
78                for (EObject eObject : resource.getContents()) {
79                        Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
80                        if (diagnostic.getSeverity() != Diagnostic.OK) {
81                                printDiagnostic(diagnostic, "");
82                                throw new RuntimeException("QML validation failed: "+diagnostic.getMessage()+". See console output for details.");
83                        }
84                        if(!(eObject instanceof QMLDeclarations)) {
85                                throw new RuntimeException("Check QML definition: The root element of the file must be a QMLDeclarations element.");
86                        }
87                        
88                        returnDeclaration = ((QMLDeclarations)eObject);
89                        break;
90                }
91                return returnDeclaration;
92 
93        }
94 
95        /**
96         * <!-- begin-user-doc --> Prints diagnostics with indentation. <!--
97         * end-user-doc -->
98         * 
99         * @param diagnostic
100         *            the diagnostic to print.
101         * @param indent
102         *            the indentation for printing.
103         */
104        protected void printDiagnostic(Diagnostic diagnostic, String indent) {
105                System.out.print(indent);
106                System.out.println(diagnostic.getMessage());
107                for (Diagnostic child : diagnostic.getChildren()) {
108                        printDiagnostic(child, indent + "  ");
109                }
110        }
111        
112        public List<QMLContractType> getQMLContractTypes(QMLDeclarations declarations) {
113                if (declarations == null) {
114                        return null;
115                }
116                List<QMLContractType> contractTypes = new ArrayList<QMLContractType>();
117                for (QMLDeclaration declaration : declarations.getQmlDeclarations()) {
118                        if(declaration instanceof QMLContractType) {
119                                contractTypes.add((QMLContractType)declaration);
120                        }
121                }
122                return contractTypes;
123        }
124        
125        public List<SimpleQMLContract> getSimpleQMLContracts(QMLDeclarations declarations) {
126                if (declarations == null) {
127                        return null;
128                }
129                List<SimpleQMLContract> simpleContracts = new ArrayList<SimpleQMLContract>();
130                for (QMLDeclaration declaration : declarations.getQmlDeclarations()) {
131                        if(declaration instanceof SimpleQMLContract) {
132                                simpleContracts.add((SimpleQMLContract)declaration);
133                        }
134                }
135                return simpleContracts;
136        }
137        
138        public List<SimpleQMLProfile> getSimpleQMLProfiles(QMLDeclarations declarations) {
139                if (declarations == null) {
140                        return null;
141                }
142                List<SimpleQMLProfile> simpleProfiles = new ArrayList<SimpleQMLProfile>();
143                for (QMLDeclaration declaration : declarations.getQmlDeclarations()) {
144                        if(declaration instanceof SimpleQMLProfile) {
145                                simpleProfiles.add((SimpleQMLProfile)declaration);
146                        }
147                }
148                return simpleProfiles;
149        }
150        
151        public List<RefinedQMLContract> getRefinedQMLContracts(QMLDeclarations declarations) {
152                if (declarations == null) {
153                        return null;
154                }
155                List<RefinedQMLContract> refinedContracts = new ArrayList<RefinedQMLContract>();
156                for (QMLDeclaration declaration : declarations.getQmlDeclarations()) {
157                        if(declaration instanceof RefinedQMLContract) {
158                                refinedContracts.add((RefinedQMLContract)declaration);
159                        }
160                }
161                return refinedContracts;
162        }
163        
164        public List<RefinedQMLProfile> getRefinedQMLProfiles(QMLDeclarations declarations) {
165                if (declarations == null) {
166                        return null;
167                }
168                List<RefinedQMLProfile> simpleProfiles = new ArrayList<RefinedQMLProfile>();
169                for (QMLDeclaration declaration : declarations.getQmlDeclarations()) {
170                        if(declaration instanceof RefinedQMLProfile) {
171                                simpleProfiles.add((RefinedQMLProfile)declaration);
172                        }
173                }
174                return simpleProfiles;
175        }
176 
177}

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