Package: ResourceLoader

ResourceLoader

nameinstructionbranchcomplexitylinemethod
ResourceLoader()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getResource(EditingDomain, URI)
M: 0 C: 29
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
getResource(ResourceSet, URI)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getResourceManager()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
initializeEmptyResource(Resource)
M: 0 C: 11
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2013 RCP Vision (http://www.rcp-vision.com) and others.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * Lorenzo Bettini - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.emf.parsley.resource;
12:
13: import org.eclipse.emf.common.util.URI;
14: import org.eclipse.emf.ecore.resource.Resource;
15: import org.eclipse.emf.ecore.resource.ResourceSet;
16: import org.eclipse.emf.edit.domain.EditingDomain;
17:
18: import com.google.inject.Inject;
19:
20: /**
21: * ResourceLoader is responsible for loading a {@link Resource}.
22: *
23: * @author Lorenzo Bettini
24: */
25: public class ResourceLoader {
26:
27:         @Inject
28:         private ResourceManager resourceManager;
29:
30:         public Resource getResource(ResourceSet resourceSet, URI resourceURI) {
31:                 Resource resource = resourceSet.getResource(resourceURI, true);
32:                 initializeEmptyResource(resource);
33:                 return resource;
34:         }
35:
36:         protected ResourceManager getResourceManager() {
37:                 return resourceManager;
38:         }
39:         
40:         /**
41:          * Tries to load the resource using the resource set of the editing domain
42:          * and returns a {@link LoadResourceResponse}.
43:          *
44:          * @param editingDomain
45:          * @param resourceURI
46:          * @return
47:          */
48:         public LoadResourceResponse getResource(EditingDomain editingDomain, URI resourceURI) {
49:                 Resource resource = null;
50:                 Exception exception = null;
51:                 try {
52:                         // Load the resource through the editing domain.
53:                         resource = getResource(editingDomain.getResourceSet(), resourceURI);
54:                 } catch (Exception e) {
55:                         exception = e;
56:                         resource = editingDomain.getResourceSet().getResource(resourceURI,
57:                                         false);
58:                         initializeEmptyResource(resource);
59:                 }
60:
61:                 return new LoadResourceResponse(resource, exception);
62:         }
63:
64:         protected void initializeEmptyResource(Resource resource) {
65:•                if (resource != null && resource.getContents().isEmpty()) {
66:                         getResourceManager().initialize(resource);
67:                 }
68:         }
69: }