Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java')
-rw-r--r--plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java
new file mode 100644
index 00000000000..f08d4c9185a
--- /dev/null
+++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.resourceloading/src/org/eclipse/papyrus/infra/services/resourceloading/OnDemandLoadingModelSet.java
@@ -0,0 +1,95 @@
+/**
+ *
+ */
+package org.eclipse.papyrus.infra.services.resourceloading;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.ModelsReader;
+import org.eclipse.papyrus.infra.core.resource.notation.NotationUtils;
+import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils;
+import org.eclipse.papyrus.infra.core.resource.uml.UmlUtils;
+import org.eclipse.papyrus.infra.core.utils.DiResourceSet;
+import org.eclipse.papyrus.infra.services.resourceloading.impl.ProxyManager;
+
+
+/**
+ * A {@link ModelSet} allowing to load models on demand.
+ * Also, this implementation allows to have loading strategies.
+ *
+ * TODO extends {@link ModelSet} rather than {@link DiResourceSet}. This can be done once
+ * DiResourceSet is not referenced anywhere.
+ *
+ * @author cedric dumoulin
+ * @author emilien perico
+ *
+ */
+public class OnDemandLoadingModelSet extends DiResourceSet {
+
+ /** Set that enables to always load the uri with any strategy. */
+ private Set<URI> uriLoading = new HashSet<URI>();
+
+ /**
+ * The proxy manager that loads the model according to a specific strategy.
+ */
+ private IProxyManager proxyManager;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public OnDemandLoadingModelSet() {
+ super();
+ // Register declared models
+ ModelsReader reader = new ModelsReader();
+ reader.readModel(this);
+ proxyManager = new ProxyManager(this);
+ }
+
+
+
+ @Override
+ public void unload() {
+ super.unload();
+ proxyManager.dispose();
+ }
+
+
+
+ /**
+ * @see org.eclipse.emf.ecore.resource.impl.ResourceSetImpl#getEObject(org.eclipse.emf.common.util.URI, boolean)
+ */
+ @Override
+ public EObject getEObject(URI uri, boolean loadOnDemand) {
+ //return super.getEObject(uri, loadOnDemand);
+
+ URI resourceURI = uri.trimFragment();
+ // for performance reasons, we check the three initial resources first
+ // TODO not use getUMLModel
+ if(resourceURI.equals(UmlUtils.getUmlModel(this).getResourceURI()) || resourceURI.equals(NotationUtils.getNotationModel(this).getResourceURI()) || resourceURI.equals(SashModelUtils.getSashModel(this).getResourceURI()) || uriLoading.contains(resourceURI)) {
+ // do not manage eObject of the current resources
+ return super.getEObject(uri, loadOnDemand);
+ } else if(loadOnDemand) {
+ return proxyManager.getEObjectFromStrategy(uri);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Enables to add an URI that will be always loaded.
+ * It is not listening at the current loading strategy and always load the specified URI if needed.
+ *
+ * @param alwaysLoadedUri
+ * the always loaded uri
+ */
+ public void forceUriLoading(URI alwaysLoadedUri) {
+ uriLoading.add(alwaysLoadedUri);
+ }
+
+}

Back to the top