View | Details | Raw Unified | Return to bug 351145
Collapse All | Expand All

(-)src/org/eclipse/sphinx/emf/workspace/loading/ModelLoadManager.java (-9 / +11 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 * 
3
 * 
4
 * Copyright (c) 2008-2012 BMW Car IT, itemis, See4sys and others.
4
 * Copyright (c) 2008-2012 BMW Car IT, itemis, See4sys, 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 11-16 Link Here
11
 *     See4sys - Initial API and implementation
11
 *     See4sys - Initial API and implementation
12
 *     BMW Car IT - [374883] Improve handling of out-of-sync workspace files during descriptor initialization
12
 *     BMW Car IT - [374883] Improve handling of out-of-sync workspace files during descriptor initialization
13
 *     itemis - [393021] ClassCastExceptions raised during loading model resources with Sphinx are ignored
13
 *     itemis - [393021] ClassCastExceptions raised during loading model resources with Sphinx are ignored
14
 *      CES - Refactoring for a more extensible framework
15
14
 * 
16
 * 
15
 * </copyright>
17
 * </copyright>
16
 */
18
 */
Lines 51-60 Link Here
51
import org.eclipse.emf.transaction.TransactionalEditingDomain;
53
import org.eclipse.emf.transaction.TransactionalEditingDomain;
52
import org.eclipse.emf.transaction.util.TransactionUtil;
54
import org.eclipse.emf.transaction.util.TransactionUtil;
53
import org.eclipse.osgi.util.NLS;
55
import org.eclipse.osgi.util.NLS;
54
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelper;
56
import org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer;
57
import org.eclipse.sphinx.emf.ecore.proxymanagement.ILookupResolver;
58
import org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper;
55
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelperAdapterFactory;
59
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelperAdapterFactory;
56
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.blacklist.ModelIndex;
57
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.lookupresolver.EcoreIndex;
58
import org.eclipse.sphinx.emf.internal.resource.ResourceProblemMarkerService;
60
import org.eclipse.sphinx.emf.internal.resource.ResourceProblemMarkerService;
59
import org.eclipse.sphinx.emf.metamodel.IMetaModelDescriptor;
61
import org.eclipse.sphinx.emf.metamodel.IMetaModelDescriptor;
60
import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry;
62
import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry;
Lines 746-752 Link Here
746
					}
748
					}
747
749
748
					// Disable resolution of fragment-based proxies while model loading is ongoing
750
					// Disable resolution of fragment-based proxies while model loading is ongoing
749
					ProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(editingDomain.getResourceSet());
751
					IProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(editingDomain.getResourceSet());
750
					if (proxyHelper != null) {
752
					if (proxyHelper != null) {
751
						proxyHelper.setIgnoreFragmentBasedProxies(true);
753
						proxyHelper.setIgnoreFragmentBasedProxies(true);
752
					}
754
					}
Lines 805-817 Link Here
805
		}
807
		}
806
	}
808
	}
807
809
808
	private void updateUnresolvedProxyBlackList(Collection<IFile> files, ModelIndex blackList) {
810
	private void updateUnresolvedProxyBlackList(Collection<IFile> files, IBlackListingIndexer iBlackListingIndexer) {
809
		Assert.isNotNull(files);
811
		Assert.isNotNull(files);
810
		Assert.isNotNull(blackList);
812
		Assert.isNotNull(iBlackListingIndexer);
811
813
812
		for (IFile file : files) {
814
		for (IFile file : files) {
813
			Resource resource = EcorePlatformUtil.getResource(file);
815
			Resource resource = EcorePlatformUtil.getResource(file);
814
			blackList.updateIndexOnResourceLoaded(resource);
816
			iBlackListingIndexer.updateIndexOnResourceLoaded(resource);
815
		}
817
		}
816
	}
818
	}
817
819
Lines 819-825 Link Here
819
	 * This is a fast implementation of proxy resolution. The idea is to use a map of URI -> EObject to quickly get
821
	 * This is a fast implementation of proxy resolution. The idea is to use a map of URI -> EObject to quickly get
820
	 * object.
822
	 * object.
821
	 */
823
	 */
