Skip to content

Package: EcoreHelper

EcoreHelper

nameinstructionbranchcomplexitylinemethod
cleanAndRecheckRemovedURIs(Set)
M: 0 C: 73
100%
M: 2 C: 10
83%
M: 2 C: 5
71%
M: 0 C: 14
100%
M: 0 C: 1
100%
convertRsToVirtual(String, ResourceSet)
M: 15 C: 57
79%
M: 3 C: 7
70%
M: 3 C: 3
50%
M: 7 C: 14
67%
M: 0 C: 1
100%
getDefaultPackageRegistryContents()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getEPackage(Resource)
M: 2 C: 18
90%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 3
75%
M: 0 C: 1
100%
getOtherRelatedWorkspacePaths(String)
M: 15 C: 55
79%
M: 3 C: 5
63%
M: 3 C: 2
40%
M: 5 C: 14
74%
M: 0 C: 1
100%
initResourceSet(ResourceSet, boolean)
M: 0 C: 22
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
isContainedInPackageRegistry(String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
loadResource(String, Resource)
M: 0 C: 44
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
registerEcore(String)
M: 1 C: 62
98%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 13
93%
M: 0 C: 1
100%
registerSubpackages(EPackage)
M: 0 C: 43
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
unregisterEcore(Set)
M: 0 C: 43
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
unregisterEcore(String)
M: 0 C: 120
100%
M: 1 C: 21
95%
M: 1 C: 11
92%
M: 0 C: 30
100%
M: 0 C: 1
100%
unregisterSubpackages(EPackage)
M: 0 C: 36
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
updateRegistryAndLocalCache(EPackage, Resource, ResourceSet)
M: 11 C: 72
87%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 3 C: 13
81%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Alexandra Buzila - initial API and implementation
13: * Johannes Faltermeier - refactorings
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.ide.spi.util;
16:
17: import java.io.IOException;
18: import java.text.MessageFormat;
19: import java.util.HashMap;
20: import java.util.HashSet;
21: import java.util.LinkedHashMap;
22: import java.util.LinkedHashSet;
23: import java.util.Map;
24: import java.util.Set;
25:
26: import org.eclipse.core.runtime.IStatus;
27: import org.eclipse.emf.common.util.URI;
28: import org.eclipse.emf.ecore.EObject;
29: import org.eclipse.emf.ecore.EPackage;
30: import org.eclipse.emf.ecore.EPackage.Registry;
31: import org.eclipse.emf.ecore.plugin.EcorePlugin;
32: import org.eclipse.emf.ecore.resource.Resource;
33: import org.eclipse.emf.ecore.resource.ResourceSet;
34: import org.eclipse.emf.ecore.resource.URIConverter;
35: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
36: import org.eclipse.emf.ecore.util.EcoreUtil;
37: import org.eclipse.emf.ecore.xmi.XMLResource;
38: import org.eclipse.emf.ecp.ide.internal.Activator;
39: import org.eclipse.emf.ecp.internal.ide.util.messages.Messages;
40:
41: /**
42: * Helper methods for dealing with ecores.
43: *
44: * @author Alexandra Buzila
45: * @since 1.13
46: *
47: */
48: public final class EcoreHelper {
49:
50:         /**
51:          * ResourceSet which overrides the getResource and double checks for registry.
52:          *
53:          * @author Eugen Neufeld
54:          *
55:          */
56:         private static final class EMFFormsResourceSetImpl extends ResourceSetImpl {
57:                 private final String ecorePath;
58:
59:                 /**
60:                  * @param ecorePath
61:                  */
62:                 private EMFFormsResourceSetImpl(String ecorePath) {
63:                         this.ecorePath = ecorePath;
64:                 }
65:
66:                 // BEGIN COMPLEX CODE
67:                 // COPIED FROM SUPERCLASS
68:                 @Override
69:                 public Resource getResource(URI uri, boolean loadOnDemand) {
70:                         // BEGIN CHANGES (en)
71:                         if (uri.isPlatform()) {
72:                                 if (!WORKSPACEURI_REFERENCEDBY.containsKey(uri.toString())) {
73:                                         WORKSPACEURI_REFERENCEDBY.put(uri.toString(), new LinkedHashSet<String>());
74:                                 }
75:                                 WORKSPACEURI_REFERENCEDBY.get(uri.toString()).add(ECOREPATH_TO_WORKSPACEURI.get(ecorePath));
76:                         }
77:                         // END CHANGES
78:                         if (resourceLocator != null) {
79:                                 return resourceLocator.getResource(uri, loadOnDemand);
80:                         }
81:
82:                         final Map<URI, Resource> map = getURIResourceMap();
83:                         if (map != null) {
84:                                 final Resource resource = map.get(uri);
85:                                 if (resource != null) {
86:                                         if (loadOnDemand && !resource.isLoaded()) {
87:                                                 demandLoadHelper(resource);
88:                                         }
89:                                         return resource;
90:                                 }
91:                         }
92:
93:                         final URIConverter theURIConverter = getURIConverter();
94:                         final URI normalizedURI = theURIConverter.normalize(uri);
95:                         for (final Resource resource : getResources()) {
96:                                 if (theURIConverter.normalize(resource.getURI()).equals(normalizedURI)) {
97:                                         if (loadOnDemand && !resource.isLoaded()) {
98:                                                 demandLoadHelper(resource);
99:                                         }
100:
101:                                         if (map != null) {
102:                                                 map.put(uri, resource);
103:                                         }
104:                                         return resource;
105:                                 }
106:                         }
107:
108:                         final Resource delegatedResource = delegatedGetResource(uri, loadOnDemand);
109:                         if (delegatedResource != null) {
110:                                 if (map != null) {
111:                                         map.put(uri, delegatedResource);
112:                                 }
113:                                 return delegatedResource;
114:                         }
115:
116:                         if (loadOnDemand) {
117:                                 final Resource resource = demandCreateResource(uri);
118:                                 if (resource == null) {
119:                                         throw new RuntimeException(
120:                                                 "Cannot create a resource for '" + uri + "'; a registered resource factory is needed"); //$NON-NLS-1$//$NON-NLS-2$
121:                                 }
122:
123:                                 demandLoadHelper(resource);
124:                                 // BEGIN CHANGES (en)
125:                                 // custom recheck whether resource is known in the registry
126:                                 // and if so use it instead of a custom loaded one
127:                                 final Resource delegatedGetResource = delegatedGetResource(
128:                                         URI.createURI(((EPackage) resource.getContents().get(0)).getNsURI()), loadOnDemand);
129:                                 final Resource resultResource = delegatedGetResource != null ? delegatedGetResource : resource;
130:                                 if (delegatedGetResource != null) {
131:                                         getResources().remove(resource);
132:                                 }
133:                                 if (map != null) {
134:                                         map.put(uri, resultResource);
135:                                 }
136:                                 return resultResource;
137:                                 // END CHANGES
138:                         }
139:
140:                         return null;
141:                 }
142:                 // END COMPLEX CODE
143:         }
144:
145:         /**
146:          * Contains mapping between an ecore path and the corresponding platform resource URI.
147:          */
148:         private static final Map<String, String> ECOREPATH_TO_WORKSPACEURI = new HashMap<String, String>();
149:
150:         /** Keeps track of how many times an ecore path was registered in order to not unregister it prematurely. */
151:         private static final Map<String, Integer> ECOREPATH_TO_REGISTRATIONCOUNT = new HashMap<String, Integer>();
152:
153:         /**
154:          * Contains mapping between an platform resource URI and the URIs which reference it.
155:          */
156:         private static final Map<String, Set<String>> WORKSPACEURI_REFERENCEDBY = new HashMap<String, Set<String>>();
157:         /**
158:          * URIs which are still in use although it was requested to be removed.
159:          */
160:         private static final Set<String> URIS_HOLD = new LinkedHashSet<String>();
161:         /**
162:          * A set of all namespace uris that were registerd by the tooling.
163:          */
164:         private static final Set<String> ALL_NSURIS_REGISTERED_BY_TOOLING = new HashSet<String>();
165:
166:         /** Local EPackage Registry. */
167:         private static final Map<String, EPackage> WORKSPACEURI_TO_REGISTEREDPACKAGE = new LinkedHashMap<String, EPackage>();
168:
169:         private EcoreHelper() {
170:         }
171:
172:         /**
173:          * Put an ecore's {@link EPackage} into the {@link org.eclipse.emf.ecore.EPackage.Registry}. Subsequently, register
174:          * all referenced ecores.
175:          *
176:          * @param ecorePath - path to the ecore
177:          * @throws IOException if resource cannot be loaded
178:          *
179:          */
180:         public static void registerEcore(final String ecorePath) throws IOException {
181:•                if (ecorePath == null) {
182:                         return;
183:                 }
184:
185:                 // actually load the ecore reusing already loaded packages from the workspace
186:                 final ResourceSet physicalResourceSet = new EMFFormsResourceSetImpl(ecorePath);
187:                 initResourceSet(physicalResourceSet, true);
188:                 final URI uri = URI.createPlatformResourceURI(ecorePath, false);
189:                 ECOREPATH_TO_WORKSPACEURI.put(ecorePath, uri.toString());
190:                 ECOREPATH_TO_REGISTRATIONCOUNT.put(ecorePath, ECOREPATH_TO_REGISTRATIONCOUNT.getOrDefault(ecorePath, 0) + 1);
191:                 final Resource r = physicalResourceSet.createResource(uri);
192:
193:                 loadResource(ecorePath, r);
194:                 // resolve the proxies
195:                 EcoreUtil.resolveAll(physicalResourceSet);
196:                 // remove self reference
197:•                if (WORKSPACEURI_REFERENCEDBY.containsKey(uri.toString())) {
198:                         WORKSPACEURI_REFERENCEDBY.get(uri.toString()).remove(uri.toString());
199:                 }
200:                 convertRsToVirtual(ecorePath, physicalResourceSet);
201:
202:         }
203:
204:         private static void convertRsToVirtual(String ecorePath, final ResourceSet physicalResourceSet) {
205:                 final ResourceSetImpl virtualResourceSet = new ResourceSetImpl();
206:•                for (final Resource physicalResource : physicalResourceSet.getResources()) {
207:
208:                         final EPackage ePackage = getEPackage(physicalResource);
209:•                        if (ePackage == null) {
210:                                 continue;
211:                         }
212:
213:•                        if (isContainedInPackageRegistry(ePackage.getNsURI())) {
214:•                                if (!ALL_NSURIS_REGISTERED_BY_TOOLING.contains(ePackage.getNsURI())) {
215:                                         Activator.log(
216:                                                 IStatus.INFO,
217:                                                 String.format(
218:                                                         "Tooling Registered Packages don't contain package with URI %1$s.", ePackage.getNsURI())); //$NON-NLS-1$
219:                                         registerSubpackages(ePackage);
220:                                         continue;
221:                                 }
222:                                 final EPackage registeredPackage = EPackage.Registry.INSTANCE.getEPackage(ePackage.getNsURI());
223:•                                if (EcoreUtil.equals(ePackage, registeredPackage)) {
224:                                         Activator.log(IStatus.INFO,
225:                                                 String.format("Another package with same URI is already registered: %1$s.", registeredPackage)); //$NON-NLS-1$
226:                                         registerSubpackages(ePackage);
227:                                         continue;
228:                                 }
229:                         }
230:                         updateRegistryAndLocalCache(ePackage, physicalResource, virtualResourceSet);
231:                 }
232:         }
233:
234:         /**
235:          * Wraps loading a {@link Resource} in order to catch thrown IOExceptions and rethrow them with more informative
236:          * messages.
237:          *
238:          * @param ecorePath The path of the resource. Needed for informative messages
239:          * @param resource The {@link Resource} to load
240:          * @throws IOException if the loading of the Resource fails
241:          */
242:         protected static void loadResource(String ecorePath, final Resource resource) throws IOException {
243:                 try {
244:                         resource.load(null);
245:                 } catch (final IOException e) {
246:•                        if (e.getMessage().contains("does not exist")) { //$NON-NLS-1$
247:                                 throw new IOException(MessageFormat.format(
248:                                         Messages.EcoreHelper_invalidEcorePath,
249:                                         ecorePath), e.getCause());
250:                         }
251:                         throw new IOException(
252:                                 MessageFormat.format(Messages.EcoreHelper_invalidEcore,
253:                                         ecorePath, e.getMessage()),
254:                                 e.getCause());
255:                 }
256:         }
257:
258:         /**
259:          * Returns the first {@link EPackage} contained in the resource, as returned by {@link Resource#getContents()}.
260:          *
261:          * @param resource the container resource
262:          * @return the first {@link EPackage} contained in the resource or <code>null</code> if no EPackage can be found
263:          */
264:         private static EPackage getEPackage(Resource resource) {
265:•                for (final EObject eObject : resource.getContents()) {
266:•                        if (eObject instanceof EPackage) {
267:                                 return (EPackage) eObject;
268:                         }
269:                 }
270:                 return null;
271:         }
272:
273:         private static void updateRegistryAndLocalCache(EPackage ePackage,
274:                 Resource oldResource, ResourceSet newResourceSet) {
275:•                if (ePackage.getNsURI() == null || ePackage.getNsURI().isEmpty()) {
276:                         Activator.log(IStatus.WARNING,
277:                                 String.format("Package does not have a valid Ns URI [%1$s].", ePackage)); //$NON-NLS-1$
278:                         return;
279:                 }
280:                 final String platformResourceURI = oldResource.getURI().toString();
281:                 oldResource.getContents().remove(ePackage);
282:                 final Resource virtualResource = newResourceSet.createResource(URI.createURI(ePackage.getNsURI()));
283:                 virtualResource.getContents().add(ePackage);
284:                 EPackage.Registry.INSTANCE.put(ePackage.getNsURI(), ePackage);
285:                 ALL_NSURIS_REGISTERED_BY_TOOLING.add(ePackage.getNsURI());
286:                 Activator.log(IStatus.INFO, String.format("Registered Package with URI %1$s.", ePackage.getNsURI())); //$NON-NLS-1$
287:                 WORKSPACEURI_TO_REGISTEREDPACKAGE.put(platformResourceURI, ePackage);
288:                 Activator.log(IStatus.INFO,
289:                         String.format("Mapped Package with URI %1$s to %2$s.", ePackage.getNsURI(), platformResourceURI)); //$NON-NLS-1$
290:                 registerSubpackages(ePackage);
291:         }
292:
293:         /**
294:          * @param ePackage - the EPackage whose subpackages need to be registered
295:          */
296:         private static void registerSubpackages(EPackage ePackage) {
297:•                for (final EPackage subpackage : ePackage.getESubpackages()) {
298:•                        if (EPackage.Registry.INSTANCE.containsKey(subpackage.getNsURI())) {
299:                                 continue;
300:                         }
301:                         EPackage.Registry.INSTANCE.put(subpackage.getNsURI(), subpackage);
302:                         Activator.log(IStatus.INFO,
303:                                 String.format("Register subpackage %1$s of package %2$s.", subpackage.getNsURI(), ePackage.getNsURI())); //$NON-NLS-1$
304:                         registerSubpackages(subpackage);
305:                 }
306:         }
307:
308:         /**
309:          * <p>
310:          * Returns the path for all ecores for which
311:          * <p>
312:          * <p>
313:          * a) the given ecore is dependent on.
314:          * </p>
315:          * <p>
316:          * b) the uri is a platform resource URI, meaning the ecore is available in the workspace.
317:          * </p>
318:          *
319:          * @param ecorePath the path
320:          * @return the ecore nsuris
321:          */
322:         public static Set<String> getOtherRelatedWorkspacePaths(String ecorePath) {
323:                 final Set<String> result = new LinkedHashSet<String>();
324:•                if (ecorePath == null) {
325:                         return result;
326:                 }
327:                 try {
328:                         final ResourceSet physicalResourceSet = new ResourceSetImpl();
329:                         initResourceSet(physicalResourceSet, false);
330:                         final URI uri = URI.createPlatformResourceURI(ecorePath, false);
331:                         final Resource tempResource = physicalResourceSet.createResource(uri);
332:                         tempResource.load(null);
333:                         // resolve the proxies
334:                         EcoreUtil.resolveAll(physicalResourceSet);
335:•                        for (final Resource physicalResource : physicalResourceSet.getResources()) {
336:•                                if (physicalResource.getContents().size() == 0) {
337:                                         continue;
338:                                 }
339:•                                if (!physicalResource.getURI().isPlatformResource()) {
340:                                         continue;
341:                                 }
342:                                 result.add(physicalResource.getURI().toString());
343:                         }
344:                 } catch (final IOException ex) {
345:                         Activator.log(IStatus.INFO,
346:                                 String.format("Error while loading %1$s.", ecorePath)); //$NON-NLS-1$
347:                 }
348:                 return result;
349:         }
350:
351:         private static boolean isContainedInPackageRegistry(String nsURI) {
352:                 final Registry instance = EPackage.Registry.INSTANCE;
353:                 return instance.containsKey(nsURI);
354:         }
355:
356:         /**
357:          * Remove the ecore's {@link EPackage} from the {@link org.eclipse.emf.ecore.EPackage.Registry}.
358:          * It also removes the packages of referenced ecores.
359:          *
360:          * @param ecorePath - the path of the ecore to be removed.
361:          *
362:          */
363:         public static void unregisterEcore(String ecorePath) {
364:•                if (ecorePath == null || !ECOREPATH_TO_WORKSPACEURI.containsKey(ecorePath)) {
365:                         return;
366:                 }
367:
368:                 ECOREPATH_TO_REGISTRATIONCOUNT.put(ecorePath, ECOREPATH_TO_REGISTRATIONCOUNT.getOrDefault(ecorePath, 1) - 1);
369:•                if (ECOREPATH_TO_REGISTRATIONCOUNT.get(ecorePath) == 0) {
370:                         ECOREPATH_TO_REGISTRATIONCOUNT.remove(ecorePath);
371:                 } else {
372:                         return;
373:                 }
374:
375:                 final String uriToUnregister = ECOREPATH_TO_WORKSPACEURI.remove(ecorePath);
376:
377:                 final Set<String> referencedBy = WORKSPACEURI_REFERENCEDBY.get(uriToUnregister);
378:                 URIS_HOLD.add(uriToUnregister);
379:•                if (ECOREPATH_TO_WORKSPACEURI.size() == 0) {
380:                         URIS_HOLD.addAll(WORKSPACEURI_REFERENCEDBY.keySet());
381:                 }
382:
383:                 final Set<String> workspaceURIsToRemove = new LinkedHashSet<String>();
384:                 boolean addedToDelete = false;
385:•                if (referencedBy == null || referencedBy.size() == 0) {
386:                         workspaceURIsToRemove.add(uriToUnregister);
387:                         addedToDelete = true;
388:•                } else if (URIS_HOLD.containsAll(referencedBy)) {
389:•                        for (final String refed : referencedBy) {
390:                                 final Set<String> toDeleteRefedBy = WORKSPACEURI_REFERENCEDBY.get(refed);
391:•                                if (URIS_HOLD.containsAll(toDeleteRefedBy)) {
392:                                         workspaceURIsToRemove.add(refed);
393:                                         addedToDelete = true;
394:                                 }
395:                         }
396:•                        if (workspaceURIsToRemove.containsAll(referencedBy)) {
397:                                 workspaceURIsToRemove.add(uriToUnregister);
398:                                 addedToDelete = true;
399:                         }
400:                 }
401:•                if (addedToDelete) {
402:                         cleanAndRecheckRemovedURIs(workspaceURIsToRemove);
403:                 }
404:
405:                 unregisterEcore(workspaceURIsToRemove);
406:         }
407:
408:         private static void cleanAndRecheckRemovedURIs(final Set<String> workspaceURIsToRemove) {
409:                 boolean addedToDelete = true;
410:•                while (addedToDelete) {
411:                         addedToDelete = false;
412:•                        for (final String toDelete : workspaceURIsToRemove) {
413:                                 URIS_HOLD.remove(toDelete);
414:                                 WORKSPACEURI_REFERENCEDBY.remove(toDelete);
415:•                                for (final String key : WORKSPACEURI_REFERENCEDBY.keySet()) {
416:                                         WORKSPACEURI_REFERENCEDBY.get(key).remove(toDelete);
417:                                 }
418:                         }
419:                         // recheck URIs_HOLD
420:•                        for (final String uri : URIS_HOLD) {
421:                                 final Set<String> toDeleteRefedBy = WORKSPACEURI_REFERENCEDBY.get(uri);
422:•                                if (toDeleteRefedBy == null || toDeleteRefedBy.size() == 0) {
423:                                         workspaceURIsToRemove.add(uri);
424:                                         addedToDelete = true;
425:                                 }
426:                         }
427:                 }
428:         }
429:
430:         /**
431:          * Remove the ecore's {@link EPackage} from the {@link org.eclipse.emf.ecore.EPackage.Registry}.
432:          * It also removes the packages of referenced ecores (if needed).
433:          *
434:          */
435:         private static void unregisterEcore(Set<String> workspaceURIsToRemove) {
436:                 // unregister no longer needed workspace URIs
437:•                for (final String toRemove : workspaceURIsToRemove) {
438:                         final EPackage pkgToRemove = WORKSPACEURI_TO_REGISTEREDPACKAGE.remove(toRemove);
439:•                        if (pkgToRemove == null) {
440:                                 continue;
441:                         }
442:                         EPackage.Registry.INSTANCE.remove(pkgToRemove.getNsURI());
443:                         ALL_NSURIS_REGISTERED_BY_TOOLING.remove(pkgToRemove.getNsURI());
444:                         Activator.log(IStatus.INFO,
445:                                 String.format("Unregister package %1$s.", pkgToRemove.getNsURI())); //$NON-NLS-1$
446:                         unregisterSubpackages(pkgToRemove);
447:                 }
448:         }
449:
450:         /**
451:          * @param ePackage - the EPackage whose subpackages need to be unregistered
452:          */
453:         private static void unregisterSubpackages(EPackage ePackage) {
454:•                for (final EPackage subpackage : ePackage.getESubpackages()) {
455:                         EPackage.Registry.INSTANCE.remove(subpackage.getNsURI());
456:                         Activator.log(IStatus.INFO,
457:                                 String
458:                                         .format("Unregister subpackage %1$s of package %2$s.", subpackage.getNsURI(), ePackage.getNsURI())); //$NON-NLS-1$
459:                         unregisterSubpackages(subpackage);
460:                 }
461:         }
462:
463:         /**
464:          * @return the EPackages which are registered in the EPackage registry by default (without the ones registered
465:          * during runtime by the tooling).
466:          */
467:         public static Object[] getDefaultPackageRegistryContents() {
468:
469:                 final Set<String> packages = new HashSet<String>();
470:                 packages.addAll(EPackage.Registry.INSTANCE.keySet());
471:                 packages.removeAll(ALL_NSURIS_REGISTERED_BY_TOOLING);
472:                 return packages.toArray();
473:         }
474:
475:         /*
476:          * If the Ecore.ecore is referenced with a resource uri in an ecore-file, the ecore editor is able to load this file
477:          * even if the Ecore.ecore is not available in the workspace. Therefore those ecores should be regarded as valid.
478:          * Hence we need to remap the resource uri to a plugin uri if the Ecore.ecore is not available in the workspace
479:          * in order to resolve the proxy.
480:          * Moreover when a new ecore is loaded we need to prevent EMF to resolve proxies to other platform-resource URIs
481:          * with the package registry
482:          */
483:         private static void initResourceSet(final ResourceSet resourceSet, boolean withLocalRegistry) {
484:•                if (withLocalRegistry) {
485:                         resourceSet.getPackageRegistry().putAll(WORKSPACEURI_TO_REGISTEREDPACKAGE);
486:                         Activator.log(IStatus.INFO, "Added map of platformuri to epackage to resourceset package registry."); //$NON-NLS-1$
487:                 }
488:
489:                 // needed to be able to resolve resource paths to plugin paths and thus load referenced ecores
490:                 resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
491:
492:                 resourceSet.getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, Boolean.TRUE);
493:         }
494:
495: }