Lines 1-7
Link Here
|
1 |
/** |
1 |
/** |
2 |
* <copyright> |
2 |
* <copyright> |
3 |
* |
3 |
* |
4 |
* Copyright (c) 2013 itemis and others. |
4 |
* Copyright (c) 2013 itemis, Continental Engineering Services (CES) and others. |
5 |
* All rights reserved. This program and the accompanying materials |
5 |
* All rights reserved. This program and the accompanying materials |
6 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* are made available under the terms of the Eclipse Public License v1.0 |
7 |
* which accompanies this distribution, and is available at |
7 |
* which accompanies this distribution, and is available at |
Lines 10-15
Link Here
|
10 |
* Contributors: |
10 |
* Contributors: |
11 |
* itemis - Initial API and implementation |
11 |
* itemis - Initial API and implementation |
12 |
* itemis - [409458] Enhance ScopingResourceSetImpl#getEObjectInScope() to enable cross-document references between model files with different metamodels |
12 |
* itemis - [409458] Enhance ScopingResourceSetImpl#getEObjectInScope() to enable cross-document references between model files with different metamodels |
|
|
13 |
* CES - Refactoring for a more extensible framework |
13 |
* |
14 |
* |
14 |
* </copyright> |
15 |
* </copyright> |
15 |
*/ |
16 |
*/ |
Lines 22-28
Link Here
|
22 |
import org.eclipse.emf.ecore.resource.Resource; |
23 |
import org.eclipse.emf.ecore.resource.Resource; |
23 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
24 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
24 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
25 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
25 |
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelper; |
|
|
26 |
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelperAdapterFactory; |
26 |
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelperAdapterFactory; |
27 |
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.resolver.DefaultResourceSetEObjectResolver; |
27 |
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.resolver.DefaultResourceSetEObjectResolver; |
28 |
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.resolver.EObjectResolveRequest; |
28 |
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.resolver.EObjectResolveRequest; |
Lines 31-36
Link Here
|
31 |
import org.eclipse.sphinx.emf.metamodel.IMetaModelDescriptor; |
31 |
import org.eclipse.sphinx.emf.metamodel.IMetaModelDescriptor; |
32 |
import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry; |
32 |
import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry; |
33 |
|
33 |
|
|
|
34 |
/** |
35 |
* Handles the proxy resolution by trying to resolve a proxy object inside a resource set. Uses a {@link IProxyHelper} |
36 |
* in order to resolve proxies in a performance-optimized way. |
37 |
*/ |
34 |
public class ProxyResolutionBehavior { |
38 |
public class ProxyResolutionBehavior { |
35 |
|
39 |
|
36 |
/** |
40 |
/** |
Lines 42-53
Link Here
|
42 |
private IEObjectResolver fEObjectResolver; |
46 |
private IEObjectResolver fEObjectResolver; |
43 |
|
47 |
|
44 |
/** |
48 |
/** |
45 |
* Protected constructor for the singleton pattern |
49 |
* Protected constructor for the singleton pattern. |
46 |
*/ |
50 |
*/ |
47 |
protected ProxyResolutionBehavior(IEObjectResolver eObjectResolver) { |
51 |
protected ProxyResolutionBehavior(IEObjectResolver eObjectResolver) { |
48 |
fEObjectResolver = eObjectResolver; |
52 |
fEObjectResolver = eObjectResolver; |
49 |
} |
53 |
} |
50 |
|
54 |
|
|
|
55 |
/** |
56 |
* Resolves the given proxy object inside the given context, by performing the proxy resolution in the resource set |
57 |
* containing the resource where the context object is located. |
58 |
* |
59 |
* @param contextObject |
60 |
* the context within the proxy resolution is performed |
61 |
* @param proxy |
62 |
* the object to resolve |
63 |
* @return the resolved object, if the resolution was successful or the original <code>proxy</code> object, if it |
64 |
* was not possible to resolve it. |
65 |
*/ |
51 |
public EObject eResolveProxy(EObject contextObject, EObject proxy) { |
66 |
public EObject eResolveProxy(EObject contextObject, EObject proxy) { |
52 |
if (proxy == null) { |
67 |
if (proxy == null) { |
53 |
return null; |
68 |
return null; |
Lines 67-76
Link Here
|
67 |
return EcoreUtil.resolve(proxy, contextObject); |
82 |
return EcoreUtil.resolve(proxy, contextObject); |
68 |
} |
83 |
} |
69 |
|
84 |
|
|
|
85 |
/** |
86 |
* Returns whether the given object is a proxy or not. |
87 |
* |
88 |
* @param proxy |
89 |
* the given object that may or may not be a proxy |
90 |
* @return <code>true</code> if <code>proxy</code> is a proxy object, or <code>false</code>, otherwise. |
91 |
*/ |
70 |
protected boolean isNoProxy(EObject proxy) { |
92 |
protected boolean isNoProxy(EObject proxy) { |
71 |
return ((InternalEObject) proxy).eProxyURI() == null; |
93 |
return ((InternalEObject) proxy).eProxyURI() == null; |
72 |
} |
94 |
} |
73 |
|
95 |
|
|
|
96 |
/** |
97 |
* Resolves the given proxy object inside the given context, by using a proxy helper registered for the given |
98 |
* resource set. |
99 |
* |
100 |
* @param resourceSet |
101 |
* the resource set for which to retrieve the proxy helper |
102 |
* @param contextObject |
103 |
* the object which is to be used to calculate the set of EObjects from which to resolve the specified |
104 |
* <code>proxy</code>. |
105 |
* @param proxy |
106 |
* the object to resolve |
107 |
* @return the resolved object, if the resolution was successful or the original <code>proxy</code> object, if it |
108 |
* was not possible to resolve it. |
109 |
*/ |
74 |
protected EObject eResolveProxyInResourceSet(ResourceSet resourceSet, EObject contextObject, EObject proxy) { |
110 |
protected EObject eResolveProxyInResourceSet(ResourceSet resourceSet, EObject contextObject, EObject proxy) { |
75 |
Assert.isNotNull(resourceSet); |
111 |
Assert.isNotNull(resourceSet); |
76 |
Assert.isNotNull(proxy); |
112 |
Assert.isNotNull(proxy); |
Lines 78-87
Link Here
|
78 |
URI proxyURI = ((InternalEObject) proxy).eProxyURI(); |
114 |
URI proxyURI = ((InternalEObject) proxy).eProxyURI(); |
79 |
|
115 |
|
80 |
// Retrieve proxy helper in order to resolve proxy in a performance-optimized way |
116 |
// Retrieve proxy helper in order to resolve proxy in a performance-optimized way |
81 |
ProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(resourceSet); |
117 |
IProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(resourceSet); |
82 |
if (proxyHelper != null) { |
118 |
if (proxyHelper != null) { |
83 |
// If proxy URI references a known unresolved proxy then don't try to resolve it again |
119 |
// If proxy URI references a known unresolved proxy then don't try to resolve it again |
84 |
if (proxyHelper.getBlackList().existsProxyURI(proxyURI)) { |
120 |
if (proxyHelper.getBlackList().existsProxy(proxy)) { |
85 |
return proxy; |
121 |
return proxy; |
86 |
} |
122 |
} |
87 |
|
123 |
|
Lines 89-95
Link Here
|
89 |
if (proxyURI.segmentCount() == 0) { |
125 |
if (proxyURI.segmentCount() == 0) { |
90 |
// If lookup-based proxy resolution is possible then go ahead and try to do so |
126 |
// If lookup-based proxy resolution is possible then go ahead and try to do so |
91 |
if (proxyURI.segmentCount() == 0 && proxyHelper.getLookupResolver().isAvailable()) { |
127 |
if (proxyURI.segmentCount() == 0 && proxyHelper.getLookupResolver().isAvailable()) { |
92 |
EObject resolvedEObject = proxyHelper.getLookupResolver().get(proxyURI); |
128 |
EObject resolvedEObject = proxyHelper.getLookupResolver().get(proxy); |
93 |
if (resolvedEObject != null) { |
129 |
if (resolvedEObject != null) { |
94 |
return resolvedEObject; |
130 |
return resolvedEObject; |
95 |
} |
131 |
} |
Lines 101-126
Link Here
|
101 |
} |
137 |
} |
102 |
} |
138 |
} |
103 |
} |
139 |
} |
104 |
EObjectResolveRequest resolveRequest = new EObjectResolveRequest(proxy, contextObject); |
140 |
if (proxyHelper.shouldResolve(proxy, contextObject)) { |
105 |
resolveRequest.setIncludeUnloadedEObjects(true); |
141 |
EObjectResolveRequest resolveRequest = new EObjectResolveRequest(proxy, contextObject); |
106 |
EObject resolvedEObject = fEObjectResolver.resolve(resolveRequest); |
142 |
resolveRequest.setIncludeUnloadedEObjects(true); |
|
|
143 |
EObject resolvedEObject = fEObjectResolver.resolve(resolveRequest); |
107 |
|
144 |
|
108 |
if (resolvedEObject == proxy && proxyHelper != null) { |
145 |
if (resolvedEObject == proxy && proxyHelper != null) { |
109 |
// Remember proxy as known unresolved proxy |
146 |
// Remember proxy as known unresolved proxy |
110 |
/* |
147 |
/* |
111 |
* !! Important Note !! Blacklist proxy only if it has the same metamodel or target metamodel as the object |
148 |
* !! Important Note !! Blacklist proxy only if it has the same metamodel or target metamodel as the |
112 |
* that references it. When the target object for the proxy of some other metamodel becomes available it |
149 |
* object that references it. When the target object for the proxy of some other metamodel becomes |
113 |
* will get loaded into the editing domain/resource set for this other metamodel but not into the same |
150 |
* available it will get loaded into the editing domain/resource set for this other metamodel but not |
114 |
* editing domain/resource set that contains the object referencing the proxy. Therefore the proxy must also |
151 |
* into the same editing domain/resource set that contains the object referencing the proxy. Therefore |
115 |
* be blacklisted only by the proxy helper adapter of the other resource set but not by the proxy helper |
152 |
* the proxy must also be blacklisted only by the proxy helper adapter of the other resource set but not |
116 |
* adapter of this resource set. |
153 |
* by the proxy helper adapter of this resource set. |
117 |
*/ |
154 |
*/ |
118 |
IMetaModelDescriptor proxyMMDescriptor = MetaModelDescriptorRegistry.INSTANCE.getDescriptor(proxy.eClass()); |
155 |
IMetaModelDescriptor proxyMMDescriptor = MetaModelDescriptorRegistry.INSTANCE.getDescriptor(proxy.eClass()); |
119 |
IMetaModelDescriptor contextMMDescriptor = MetaModelDescriptorRegistry.INSTANCE.getEffectiveDescriptor(contextObject.eResource()); |
156 |
IMetaModelDescriptor contextMMDescriptor = MetaModelDescriptorRegistry.INSTANCE.getEffectiveDescriptor(contextObject.eResource()); |
120 |
if (proxyMMDescriptor.equals(contextMMDescriptor)) { |
157 |
if (proxyMMDescriptor.equals(contextMMDescriptor)) { |
121 |
proxyHelper.getBlackList().addProxyURI(proxyURI); |
158 |
proxyHelper.handleUnresolvedProxy(proxy); |
|
|
159 |
} |
122 |
} |
160 |
} |
|
|
161 |
|
162 |
return resolvedEObject; |
123 |
} |
163 |
} |
124 |
return resolvedEObject; |
164 |
|
|
|
165 |
return proxy; |
125 |
} |
166 |
} |
126 |
} |
167 |
} |