aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2009-03-10 09:01:47 -0400
committeratikhomirov2009-03-10 09:01:47 -0400
commit4f8b39a05c26b944d68d5d578a3acc404845165d (patch)
tree67029b22bdcc92abf4fef5a00db1cdf956f0b12b
parentdcf04865f097e00e4e0fdff8bc10bc6092fd8f74 (diff)
downloadorg.eclipse.gmf-tooling-4f8b39a05c26b944d68d5d578a3acc404845165d.tar.gz
org.eclipse.gmf-tooling-4f8b39a05c26b944d68d5d578a3acc404845165d.tar.xz
org.eclipse.gmf-tooling-4f8b39a05c26b944d68d5d578a3acc404845165d.zip
[259583] employ real m2m transformations - utility methods to load EMF GenModel for further reference in the transformations
-rw-r--r--plugins/org.eclipse.gmf.codegen/plugin.xml31
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.nativestubs/gmf/GenModelAccess.qvto27
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/GenModelAccessHelpers.java106
3 files changed, 153 insertions, 11 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/plugin.xml b/plugins/org.eclipse.gmf.codegen/plugin.xml
index 6fa48ff16..c0e85a507 100644
--- a/plugins/org.eclipse.gmf.codegen/plugin.xml
+++ b/plugins/org.eclipse.gmf.codegen/plugin.xml
@@ -103,15 +103,24 @@
</content-type>
</extension>
- <extension point="org.eclipse.m2m.qvt.oml.javaBlackboxUnits">
- <library class="org.eclipse.gmf.internal.codegen.util.GenModelUtils">
- <metamodel nsURI="http://www.eclipse.org/emf/2002/GenModel"/>
- <metamodel nsURI="http://www.eclipse.org/emf/2002/Ecore"/>
- </library>
- <library class="org.eclipse.gmf.internal.codegen.util.EMFUtils">
- <metamodel nsURI="http://www.eclipse.org/emf/2002/Ecore"/>
- </library>
- <library class="org.eclipse.gmf.internal.codegen.util.CodeGenerationUtils">
- </library>
- </extension>
+ <extension point="org.eclipse.m2m.qvt.oml.javaBlackboxUnits">
+ <library class="org.eclipse.gmf.internal.codegen.util.GenModelUtils">
+ <metamodel nsURI="http://www.eclipse.org/emf/2002/GenModel"/>
+ <metamodel nsURI="http://www.eclipse.org/emf/2002/Ecore"/>
+ </library>
+ <library class="org.eclipse.gmf.internal.codegen.util.EMFUtils">
+ <metamodel nsURI="http://www.eclipse.org/emf/2002/Ecore"/>
+ </library>
+ <library class="org.eclipse.gmf.internal.codegen.util.CodeGenerationUtils"/>
+ <unit
+ description="GMF utulities to access EMF GenModels"
+ name="GenModelAccess"
+ namespace="gmf">
+ <library
+ class="org.eclipse.gmf.internal.codegen.util.GenModelAccessHelpers">
+ <metamodel nsURI="http://www.eclipse.org/emf/2002/Ecore"/>
+ <metamodel nsURI="http://www.eclipse.org/emf/2002/GenModel"/>
+ </library>
+ </unit>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.gmf.codegen/templates.nativestubs/gmf/GenModelAccess.qvto b/plugins/org.eclipse.gmf.codegen/templates.nativestubs/gmf/GenModelAccess.qvto
new file mode 100644
index 000000000..1d85f775b
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.nativestubs/gmf/GenModelAccess.qvto
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2009 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+modeltype ecore uses "http://www.eclipse.org/emf/2002/Ecore";
+modeltype genmodel uses "http://www.eclipse.org/emf/2002/GenModel";
+
+library GenModelAccess;
+
+-- similar to loadGenModel('http://www.eclipse.org/emf/2002/Ecore')
+helper loadEcoreGenModel() : GenModel { return null; }
+helper loadEcoreGenModel(EObject ctx) : GenModel { return null; }
+
+-- similar to loadGenModel('http://www.eclipse.org/gmf/runtime/1.0.2/notation')
+helper loadNotationGenModel() : GenModel { return null; }
+helper loadNotationGenModel(EObject ctx) : GenModel { return null; }
+
+-- nsURI - identifies ECore model you need GenModel for.
+helper loadGenModel(String nsURI) : GenModel { return null; }
+helper loadGenModel(String nsURI, EObject ctx) : GenModel { return null; }
diff --git a/plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/GenModelAccessHelpers.java b/plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/GenModelAccessHelpers.java
new file mode 100644
index 000000000..979800593
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen/templates.qvtlib/org/eclipse/gmf/internal/codegen/util/GenModelAccessHelpers.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2009 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Artem Tikhomirov (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.codegen.util;
+
+import java.io.IOException;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.m2m.qvt.oml.blackbox.java.Operation;
+import org.eclipse.m2m.qvt.oml.blackbox.java.Operation.Kind;
+
+/**
+ * Logic comes from org.eclipse.gmf.internal.bridge.genmodel.BasicGenModelAccess, with few handy methods
+ * to access well-known genmodels
+ * @author artem
+ */
+public class GenModelAccessHelpers {
+
+ private ResourceSet myDefaultSet;
+
+ @Operation(contextual = false, kind = Kind.HELPER)
+ public GenModel loadGenModel(String nsURI) {
+ return loadGenModel(nsURI, null);
+ }
+
+ @Operation(contextual = false, kind = Kind.HELPER)
+ public GenModel loadGenModel(String nsURI, EObject context) {
+ ResourceSet rs = getResourceSet(context);
+ URI genModelFromExtPoint = EcorePlugin.getEPackageNsURIToGenModelLocationMap().get(nsURI);
+ if (genModelFromExtPoint != null) {
+ return (GenModel) rs.getEObject(genModelFromExtPoint.appendFragment("/"), true); //$NON-NLS-1$
+ }
+ // try to guess .genmodel file location based on .ecore file location (if any)
+ EPackage ecoreModel = rs.getPackageRegistry().getEPackage(nsURI);
+ if (ecoreModel != null && ecoreModel.eResource() != null && ecoreModel.eResource().getURI() != null) {
+ URI ecoreModelURI = ecoreModel.eResource().getURI();
+ if (!ecoreModelURI.equals(nsURI)) { // owning resource points to some real stream
+ // alternative: ecoreModelURI.isFile() || ecoreModelURI.isPlatform() || ecoreModelURI.isArchive()
+ // e.g. smth we can try to access as a file
+ URI genModelURI = ecoreModelURI.trimFileExtension().appendFileExtension("genmodel");
+ if (!genModelURI.equals(ecoreModelURI)) {
+ Resource genModelRes = rs.getResource(genModelURI, false);
+ try {
+ genModelRes.load(rs.getLoadOptions());
+ if (genModelRes.getContents().size() > 0) {
+ return (GenModel) genModelRes.getContents().get(0);
+ }
+ } catch (IOException ex) {
+ // IGNORE
+ }
+ }
+ // else FALLTHROUGH
+ }
+ }
+ // final attempt - try nsURI as if it was file URI (e.g. platform:/plugin/...)
+ URI genModelUri = URI.createURI(nsURI);
+ return (GenModel) rs.getEObject(genModelUri.appendFragment("/"), true); //$NON-NLS-1$
+ }
+
+ @Operation(contextual = false, kind = Kind.HELPER)
+ public GenModel loadEcoreGenModel() {
+ return loadEcoreGenModel(null);
+ }
+
+ @Operation(contextual = false, kind = Kind.HELPER)
+ public GenModel loadEcoreGenModel(EObject context) {
+ URI genModelUri = URI.createURI("platform:/plugin/org.eclipse.emf.ecore/model/Ecore.genmodel#/"); //$NON-NLS-1$
+ return (GenModel) getResourceSet(context).getEObject(genModelUri, true);
+ }
+
+ @Operation(contextual = false, kind = Kind.HELPER)
+ public GenModel loadNotationGenModel() {
+ return loadNotationGenModel(null);
+ }
+
+ @Operation(contextual = false, kind = Kind.HELPER)
+ public GenModel loadNotationGenModel(EObject context) {
+ URI genModelUri = URI.createURI("platform:/plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#/"); //$NON-NLS-1$
+ return (GenModel) getResourceSet(context).getEObject(genModelUri, true);
+ }
+
+ private ResourceSet getResourceSet(EObject context) {
+ if (context == null || context.eResource() == null || context.eResource().getResourceSet() == null) {
+ if (myDefaultSet == null) {
+ myDefaultSet = new ResourceSetImpl();
+ }
+ return myDefaultSet;
+ }
+ return context.eResource().getResourceSet();
+ }
+}