822
	private void forceProxyResolution(Collection<IFile> files, EcoreIndex lookupResolver, IProgressMonitor monitor) {
824
	private void forceProxyResolution(Collection<IFile> files, ILookupResolver lookupResolver, IProgressMonitor monitor) {
823
		Assert.isNotNull(files);
825
		Assert.isNotNull(files);
824
		Assert.isNotNull(lookupResolver);
826
		Assert.isNotNull(lookupResolver);
825
		SubMonitor progress = SubMonitor.convert(monitor, 100);
827
		SubMonitor progress = SubMonitor.convert(monitor, 100);
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 22-28 Link Here
22
 org.eclipse.sphinx.emf.internal.ecore;x-internal:=true,
22
 org.eclipse.sphinx.emf.internal.ecore;x-internal:=true,
23
 org.eclipse.sphinx.emf.internal.ecore.proxymanagement;x-internal:=true,
23
 org.eclipse.sphinx.emf.internal.ecore.proxymanagement;x-internal:=true,
24
 org.eclipse.sphinx.emf.internal.ecore.proxymanagement.blacklist;x-internal:=true,
24
 org.eclipse.sphinx.emf.internal.ecore.proxymanagement.blacklist;x-internal:=true,
25
 org.eclipse.sphinx.emf.internal.ecore.proxymanagement.lookupresolver;x-internal:=true,
26
 org.eclipse.sphinx.emf.internal.ecore.proxymanagement.resolver;x-internal:=true,
25
 org.eclipse.sphinx.emf.internal.ecore.proxymanagement.resolver;x-internal:=true,
27
 org.eclipse.sphinx.emf.internal.expressions;x-internal:=true,
26
 org.eclipse.sphinx.emf.internal.expressions;x-internal:=true,
28
 org.eclipse.sphinx.emf.internal.filesystem;x-internal:=true,
27
 org.eclipse.sphinx.emf.internal.filesystem;x-internal:=true,
(-)src/org/eclipse/sphinx/emf/ecore/proxymanagement/DefaultProxyHelperAdapter.java (+148 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 * 
4
 * Copyright (c) 2008-2013 See4sys, Continental Engineering Services (CES) and others.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *     See4sys - Initial API and implementation
12
 *     CES - Refactoring for a more extensible framework
13
 * 
14
 * </copyright>
15
 */
16
package org.eclipse.sphinx.emf.ecore.proxymanagement;
17
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
22
import org.eclipse.emf.common.notify.Adapter;
23
import org.eclipse.emf.common.notify.Notifier;
24
import org.eclipse.emf.common.notify.impl.AdapterImpl;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.ecore.InternalEObject;
27
import org.eclipse.emf.ecore.resource.ResourceSet;
28
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.blacklist.ModelIndex;
29
import org.eclipse.sphinx.platform.IExtendedPlatformConstants;
30
31
/**
32
 * {@link Adapter}-based implementation of {@link IProxyHelper}. May be used with {@link ResourceSet}s.This is a default
33
 * and generic implementation. Clients can override this class and provide a more efficient implementation, by taking
34
 * benefit from the specifics of the used meta-model.
35
 * 
36
 * @deprecated Will be removed as soon as a full-fledged model indexing service is in place and can be used to overcome
37
 *             performance bottlenecks due to proxy resolution.
38
 */
39
@Deprecated
40
public class DefaultProxyHelperAdapter extends AdapterImpl implements IProxyHelper {
41
42
	private EcoreIndex fLookupResolver = new EcoreIndex();
43
	private ModelIndex fBlackList = new ModelIndex();
44
45
	private boolean fIgnoreFragmentBasedProxies = false;
46
	private IgnoreFragmentBasedProxiesFlagResetter fIgnoreFragmentBasedProxiesFlagResetter = new IgnoreFragmentBasedProxiesFlagResetter();
47
48
	/*
49
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper#isIgnoreFragmentBasedProxies()
50
	 */
51
	public boolean isIgnoreFragmentBasedProxies() {
52
		return fIgnoreFragmentBasedProxies;
53
	}
54
55
	/*
56
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper#setIgnoreFragmentBasedProxies(boolean)
57
	 */
58
	public void setIgnoreFragmentBasedProxies(boolean ignore) {
59
		fIgnoreFragmentBasedProxies = ignore;
60
61
		if (ignore) {
62
			Job.getJobManager().addJobChangeListener(fIgnoreFragmentBasedProxiesFlagResetter);
63
		} else {
64
			Job.getJobManager().removeJobChangeListener(fIgnoreFragmentBasedProxiesFlagResetter);
65
		}
66
	}
67
68
	/*
69
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper#getLookupResolver()
70
	 */
71
	public ILookupResolver getLookupResolver() {
72
		return fLookupResolver;
73
	}
74
75
	/*
76
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper#getBlackList()
77
	 */
78
	public IBlackListingIndexer getBlackList() {
79
		return fBlackList;
80
	}
81
82
	/*
83
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper#dispose()
84
	 */
85
	public void dispose() {
86
		fBlackList.dispose();
87
	}
88
89
	/*
90
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper#shouldResolve(org.eclipse.emf.ecore.EObject,
91
	 * org.eclipse.emf.ecore.EObject)
92
	 */
93
	public boolean shouldResolve(EObject proxy, EObject context) {
94
		return true;
95
	}
96
97
	/*
98
	 * @see
99
	 * org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper#handleUnresolvedProxy(org.eclipse.emf.ecore.EObject)
100
	 */
101
	public void handleUnresolvedProxy(EObject proxy) {
102
103
		getBlackList().addProxyURI(((InternalEObject) proxy).eProxyURI());
104
105
	}
106
107
	/*
108
	 * @see org.eclipse.emf.common.notify.impl.AdapterImpl#isAdapterForType(java.lang.Object)
109
	 */
110
	@Override
111
	public boolean isAdapterForType(Object type) {
112
		return type == IProxyHelper.class;
113
	}
114
115
	/*
116
	 * @see org.eclipse.emf.common.notify.impl.AdapterImpl#setTarget(org.eclipse.emf.common.notify.Notifier)
117
	 */
118
	@Override
119
	public void setTarget(Notifier newTarget) {
120
		Assert.isLegal(newTarget == null || newTarget instanceof ResourceSet);
121
		super.setTarget(newTarget);
122
	}
123
124
	protected class IgnoreFragmentBasedProxiesFlagResetter extends JobChangeAdapter {
125
126
		private boolean isModelLoadingJob(IJobChangeEvent event) {
127
			if (event != null) {
128
				Job job = event.getJob();
129
				if (job != null) {
130
					return job.belongsTo(IExtendedPlatformConstants.FAMILY_MODEL_LOADING);
131
				}
132
			}
133
			return false;
134
		}
135
136
		@Override
137
		public void done(IJobChangeEvent event) {
138
			if (isModelLoadingJob(event)) {
139
				// Make sure that resolution of fragment-based proxies gets re-enabled in case that this is the last
140
				// running model loading job
141
				if (Job.getJobManager().find(IExtendedPlatformConstants.FAMILY_MODEL_LOADING).length <= 1) {
142
					setIgnoreFragmentBasedProxies(false);
143
				}
144
			}
145
		}
146
	}
147
148
}
(-)src/org/eclipse/sphinx/emf/ecore/proxymanagement/EcoreIndex.java (+110 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 * 
4
 * Copyright (c) 2008-2013 See4sys, Continental Engineering Services (CES)  and others.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *     See4sys - Initial API and implementation
12
 *     CES - Refactoring for a more extensible framework
13
 * 
14
 * </copyright>
15
 */
16
package org.eclipse.sphinx.emf.ecore.proxymanagement;
17
18
import java.util.Collection;
19
import java.util.HashMap;
20
import java.util.Iterator;
21
import java.util.Map;
22
23
import org.eclipse.core.runtime.Assert;
24
import org.eclipse.emf.common.util.URI;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.ecore.InternalEObject;
27
import org.eclipse.emf.ecore.resource.Resource;
28
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.sphinx.platform.messages.PlatformMessages;
30
31
/**
32
 * Simple implementation of Ecore Index (associating fragmend-based URIs with EObjects). Used at the end of model
33
 * loading operations in order to optimize proxy resolution for performance.
34
 * 
35
 * @deprecated Will be removed as soon as a full-fledged model indexing service is in place and can be used to overcome
36
 *             performance bottlenecks due to proxy resolution.
37
 */
38
@Deprecated
39
public class EcoreIndex implements ILookupResolver {
40
41
	// TODO Precise the resource for which we have to maintain this map.
42
	private Map<String, EObject> index = null;
43
44
	/**
45
	 * 
46
	 */
47
	private void assertIsAvailable() {
48
		if (!isAvailable()) {
49
			throw new RuntimeException(NLS.bind(PlatformMessages.error_mustNotBeNull, "index")); //$NON-NLS-1$
50
		}
51
	}
52
53
	/*
54
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.ILookupResolver#isAvailable()
55
	 */
56
	public boolean isAvailable() {
57
		return index != null;
58
	}
59
60
	/*
61
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.ILookupResolver#clear()
62
	 */
63
	public void clear() {
64
		assertIsAvailable();
65
		index = null;
66
	}
67
68
	private void init() {
69
		index = new HashMap<String, EObject>();
70
	}
71
72
	/**
73
	 * Resolves the lookup of an object represented by the given <code>uri</code>, if the lookup-based proxy resolution
74
	 * <code>isAvailable()</code>.
75
	 * 
76
	 * @param uri
77
	 *            the resource identifier of the object to resolve
78
	 * @return the object if it was resolved or <code>null</code>, otherwise.
79
	 */
80
	private EObject get(URI uri) {
81
		assertIsAvailable();
82
		Assert.isNotNull(uri, NLS.bind(PlatformMessages.arg_mustNotBeNull, "uri")); //$NON-NLS-1$
83
		return index.get(uri.fragment());
84
	}
85
86
	/*
87
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.ILookupResolver#get(org.eclipse.emf.ecore.InternalEObject)
88
	 */
89
	public EObject get(EObject proxy) {
90
		Assert.isNotNull(proxy, NLS.bind(PlatformMessages.arg_mustNotBeNull, "proxy")); //$NON-NLS-1$
91
		return get(((InternalEObject) proxy).eProxyURI());
92
	}
93
94
	/*
95
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.ILookupResolver#init(java.util.Collection)
96
	 */
97
	public void init(Collection<Resource> resources) {
98
		if (!isAvailable()) {
99
			init();
100
		}
101
		for (Resource resource : resources) {
102
			for (Iterator<EObject> i = resource.getAllContents(); i.hasNext();) {
103
				EObject o = i.next();
104
				String fragment = resource.getURIFragment(o);
105
				// FIXME A object (from another resource for instance) may already have been put with the same URI.
106
				index.put(fragment, o);
107
			}
108
		}
109
	}
110
}
(-)src/org/eclipse/sphinx/emf/ecore/proxymanagement/IBlackListingIndexer.java (+113 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 * 
4
 * Copyright (c) 2013 Continental Engineering Services (CES) and others.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *     CES - Initial API and implementation
12
 * 
13
 * </copyright>
14
 */
15
package org.eclipse.sphinx.emf.ecore.proxymanagement;
16
17
import org.eclipse.emf.common.util.URI;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.resource.Resource;
20
21
/**
22
 * Indexing service used for blacklisting unresolvable proxies. Makes use of a structure where it keeps track of the URI
23
 * of unresolved proxy objects. It also registers a listener for resource changes and reacts accordingly to resource
24
 * load/unload by updating also the indexing structure behind.
25
 */
26
27
public interface IBlackListingIndexer {
28
29
	/**
30
	 * Sets whether the blacklisting indexing service should be enabled. Note that before making changes (search, add,
31
	 * remove proxy URI or update index) on the structure for the indexing service, the service should be enabled.
32
	 * 
33
	 * @param enabled
34
	 *            the state of the indexing service
35
	 */
36
	public void setEnabled(boolean enabled);
37
38
	/**
39
	 * Clears the structure on which the indexing service was performed, without removing the listener for resource
40
	 * changes.
41
	 */
42
	public void clearAll();
43
44
	/**
45
	 * Clears the structure on which the indexing was performed and also removes the listener for resource changes.
46
	 */
47
	public void dispose();
48
49
	/**
50
	 * Returns whether the given <code>fragmentUri</code> exists in the structure on which the indexing is performed.
51
	 * 
52
	 * @param fragmentUri
53
	 *            the fragment URI to search for
54
	 * @return <code>true</code>, if the given URI is found; <code>false</code>, otherwise
55
	 */
56
	public boolean exists(URI fragmentUri);
57
58
	/**
59
	 * Returns whether the proxy with the given <code>proxyURI</code> exists in the structure on which the indexing is
60
	 * performed.
61
	 * 
62
	 * @param proxyURI
63
	 *            the proxy URI to search for
64
	 * @return <code>true</code>, if the given URI is found; <code>false</code>, otherwise
65
	 */
66
	public boolean existsProxyURI(URI proxyURI);
67
68
	/**
69
	 * Returns whether the given <code>proxy</code> object exists in the structure on which the indexing is performed.
70
	 * 
71
	 * @param proxy
72
	 *            the proxy object to search for
73
	 * @return <code>true</code>, if the given object is found; <code>false</code>, otherwise
74
	 */
75
	public boolean existsProxy(EObject proxy);
76
77
	/**
78
	 * Adds the the proxy with the given <code>proxyURI</code> in the structure of the indexing service.
79
	 * 
80
	 * @param proxyURI
81
	 *            the given URI to add
82
	 * @return <code>true</code> if the URI was added; <code>false</code>, if indexing service is not enabled or the URI
83
	 *         already exists
84
	 */
85
	public boolean addProxyURI(URI proxyURI);
86
87
	/**
88
	 * Removes the the proxy with the given <code>proxyURI</code> in the structure of the indexing service.
89
	 * 
90
	 * @param proxyURI
91
	 *            the given URI to add
92
	 * @return <code>true</code> if the URI was removed; <code>false</code>, if indexing service is not enabled or the
93
	 *         URI does not exist
94
	 */
95
	public boolean removeProxyURI(URI proxyURI);
96
97
	/**
98
	 * Updates the indexing structure, trying to resolve the stored proxy objects against the loaded resource.
99
	 * 
100
	 * @param notifier
101
	 *            the resource that was loaded
102
	 */
103
	public void updateIndexOnResourceLoaded(Resource notifier);
104
105
	/**
106
	 * Updates the indexing structure, by removing the stored proxy URIs belonging to the unloaded resource.
107
	 * 
108
	 * @param notifier
109
	 *            the resource that was unloaded
110
	 */
111
	public void updateIndexOnResourceUnloaded(Resource notifier);
112
113
}
(-)src/org/eclipse/sphinx/emf/ecore/proxymanagement/ILookupResolver.java (+60 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 * 
4
 * Copyright (c) 2013 Continental Engineering Services (CES) and others.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *     CES - Initial API and implementation
12
 * 
13
 * </copyright>
14
 */
15
package org.eclipse.sphinx.emf.ecore.proxymanagement;
16
17
import java.util.Collection;
18
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.resource.Resource;
21
22
/**
23
 * Performs a lookup of objects inside a collection of resources. It is used at the end of model loading operations in
24
 * order to optimize proxy resolution for performance.
25
 */
26
public interface ILookupResolver {
27
28
	/**
29
	 * Returns whether the lookup-based proxy resolution was initialized and the lookup can be performed. If not, a call
30
	 * to <code>init</code> is necessary.
31
	 * 
32
	 * @return <code>true</code> if the lookup can be performed; <code>false</code> otherwise.
33
	 */
34
	public boolean isAvailable();
35
36
	/**
37
	 * Clears the structure on which the lookup-based proxy resolution was performed.
38
	 */
39
	public void clear();
40
41
	/**
42
	 * Resolves the lookup of an object represented by the given <code>proxy</code> object, if the lookup-based proxy
43
	 * resolution <code>isAvailable()</code>.
44
	 * 
45
	 * @param proxy
46
	 *            the proxy representing the object to resolve
47
	 * @return the object if it was resolved or <code>null</code>, otherwise.
48
	 */
49
	public EObject get(EObject proxy);
50
51
	/**
52
	 * Initializes the structure on which to perform the lookup-based proxy resolution, with the given
53
	 * <code>resources</code>.
54
	 * 
55
	 * @param resources
56
	 *            the collection of resources where the lookup will be performed
57
	 */
58
	public void init(Collection<Resource> resources);
59
60
}
(-)src/org/eclipse/sphinx/emf/ecore/proxymanagement/IProxyHelper.java (+86 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 * 
4
 * Copyright (c) 2008-2013 See4sys, Continental Engineering Services (CES) and others.
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 * 
10
 * Contributors: 
11
 *     See4sys - Initial API and implementation
12
 *     CES - Refactoring for a more extensible framework
13
 * 
14
 * </copyright>
15
 */
16
package org.eclipse.sphinx.emf.ecore.proxymanagement;
17
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.resource.ResourceSet;
20
21
/**
22
 * A set of {@link ResourceSet} level services which can be used to optimize proxy resolution for performance. Uses a
23
 * {@link ILookupResolver} to resolve objects and {@link IBlackListingIndexer} for keeping track of the unresolved proxy
24
 * objects. Clients can take benefit of the particularities of the used meta-model and decide if the attept to resolve a
25
 * proxy object should be made and also how to handle an unresolved proxy.
26
 */
27
public interface IProxyHelper {
28
29
	/**
30
	 * Returns whether the fragment-based proxies are ignored at proxy resolution.
31
	 * 
32
	 * @return <code>true</code>, if fragment-based proxiesa are ignored; <code>false</code>, otherwise.
33
	 */
34
	boolean isIgnoreFragmentBasedProxies();
35
36
	/**
37
	 * Sets the flag indicating if the fragment-based proxies are ignored at proxy resolution.
38
	 * 
39
	 * @param ignoreFragmentBasedProxies
40
	 *            whether to ignore fragment-based proxies
41
	 */
42
	void setIgnoreFragmentBasedProxies(boolean ignoreFragmentBasedProxies);
43
44
	/**
45
	 * Returns the lookup resolver that performs a lookup of objects.
46
	 * 
47
	 * @return the lookup resolver
48
	 */
49
	ILookupResolver getLookupResolver();
50
51
	/**
52
	 * Returns the indexing service used for unresolvable proxies.
53
	 * 
54
	 * @return
55
	 */
56
	IBlackListingIndexer getBlackList();
57
58
	/**
59
	 * Performs all the needed dispose operations.
60
	 */
61
	void dispose();
62
63
	/**
64
	 * Returns whether to try to resolve the given <code>proxy</code> object, in the given <code>context</code> object.
65
	 * The proxy resolution operation is time-consuming, because the attemt to resolve the object is performed inside
66
	 * the entire resource set. This is the last change for clients of this method to abort it, if it is not necessary
67
	 * to perform it at this point.
68
	 * 
69
	 * @param proxy
70
	 *            the EObject containing the URI of the EObject to resolve scopeContext
71
	 * @param context
72
	 *            the EObject used to calculate the set of EObjects from which to resolve the specified proxy
73
	 * @return <code>true</code>, if the attempt to resolve the object is performed; <code>false</code>, if the object
74
	 *         remains unresolved.
75
	 */
76
	boolean shouldResolve(EObject proxy, EObject context);
77
78
	/**
79
	 * Performs the necessary operations for handling an unresolved proxy.
80
	 * 
81
	 * @param proxy
82
	 *            the unresolved proxy object
83
	 */
84
	void handleUnresolvedProxy(EObject proxy);
85
86
}
(-)src/org/eclipse/sphinx/emf/ecore/proxymanagement/ProxyResolutionBehavior.java (-24 / +65 lines)
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
}
(-)src/org/eclipse/sphinx/emf/internal/ecore/proxymanagement/ProxyHelperAdapterFactory.java (-17 / +17 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 * 
3
 * 
4
 * Copyright (c) 2008-2012 See4sys, BMW Car IT and others.
4
 * Copyright (c) 2008-2012 See4sys, BMW Car IT, 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
 *     See4sys - Initial API and implementation
11
 *     See4sys - Initial API and implementation
12
 *     BMW Car IT - Avoid usage of Object.finalize
12
 *     BMW Car IT - Avoid usage of Object.finalize
13
 *     CES - Refactoring for a more extensible framework
13
 * 
14
 * 
14
 * </copyright>
15
 * </copyright>
15
 */
16
 */
Lines 17-22 Link Here
17
18
18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.emf.common.notify.Adapter;
20
import org.eclipse.emf.common.notify.Adapter;
21
import org.eclipse.emf.common.notify.AdapterFactory;
20
import org.eclipse.emf.common.notify.Notifier;
22
import org.eclipse.emf.common.notify.Notifier;
21
import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
23
import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl;
22
import org.eclipse.emf.ecore.resource.ResourceSet;
24
import org.eclipse.emf.ecore.resource.ResourceSet;
Lines 24-38 Link Here
24
import org.eclipse.emf.transaction.TransactionalEditingDomain;
26
import org.eclipse.emf.transaction.TransactionalEditingDomain;
25
import org.eclipse.sphinx.emf.domain.factory.EditingDomainFactoryListenerRegistry;
27
import org.eclipse.sphinx.emf.domain.factory.EditingDomainFactoryListenerRegistry;
26
import org.eclipse.sphinx.emf.domain.factory.ITransactionalEditingDomainFactoryListener;
28
import org.eclipse.sphinx.emf.domain.factory.ITransactionalEditingDomainFactoryListener;
29
import org.eclipse.sphinx.emf.ecore.proxymanagement.DefaultProxyHelperAdapter;
30
import org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper;
27
import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry;
31
import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry;
28
32
29
/**
33
/**
30
 * An {@link AdapterFactory adapter factory} for creating {@link ProxyHelper} adapters on {@link ResourceSet}s.
34
 * An {@link AdapterFactory adapter factory} for creating {@link IProxyHelper} adapters on {@link ResourceSet}s.
31
 * 
32
 * @deprecated Will be removed as soon as a full-fledged model indexing service is in place and can be used to overcome
33
 *             performance bottlenecks due to proxy resolution.
34
 */
35
 */
35
@Deprecated
36
public class ProxyHelperAdapterFactory extends AdapterFactoryImpl implements ITransactionalEditingDomainFactoryListener {
36
public class ProxyHelperAdapterFactory extends AdapterFactoryImpl implements ITransactionalEditingDomainFactoryListener {
37
37
38
	/**
38
	/**
Lines 61-86 Link Here
61
	 */
61
	 */
62
	@Override
62
	@Override
63
	public boolean isFactoryForType(Object type) {
63
	public boolean isFactoryForType(Object type) {
64
		return type == ProxyHelper.class;
64
		return type == IProxyHelper.class;
65
	}
65
	}
66
66
67
	/**
67
	/**
68
	 * Returns either a previously associated {@link ProxyHelper} adapter or a newly associated one, as appropriate.
68
	 * Returns either a previously associated {@link IProxyHelper} adapter or a newly associated one, as appropriate.
69
	 * {@link Adapter#isAdapterForType(Object) Checks} if the an adapter for {@link ProxyHelper} is already associated
69
	 * {@link Adapter#isAdapterForType(Object) Checks} if the an adapter for {@link IProxyHelper} is already associated
70
	 * with the target and returns it in that case; {@link AdapterFactory#adaptNew(Notifier, Object) creates} a new
70
	 * with the target and returns it in that case; {@link AdapterFactory#adaptNew(Notifier, Object) creates} a new
71
	 * {@link ProxyHelper} adapter if possible otherwise.
71
	 * {@link IProxyHelper} adapter if possible otherwise.
72
	 * 
72
	 * 
73
	 * @param target
73
	 * @param target
74
	 *            The notifier to adapt.
74
	 *            The notifier to adapt.
75
	 * @return A previously existing associated {@link ProxyHelper} adapter, a new associated {@link ProxyHelper}
75
	 * @return A previously existing associated {@link IProxyHelper} adapter, a new associated {@link IProxyHelper}
76
	 *         adapter if possible, or <code>null</code> otherwise.
76
	 *         adapter if possible, or <code>null</code> otherwise.
77
	 * @see AdapterFactory#adapt(Notifier, Object)
77
	 * @see AdapterFactory#adapt(Notifier, Object)
78
	 * @see Adapter#isAdapterForType(Object)
78
	 * @see Adapter#isAdapterForType(Object)
79
	 * @see AdapterFactory#adaptNew(Notifier, Object)
79
	 * @see AdapterFactory#adaptNew(Notifier, Object)
80
	 */
80
	 */
81
	public ProxyHelper adapt(Notifier target) {
81
	public IProxyHelper adapt(Notifier target) {
82
		if (target != null) {
82
		if (target != null) {
83
			return (ProxyHelper) adapt(target, ProxyHelper.class);
83
			return (IProxyHelper) adapt(target, IProxyHelper.class);
84
		}
84
		}
85
		return null;
85
		return null;
86
	}
86
	}
Lines 91-97 Link Here
91
	@Override
91
	@Override
92
	protected Adapter createAdapter(Notifier target) {
92
	protected Adapter createAdapter(Notifier target) {
93
		if (target instanceof ResourceSet) {
93
		if (target instanceof ResourceSet) {
94
			return new ProxyHelperAdapter();
94
			return new DefaultProxyHelperAdapter();
95
		}
95
		}
96
		return null;
96
		return null;
97
	}
97
	}
Lines 111-119 Link Here
111
	 * eclipse .emf.transaction.TransactionalEditingDomain)
111
	 * eclipse .emf.transaction.TransactionalEditingDomain)
112
	 */
112
	 */
113
	public void preDisposeEditingDomain(TransactionalEditingDomain editingDomain) {
113
	public void preDisposeEditingDomain(TransactionalEditingDomain editingDomain) {
114
		Adapter adapter = EcoreUtil.getExistingAdapter(editingDomain.getResourceSet(), ProxyHelper.class);
114
		Adapter adapter = EcoreUtil.getExistingAdapter(editingDomain.getResourceSet(), IProxyHelper.class);
115
		if (adapter instanceof ProxyHelperAdapter) {
115
		if (adapter instanceof IProxyHelper) {
116
			((ProxyHelperAdapter) adapter).dispose();
116
			((IProxyHelper) adapter).dispose();
117
		}
117
		}
118
	}
118
	}
119
}
119
}
(-)src/org/eclipse/sphinx/emf/internal/ecore/proxymanagement/blacklist/ModelIndex.java (-1 / +66 lines)
Lines 9-14 Link Here
9
 * 
9
 * 
10
 * Contributors: 
10
 * Contributors: 
11
 *     See4sys - Initial API and implementation
11
 *     See4sys - Initial API and implementation
12
 *     Continental - Refactoring for a more extensible framework
12
 * 
13
 * 
13
 * </copyright>
14
 * </copyright>
14
 */
15
 */
Lines 18-27 Link Here
18
import java.util.Collections;
19
import java.util.Collections;
19
20
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.emf.common.util.URI;
23
import org.eclipse.emf.common.util.URI;
22
import org.eclipse.emf.ecore.EClass;
24
import org.eclipse.emf.ecore.EClass;
23
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.ecore.InternalEObject;
24
import org.eclipse.emf.ecore.resource.Resource;
27
import org.eclipse.emf.ecore.resource.Resource;
28
import org.eclipse.osgi.util.NLS;
29
import org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer;
30
import org.eclipse.sphinx.platform.messages.PlatformMessages;
25
31
26
/**
32
/**
27
 * Indexing service used for blacklisting unresolvable proxies. Used to avoid repeated attempts to resolve such proxies
33
 * Indexing service used for blacklisting unresolvable proxies. Used to avoid repeated attempts to resolve such proxies
Lines 31-60 Link Here
31
 *             performance bottlenecks due to proxy resolution.
37
 *             performance bottlenecks due to proxy resolution.
32
 */
38
 */
33
@Deprecated
39
@Deprecated
34
public class ModelIndex {
40
public class ModelIndex implements IBlackListingIndexer {
35
41
36
	private MapModelIndex mapModelIndex;
42
	private MapModelIndex mapModelIndex;
37
	private boolean enabled;
43
	private boolean enabled;
38
44
45
	/*
46
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#setEnabled(boolean)
47
	 */
39
	public void setEnabled(boolean enabled) {
48
	public void setEnabled(boolean enabled) {
40
		this.enabled = enabled;
49
		this.enabled = enabled;
41
	}
50
	}
42
51
52
	/**
53
	 * 
54
	 */
43
	public ModelIndex() {
55
	public ModelIndex() {
44
		mapModelIndex = new MapModelIndex();
56
		mapModelIndex = new MapModelIndex();
45
		enabled = true;
57
		enabled = true;
46
	}
58
	}
47
59
60
	/*
61
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#clearAll()
62
	 */
48
	public void clearAll() {
63
	public void clearAll() {
49
		if (enabled) {
64
		if (enabled) {
50
			mapModelIndex.clearAll();
65
			mapModelIndex.clearAll();
51
		}
66
		}
52
	}
67
	}
53
68
69
	/*
70
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#dispose()
71
	 */
54
	public void dispose() {
72
	public void dispose() {
55
		mapModelIndex.dispose();
73
		mapModelIndex.dispose();
56
	}
74
	}
57
75
76
	/*
77
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#exists(org.eclipse.emf.common.util.URI)
78
	 */
58
	public boolean exists(URI fragmentUri) {
79
	public boolean exists(URI fragmentUri) {
59
		if (enabled) {
80
		if (enabled) {
60
			return mapModelIndex.exists(fragmentUri);
81
			return mapModelIndex.exists(fragmentUri);
Lines 62-67 Link Here
62
		return false;
83
		return false;
63
	}
84
	}
64
85
86
	/*
87
	 * @see
88
	 * org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#existsProxyURI(org.eclipse.emf.common.util.URI)
89
	 */
65
	public boolean existsProxyURI(URI proxyURI) {
90
	public boolean existsProxyURI(URI proxyURI) {
66
		if (enabled) {
91
		if (enabled) {
67
			return mapModelIndex.existsProxyURI(proxyURI);
92
			return mapModelIndex.existsProxyURI(proxyURI);
Lines 69-74 Link Here
69
		return false;
94
		return false;
70
	}
95
	}
71
96
97
	/*
98
	 * @see org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#existsProxy(org.eclipse.emf.ecore.EObject)
99
	 */
100
	public boolean existsProxy(EObject proxy) {
101
		Assert.isNotNull(proxy, NLS.bind(PlatformMessages.arg_mustNotBeNull, "proxy")); //$NON-NLS-1$
102
		return existsProxyURI(((InternalEObject) proxy).eProxyURI());
103
104
	}
105
106
	/*
107
	 * @see
108
	 * org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#addProxyURI(org.eclipse.emf.common.util.URI)
109
	 */
72
	public boolean addProxyURI(URI proxyURI) {
110
	public boolean addProxyURI(URI proxyURI) {
73
		if (enabled) {
111
		if (enabled) {
74
			return mapModelIndex.addProxyURI(proxyURI);
112
			return mapModelIndex.addProxyURI(proxyURI);
Lines 76-81 Link Here
76
		return false;
114
		return false;
77
	}
115
	}
78
116
117
	/*
118
	 * @see
119
	 * org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#removeProxyURI(org.eclipse.emf.common.util.URI)
120
	 */
79
	public boolean removeProxyURI(URI proxyURI) {
121
	public boolean removeProxyURI(URI proxyURI) {
80
		if (enabled) {
122
		if (enabled) {
81
			return mapModelIndex.removeProxyURI(proxyURI);
123
			return mapModelIndex.removeProxyURI(proxyURI);
Lines 83-100 Link Here
83
		return false;
125
		return false;
84
	}
126
	}
85
127
128
	/*
129
	 * @see
130
	 * org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#updateIndexOnResourceLoaded(org.eclipse.emf
131
	 * .ecore.resource.Resource)
132
	 */
86
	public void updateIndexOnResourceLoaded(Resource notifier) {
133
	public void updateIndexOnResourceLoaded(Resource notifier) {
87
		if (enabled) {
134
		if (enabled) {
88
			mapModelIndex.updateIndexOnResourceLoaded(notifier);
135
			mapModelIndex.updateIndexOnResourceLoaded(notifier);
89
		}
136
		}
90
	}
137
	}
91
138
139
	/*
140
	 * @see
141
	 * org.eclipse.sphinx.emf.ecore.proxymanagement.IBlackListingIndexer#updateIndexOnResourceUnloaded(org.eclipse.emf
142
	 * .ecore.resource.Resource)
143
	 */
92
	public void updateIndexOnResourceUnloaded(Resource notifier) {
144
	public void updateIndexOnResourceUnloaded(Resource notifier) {
93
		if (enabled) {
145
		if (enabled) {
94
			mapModelIndex.updateIndexOnResourceUnloaded(notifier);
146
			mapModelIndex.updateIndexOnResourceUnloaded(notifier);
95
		}
147
		}
96
	}
148
	}
97
149
150
	/**
151
	 * @param eClass
152
	 * @param scope
153
	 * @return
154
	 */
98
	public Collection<URI> findInstances(EClass eClass, IProject scope) {
155
	public Collection<URI> findInstances(EClass eClass, IProject scope) {
99
		if (enabled) {
156
		if (enabled) {
100
			return mapModelIndex.findInstances(eClass, scope);
157
			return mapModelIndex.findInstances(eClass, scope);
Lines 102-107 Link Here
102
		return Collections.emptySet();
159
		return Collections.emptySet();
103
	}
160
	}
104
161
162
	/**
163
	 * @param object
164
	 * @param scope
165
	 * @return
166
	 */
105
	public Collection<URI> findReferencesTo(EObject object, IProject scope) {
167
	public Collection<URI> findReferencesTo(EObject object, IProject scope) {
106
		if (enabled) {
168
		if (enabled) {
107
			return mapModelIndex.findReferencesTo(object, scope);
169
			return mapModelIndex.findReferencesTo(object, scope);
Lines 109-114 Link Here
109
		return Collections.emptySet();
171
		return Collections.emptySet();
110
	}
172
	}
111
173
174
	/**
175
	 * @throws Exception
176
	 */
112
	public void reIndex() throws Exception {
177
	public void reIndex() throws Exception {
113
		if (enabled) {
178
		if (enabled) {
114
			mapModelIndex.reIndex();
179
			mapModelIndex.reIndex();
(-)src/org/eclipse/sphinx/emf/internal/ecore/proxymanagement/blacklist/ModelIndexUpdater.java (-3 / +3 lines)
Lines 40-46 Link Here
40
import org.eclipse.emf.transaction.ResourceSetListenerImpl;
40
import org.eclipse.emf.transaction.ResourceSetListenerImpl;
41
import org.eclipse.sphinx.emf.Activator;
41
import org.eclipse.sphinx.emf.Activator;
42
import org.eclipse.sphinx.emf.domain.factory.AbstractResourceSetListenerInstaller;
42
import org.eclipse.sphinx.emf.domain.factory.AbstractResourceSetListenerInstaller;
43
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelper;
43
import org.eclipse.sphinx.emf.ecore.proxymanagement.IProxyHelper;
44
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelperAdapterFactory;
44
import org.eclipse.sphinx.emf.internal.ecore.proxymanagement.ProxyHelperAdapterFactory;
45
import org.eclipse.sphinx.emf.model.IModelDescriptor;
45
import org.eclipse.sphinx.emf.model.IModelDescriptor;
46
import org.eclipse.sphinx.emf.model.ModelDescriptorRegistry;
46
import org.eclipse.sphinx.emf.model.ModelDescriptorRegistry;
Lines 70-76 Link Here
70
70
71
	@Override
71
	@Override
72
	public void resourceSetChanged(ResourceSetChangeEvent event) {
72
	public void resourceSetChanged(ResourceSetChangeEvent event) {
73
		ProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(event.getEditingDomain().getResourceSet());
73
		IProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(event.getEditingDomain().getResourceSet());
74
		List<?> notifications = event.getNotifications();
74
		List<?> notifications = event.getNotifications();
75
		for (Object object : notifications) {
75
		for (Object object : notifications) {
76
			if (object instanceof Notification) {
76
			if (object instanceof Notification) {
Lines 142-148 Link Here
142
						}
142
						}
143
						for (Resource resource : updatedResources) {
143
						for (Resource resource : updatedResources) {
144
							if (resource.isLoaded()) {
144
							if (resource.isLoaded()) {
145
								ProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(resource.getResourceSet());
145
								IProxyHelper proxyHelper = ProxyHelperAdapterFactory.INSTANCE.adapt(resource.getResourceSet());
146
								proxyHelper.getBlackList().updateIndexOnResourceLoaded(resource);
146
								proxyHelper.getBlackList().updateIndexOnResourceLoaded(resource);
147
							}
147
							}
148
						}
148
						}

Return to bug 351145