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

COVERAGE SUMMARY FOR SOURCE FILE [EMFTools.java]

nameclass, %method, %block, %line, %
EMFTools.java0%   (0/1)0%   (0/3)0%   (0/95)0%   (0/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EMFTools0%   (0/1)0%   (0/3)0%   (0/95)0%   (0/23)
EMFTools (): void 0%   (0/1)0%   (0/3)0%   (0/1)
loadFromXMI (String): EObject 0%   (0/1)0%   (0/57)0%   (0/13)
saveToXMI (EObject, String): void 0%   (0/1)0%   (0/35)0%   (0/9)

1package de.uka.ipd.sdq.spa.util;
2 
3import java.io.File;
4import java.io.IOException;
5import java.util.Collections;
6 
7import org.eclipse.emf.common.util.URI;
8import org.eclipse.emf.ecore.EObject;
9import org.eclipse.emf.ecore.resource.Resource;
10import org.eclipse.emf.ecore.resource.ResourceSet;
11import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
12import org.eclipse.emf.ecore.util.EcoreUtil;
13import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
14 
15import de.uka.ipd.sdq.spa.SpaPackage;
16 
17 
18public class EMFTools {
19        
20        @SuppressWarnings("unchecked")
21        public static EObject loadFromXMI(String fileName) {
22        // Create a resource set to hold the resources.
23        ResourceSet resourceSet = new ResourceSetImpl();
24 
25        // Register the appropriate resource factory to handle all file
26        // extentions.
27        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
28                .put(Resource.Factory.Registry.DEFAULT_EXTENSION,
29                        new XMIResourceFactoryImpl());
30 
31        // Register the package to ensure it is available during loading.
32        resourceSet.getPackageRegistry().put(SpaPackage.eNS_URI,
33                        SpaPackage.eINSTANCE);
34 
35        // Construct the URI for the instance file.
36        // The argument is treated as a file path only if it denotes an existing
37        // file. Otherwise, it's directly treated as a URL.
38        File file = new File(fileName);
39        URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath())
40                : URI.createURI(fileName);
41 
42        // Demand load resource for this file.
43        Resource resource = resourceSet.getResource(uri, true);
44        System.out.println("Loaded " + uri);
45 
46   
47        EObject eObject = (EObject)resource.getContents().iterator().next();
48        return EcoreUtil.getRootContainer(eObject);
49    }
50        
51        @SuppressWarnings("unchecked")
52        public static void saveToXMI(EObject objectToSave, String fileName) {
53                  // Create a resource set.
54                  ResourceSet resourceSet = new ResourceSetImpl();
55 
56                  // Register the default resource factory -- only needed for stand-alone!
57                  resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
58                    Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
59 
60                  // Get the URI of the model file.
61                  URI fileURI = URI.createFileURI(new File(fileName).getAbsolutePath());
62 
63                  // Create a resource for this file.
64                  Resource resource = resourceSet.createResource(fileURI);
65 
66                  // Add the book and writer objects to the contents.
67                  resource.getContents().add(objectToSave);
68 
69                  // Save the contents of the resource to the file system.
70                  try
71                  {
72                    resource.save(Collections.EMPTY_MAP);
73                  }
74                  catch (IOException e) {}
75        }        
76 
77}

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