Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreperico2010-04-28 13:45:11 +0000
committereperico2010-04-28 13:45:11 +0000
commitd4847ed2bb9d78c00d14526201e077b800c2ea8a (patch)
tree798d8b1572a3eae90bf17c1d00d93f86ad62c7b6
parent94240cb121565fcc2e0c61a0c7d59052365a4e4f (diff)
downloadorg.eclipse.papyrus-d4847ed2bb9d78c00d14526201e077b800c2ea8a.tar.gz
org.eclipse.papyrus-d4847ed2bb9d78c00d14526201e077b800c2ea8a.tar.xz
org.eclipse.papyrus-d4847ed2bb9d78c00d14526201e077b800c2ea8a.zip
manage profile loading
-rw-r--r--org.eclipse.papyrus.resourceloading.umlprofile/src/org/eclipse/papyrus/resourceloading/umlprofile/UMLProfileStrategyExtension.java73
1 files changed, 53 insertions, 20 deletions
diff --git a/org.eclipse.papyrus.resourceloading.umlprofile/src/org/eclipse/papyrus/resourceloading/umlprofile/UMLProfileStrategyExtension.java b/org.eclipse.papyrus.resourceloading.umlprofile/src/org/eclipse/papyrus/resourceloading/umlprofile/UMLProfileStrategyExtension.java
index 5d405ba6f44..f5430fc96d5 100644
--- a/org.eclipse.papyrus.resourceloading.umlprofile/src/org/eclipse/papyrus/resourceloading/umlprofile/UMLProfileStrategyExtension.java
+++ b/org.eclipse.papyrus.resourceloading.umlprofile/src/org/eclipse/papyrus/resourceloading/umlprofile/UMLProfileStrategyExtension.java
@@ -10,17 +10,23 @@
* Contributors:
* Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
*
- *****************************************************************************/
+ *****************************************************************************/
package org.eclipse.papyrus.resourceloading.umlprofile;
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.papyrus.core.resourceloading.ILoadingStrategyExtension;
import org.eclipse.papyrus.core.utils.DiResourceSet;
+import org.eclipse.papyrus.core.utils.caches.TypeCacheAdapter;
import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.ProfileApplication;
import org.eclipse.uml2.uml.UMLPackage;
@@ -29,33 +35,60 @@ import org.eclipse.uml2.uml.UMLPackage;
*/
public class UMLProfileStrategyExtension implements ILoadingStrategyExtension {
+ private static final String UML_FILE_EXTENSION = "uml";
+
/**
* {@inheritDoc}
+ * Load a profile resource if it used in the model
*/
public boolean loadResource(DiResourceSet diResourceSet, URI uri) {
- // TODO use type cache adapter
- boolean result = false;
- Resource modelResource = diResourceSet.getModelResource();
-// TypeCacheAdapter adapter = TypeCacheAdapter.getExistingtypeCacheAdapter(diResourceSet);
-// Collection<EObject> applications = adapter.getReachableObjectsOfType(null,UMLPackage.Literals.PROFILE_APPLICATION);
- if(modelResource.getContents().size() > 0) {
- EObject root = modelResource.getContents().get(0);
- if (root instanceof Package) {
- Package rootPackage = (Package)root;
- for (ProfileApplication profile : rootPackage.getProfileApplications()) {
- EObject proxy = (EObject)profile.eGet(UMLPackage.Literals.PROFILE_APPLICATION__APPLIED_PROFILE,false);
- if (proxy != null && proxy.eIsProxy())
- {
- InternalEObject internal = (InternalEObject)proxy ;
- if (uri.trimFragment().equals(internal.eProxyURI()))
- {
- return true ;
+ if(UML_FILE_EXTENSION.equals(diResourceSet.getModelFileExtension())) {
+ TypeCacheAdapter adapter = null;
+ for(Adapter a : diResourceSet.eAdapters()) {
+ if(a instanceof TypeCacheAdapter) {
+ adapter = (TypeCacheAdapter)a;
+ break;
+ }
+ }
+ if(adapter == null) {
+ // throw ...
+ }
+ Resource modelResource = diResourceSet.getModelResource();
+ if(modelResource != null && !modelResource.getContents().isEmpty()) {
+ if(adapter != null) {
+ Collection<EObject> applications = null;
+ if(!adapter.isAlreadyComputed(UMLPackage.Literals.PROFILE_APPLICATION)) {
+ applications = new LinkedList<EObject>();
+ // a profile application can only be stored in a package
+ for(int i = 0; i < diResourceSet.getResources().size(); i++) {
+ for(TreeIterator<EObject> j = EcoreUtil.getAllProperContents(diResourceSet.getResources().get(i), false); j.hasNext();) {
+ EObject e = j.next();
+ if(e instanceof Package) {
+ applications.addAll(((Package)e).getProfileApplications());
+ } else {
+ j.prune();
+ }
+ }
+ }
+ adapter.fillFirstEntryCache(UMLPackage.Literals.PROFILE_APPLICATION, applications);
+ } else {
+ applications = adapter.getReachableObjectsOfType(modelResource.getContents().get(0), UMLPackage.Literals.PROFILE_APPLICATION);
+ }
+ if(applications != null) {
+ for(EObject profileApp : applications) {
+ EObject proxy = (EObject)profileApp.eGet(UMLPackage.Literals.PROFILE_APPLICATION__APPLIED_PROFILE, false);
+ if(proxy != null && proxy.eIsProxy()) {
+ InternalEObject internal = (InternalEObject)proxy;
+ if(uri.trimFragment().equals(internal.eProxyURI().trimFragment())) {
+ return true;
+ }
+ }
}
}
}
}
}
- return result;
+ return false;
}
}

Back to the top