summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmusset2009-03-05 11:42:41 (EST)
committerjmusset2009-03-05 11:42:41 (EST)
commita285c0f4b430d5632449ba84ecc132b16e777f96 (patch)
tree561716da936873279289ab07a7399d08dc8b86a9
parentc9410078f5edeac48bd8490ef79c977ea6214fc7 (diff)
downloadorg.eclipse.acceleo-a285c0f4b430d5632449ba84ecc132b16e777f96.zip
org.eclipse.acceleo-a285c0f4b430d5632449ba84ecc132b16e777f96.tar.gz
org.eclipse.acceleo-a285c0f4b430d5632449ba84ecc132b16e777f96.tar.bz2
Project renaming from MTL to Acceleo
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/.classpath7
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/.cvsignore1
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/.project34
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/META-INF/MANIFEST.MF19
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/about.html57
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/build.properties16
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/CommonClass.java293
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Ecore2PythonPlugin.java66
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Factory.java293
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Init.java293
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Parser.java293
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/common.mtl24
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/names.mtl54
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/types.mtl21
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/commonClass.mtl58
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/factory.mtl74
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/init.mtl57
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/parser.mtl62
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.readme16
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.xml37
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.readme16
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.xml37
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.readme16
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.xml37
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.readme16
-rw-r--r--examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.xml37
27 files changed, 1940 insertions, 0 deletions
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/.classpath b/examples/org.eclipse.acceleo.module.example.ecore2python/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/.cvsignore b/examples/org.eclipse.acceleo.module.example.ecore2python/.cvsignore
new file mode 100644
index 0000000..ba077a4
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/.cvsignore
@@ -0,0 +1 @@
+bin
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/.project b/examples/org.eclipse.acceleo.module.example.ecore2python/.project
new file mode 100644
index 0000000..5010526
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.acceleo.module.example.ecore2python</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.acceleo.ide.ui.acceleoBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.acceleo.ide.ui.acceleoNature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.acceleo.module.example.ecore2python/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..d1c0bf9
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/META-INF/MANIFEST.MF b/examples/org.eclipse.acceleo.module.example.ecore2python/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..be7a88d
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Acceleo Ecore2python Module Example
+Bundle-SymbolicName: org.eclipse.acceleo.module.example.ecore2python
+Bundle-Version: 0.8.0.qualifier
+Bundle-Activator: org.eclipse.acceleo.module.ecore2python.Ecore2PythonPlugin
+Bundle-Vendor: Eclipse.org
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.emf.ecore,
+ org.eclipse.emf.ecore.xmi,
+ org.eclipse.ocl,
+ org.eclipse.ocl.ecore,
+ org.eclipse.acceleo.model,
+ org.eclipse.acceleo.engine
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Eclipse-LazyStart: true
+Bundle-ActivationPolicy: lazy
+Export-Package: org.eclipse.acceleo.module.ecore2python
+
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/about.html b/examples/org.eclipse.acceleo.module.example.ecore2python/about.html
new file mode 100644
index 0000000..7e1117e
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/about.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>About</title>
+</head><body lang="EN-US">
+<h2>About This Content</h2>
+
+<em>July 25, 2008</em></p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+
+ <h3>Third Party Content</h3>
+ <p>The Content includes items that have been sourced from third parties as set out below. If you
+ did not receive this Content directly from the Eclipse Foundation, the following is provided
+ for informational purposes only, and you should look to the Redistributor's license for
+ terms and conditions of use.</p>
+ <p><em>
+ <br><br>
+ <strong>OMG MOF 2.0 Specification (06-01-01)</strong> <br>
+ <ul>
+ <li><a href="http://www.omg.org/technology/documents/formal/mof.htm">MOF 2.0 main page</a></li>
+ <li><a href="http://www.omg.org/docs/formal/06-01-01.pdf">MOF 2.0 specification</a></li>
+ <li><a href="http://www.omg.org/">OMG site</a></li>
+ </ul>
+ <br>
+ <strong>OMG OCL 2.0 specification (06-05-01)</strong> <br>
+ <ul>
+ <li><a href="http://www.omg.org/technology/documents/formal/ocl.htm">OCL 2.0 main page</a></li>
+ <li><a href="http://www.omg.org/docs/formal/06-05-01.pdf">OCL 2.0 specification</a></li>
+ <li><a href="http://www.omg.org/">OMG site</a></li>
+ </ul>
+ <br>
+ <strong>OMG MTL 1.0 specification (08-01-16)</strong> <br>
+ <ul>
+ <li><a href="http://www.omg.org/spec/MOFM2T/1.0/">MTL 1.0 main page</a></li>
+ <li><a href="http://www.omg.org/spec/MOFM2T/1.0/PDF">MTL 1.0 specification</a></li>
+ <li><a href="http://www.omg.org/">OMG site</a></li>
+ </ul>
+ <br>
+ </em></p>
+ <p>A detailed list of fixes and clarifications with respect to those specifications may be found in the plug-in directly realizing them.</p>
+</body></html> \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/build.properties b/examples/org.eclipse.acceleo.module.example.ecore2python/build.properties
new file mode 100644
index 0000000..12dd08d
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/build.properties
@@ -0,0 +1,16 @@
+################################################################################
+# Copyright (c) 2008, 2009 Obeo.
+# 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:
+# Obeo - initial API and implementation
+################################################################################
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html
+
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/CommonClass.java b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/CommonClass.java
new file mode 100644
index 0000000..9c82576
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/CommonClass.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.acceleo.module.ecore2python;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+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.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.acceleo.model.mtl.Module;
+import org.eclipse.acceleo.model.mtl.MtlPackage;
+import org.eclipse.acceleo.engine.service.AcceleoService;
+import org.eclipse.ocl.ecore.EcoreEnvironment;
+import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
+
+/**
+ * Entry point of the 'CommonClass' generation module.
+ *
+ * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
+ */
+public class CommonClass {
+
+ /**
+ * The name of the module.
+ *
+ * @generated
+ */
+ public static final String MODULE_FILE_NAME = "commonClass";
+
+ /**
+ * The name of the templates that are to be generated.
+ *
+ * @generated
+ */
+ public static final String[] TEMPLATE_NAMES = { "packageToPythonCommonFile", };
+
+ /**
+ * The root element of the module.
+ */
+ private Module module;
+
+ /**
+ * The model.
+ */
+ private EObject model;
+
+ /**
+ * The output folder.
+ */
+ private File targetFolder;
+
+ /**
+ * The other arguments.
+ */
+ List<? extends Object> arguments;
+
+ /**
+ * Constructor.
+ *
+ * @param modelURI
+ * is the URI of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public CommonClass(URI modelURI, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = CommonClass.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ model = load(modelURI, resourceSet);
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param model
+ * is the root element of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public CommonClass(EObject model, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = model.eResource().getResourceSet();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = CommonClass.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ this.model = model;
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Creates the template URI.
+ *
+ * @param entry
+ * is the local path of the EMTL file
+ * @generated NOT
+ */
+ protected URI createTemplateURI(String entry) {
+ return URI.createFileURI(entry);
+ }
+
+ /**
+ * Gets the model.
+ *
+ * @return the model root element
+ */
+ public EObject getModel() {
+ return model;
+ }
+
+ /**
+ * Updates the registry used for looking up a package based namespace, in the resource set.
+ *
+ * @param resourceSet
+ * is the resource set
+ * @generated
+ */
+ private void registerPackages(ResourceSet resourceSet) {
+ resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.ocl.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE.getNsURI(), org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(MtlPackage.eINSTANCE.getNsURI(), MtlPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put("http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore", getOCLStdLibPackage());
+ }
+
+ /**
+ * Returns the package containing the OCL standard library.
+ *
+ * @return The package containing the OCL standard library.
+ * @generated
+ */
+ private EPackage getOCLStdLibPackage() {
+ EcoreEnvironmentFactory factory = new EcoreEnvironmentFactory();
+ EcoreEnvironment environment = (EcoreEnvironment)factory.createEnvironment();
+ return (EPackage)EcoreUtil.getRootContainer(environment.getOCLStandardLibrary().getBag());
+ }
+
+ /**
+ * Updates the registry used for looking up resources factory in the given resource set.
+ *
+ * @param resourceSet
+ * The resource set that is to be updated.
+ * @generated
+ */
+ private void registerResourceFactories(ResourceSet resourceSet) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("emtl", new org.eclipse.acceleo.model.mtl.resource.EMtlResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+ }
+
+ /**
+ * The main method.
+ *
+ * @param args
+ * are the arguments
+ * @generated
+ */
+ public static void main(String[] args) {
+ try {
+ if (args.length < 2) {
+ System.out.println("Arguments not valid : {model, folder}.");
+ } else {
+ URI modelURI = URI.createFileURI(args[0]);
+ File folder = new File(args[1]);
+ List<String> arguments = new ArrayList<String>();
+ for (int i = 2; i < args.length; i++) {
+ arguments.add(args[i]);
+ }
+ CommonClass generator = new CommonClass(modelURI, folder, arguments);
+ generator.doGenerate();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Launches the generation.
+ *
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public void doGenerate() throws IOException {
+ if (!targetFolder.exists()) {
+ targetFolder.mkdirs();
+ }
+ for (int i = 0; i < TEMPLATE_NAMES.length; i++) {
+ AcceleoService.doGenerate(module, TEMPLATE_NAMES[i], model, arguments, targetFolder, false);
+ }
+ }
+
+ /**
+ * Loads a model from an {@link org.eclipse.emf.common.util.URI URI} in a given {@link ResourceSet}.
+ * <p>
+ * This will return the first root of the loaded model, other roots can be accessed via the resource's
+ * content.
+ * </p>
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The model loaded from the URI.
+ * @throws IOException
+ * If the given file does not exist.
+ * @generated
+ */
+ private EObject load(URI modelURI, ResourceSet resourceSet) throws IOException {
+ EObject result = null;
+ final Resource modelResource = createResource(modelURI, resourceSet);
+ final Map<String, String> options = new HashMap<String, String>();
+ options.put(XMLResource.OPTION_ENCODING, System.getProperty("file.encoding"));
+ modelResource.load(options);
+ if (modelResource.getContents().size() > 0) {
+ result = modelResource.getContents().get(0);
+ }
+ return result;
+ }
+
+ /**
+ * This will create a {@link Resource} given the model extension it is intended for and a ResourceSet.
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The {@link Resource} given the model extension it is intended for.
+ * @generated
+ */
+ private Resource createResource(URI modelURI, ResourceSet resourceSet) {
+ String fileExtension = modelURI.fileExtension();
+ if (fileExtension == null || fileExtension.length() == 0) {
+ fileExtension = Resource.Factory.Registry.DEFAULT_EXTENSION;
+ }
+ final Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
+ final Object resourceFactory = registry.getExtensionToFactoryMap().get(fileExtension);
+ if (resourceFactory != null) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ resourceFactory);
+ } else {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ new XMIResourceFactoryImpl());
+ }
+ return resourceSet.createResource(modelURI);
+ }
+
+}
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Ecore2PythonPlugin.java b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Ecore2PythonPlugin.java
new file mode 100644
index 0000000..e15efa2
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Ecore2PythonPlugin.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.acceleo.module.ecore2python;
+
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle.
+ *
+ * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
+ */
+public class Ecore2PythonPlugin extends Plugin {
+
+ /**
+ * The plug-in ID.
+ */
+ public static final String PLUGIN_ID = "org.eclipse.acceleo.module.ecore2python";
+
+ /**
+ * The shared instance.
+ */
+ private static Ecore2PythonPlugin plugin;
+
+ /**
+ * The constructor.
+ */
+ public Ecore2PythonPlugin() {
+ }
+
+ /**{@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /**{@inheritDoc}
+ *
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the shared instance
+ */
+ public static Ecore2PythonPlugin getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Factory.java b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Factory.java
new file mode 100644
index 0000000..51bd48b
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Factory.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.acceleo.module.ecore2python;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+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.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.acceleo.model.mtl.Module;
+import org.eclipse.acceleo.model.mtl.MtlPackage;
+import org.eclipse.acceleo.engine.service.AcceleoService;
+import org.eclipse.ocl.ecore.EcoreEnvironment;
+import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
+
+/**
+ * Entry point of the 'Factory' generation module.
+ *
+ * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
+ */
+public class Factory {
+
+ /**
+ * The name of the module.
+ *
+ * @generated
+ */
+ public static final String MODULE_FILE_NAME = "factory";
+
+ /**
+ * The name of the templates that are to be generated.
+ *
+ * @generated
+ */
+ public static final String[] TEMPLATE_NAMES = { "packageToPythonFactoryFile", };
+
+ /**
+ * The root element of the module.
+ */
+ private Module module;
+
+ /**
+ * The model.
+ */
+ private EObject model;
+
+ /**
+ * The output folder.
+ */
+ private File targetFolder;
+
+ /**
+ * The other arguments.
+ */
+ List<? extends Object> arguments;
+
+ /**
+ * Constructor.
+ *
+ * @param modelURI
+ * is the URI of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public Factory(URI modelURI, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = Factory.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ model = load(modelURI, resourceSet);
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param model
+ * is the root element of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public Factory(EObject model, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = model.eResource().getResourceSet();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = Factory.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ this.model = model;
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Creates the template URI.
+ *
+ * @param entry
+ * is the local path of the EMTL file
+ * @generated NOT
+ */
+ protected URI createTemplateURI(String entry) {
+ return URI.createFileURI(entry);
+ }
+
+ /**
+ * Gets the model.
+ *
+ * @return the model root element
+ */
+ public EObject getModel() {
+ return model;
+ }
+
+ /**
+ * Updates the registry used for looking up a package based namespace, in the resource set.
+ *
+ * @param resourceSet
+ * is the resource set
+ * @generated
+ */
+ private void registerPackages(ResourceSet resourceSet) {
+ resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.ocl.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE.getNsURI(), org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(MtlPackage.eINSTANCE.getNsURI(), MtlPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put("http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore", getOCLStdLibPackage());
+ }
+
+ /**
+ * Returns the package containing the OCL standard library.
+ *
+ * @return The package containing the OCL standard library.
+ * @generated
+ */
+ private EPackage getOCLStdLibPackage() {
+ EcoreEnvironmentFactory factory = new EcoreEnvironmentFactory();
+ EcoreEnvironment environment = (EcoreEnvironment)factory.createEnvironment();
+ return (EPackage)EcoreUtil.getRootContainer(environment.getOCLStandardLibrary().getBag());
+ }
+
+ /**
+ * Updates the registry used for looking up resources factory in the given resource set.
+ *
+ * @param resourceSet
+ * The resource set that is to be updated.
+ * @generated
+ */
+ private void registerResourceFactories(ResourceSet resourceSet) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("emtl", new org.eclipse.acceleo.model.mtl.resource.EMtlResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+ }
+
+ /**
+ * The main method.
+ *
+ * @param args
+ * are the arguments
+ * @generated
+ */
+ public static void main(String[] args) {
+ try {
+ if (args.length < 2) {
+ System.out.println("Arguments not valid : {model, folder}.");
+ } else {
+ URI modelURI = URI.createFileURI(args[0]);
+ File folder = new File(args[1]);
+ List<String> arguments = new ArrayList<String>();
+ for (int i = 2; i < args.length; i++) {
+ arguments.add(args[i]);
+ }
+ Factory generator = new Factory(modelURI, folder, arguments);
+ generator.doGenerate();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Launches the generation.
+ *
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public void doGenerate() throws IOException {
+ if (!targetFolder.exists()) {
+ targetFolder.mkdirs();
+ }
+ for (int i = 0; i < TEMPLATE_NAMES.length; i++) {
+ AcceleoService.doGenerate(module, TEMPLATE_NAMES[i], model, arguments, targetFolder, false);
+ }
+ }
+
+ /**
+ * Loads a model from an {@link org.eclipse.emf.common.util.URI URI} in a given {@link ResourceSet}.
+ * <p>
+ * This will return the first root of the loaded model, other roots can be accessed via the resource's
+ * content.
+ * </p>
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The model loaded from the URI.
+ * @throws IOException
+ * If the given file does not exist.
+ * @generated
+ */
+ private EObject load(URI modelURI, ResourceSet resourceSet) throws IOException {
+ EObject result = null;
+ final Resource modelResource = createResource(modelURI, resourceSet);
+ final Map<String, String> options = new HashMap<String, String>();
+ options.put(XMLResource.OPTION_ENCODING, System.getProperty("file.encoding"));
+ modelResource.load(options);
+ if (modelResource.getContents().size() > 0) {
+ result = modelResource.getContents().get(0);
+ }
+ return result;
+ }
+
+ /**
+ * This will create a {@link Resource} given the model extension it is intended for and a ResourceSet.
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The {@link Resource} given the model extension it is intended for.
+ * @generated
+ */
+ private Resource createResource(URI modelURI, ResourceSet resourceSet) {
+ String fileExtension = modelURI.fileExtension();
+ if (fileExtension == null || fileExtension.length() == 0) {
+ fileExtension = Resource.Factory.Registry.DEFAULT_EXTENSION;
+ }
+ final Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
+ final Object resourceFactory = registry.getExtensionToFactoryMap().get(fileExtension);
+ if (resourceFactory != null) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ resourceFactory);
+ } else {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ new XMIResourceFactoryImpl());
+ }
+ return resourceSet.createResource(modelURI);
+ }
+
+}
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Init.java b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Init.java
new file mode 100644
index 0000000..f95149c
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Init.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.acceleo.module.ecore2python;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+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.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.acceleo.model.mtl.Module;
+import org.eclipse.acceleo.model.mtl.MtlPackage;
+import org.eclipse.acceleo.engine.service.AcceleoService;
+import org.eclipse.ocl.ecore.EcoreEnvironment;
+import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
+
+/**
+ * Entry point of the 'Init' generation module.
+ *
+ * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
+ */
+public class Init {
+
+ /**
+ * The name of the module.
+ *
+ * @generated
+ */
+ public static final String MODULE_FILE_NAME = "init";
+
+ /**
+ * The name of the templates that are to be generated.
+ *
+ * @generated
+ */
+ public static final String[] TEMPLATE_NAMES = { "toModuleInit", };
+
+ /**
+ * The root element of the module.
+ */
+ private Module module;
+
+ /**
+ * The model.
+ */
+ private EObject model;
+
+ /**
+ * The output folder.
+ */
+ private File targetFolder;
+
+ /**
+ * The other arguments.
+ */
+ List<? extends Object> arguments;
+
+ /**
+ * Constructor.
+ *
+ * @param modelURI
+ * is the URI of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public Init(URI modelURI, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = Init.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ model = load(modelURI, resourceSet);
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param model
+ * is the root element of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public Init(EObject model, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = model.eResource().getResourceSet();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = Init.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ this.model = model;
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Creates the template URI.
+ *
+ * @param entry
+ * is the local path of the EMTL file
+ * @generated NOT
+ */
+ protected URI createTemplateURI(String entry) {
+ return URI.createFileURI(entry);
+ }
+
+ /**
+ * Gets the model.
+ *
+ * @return the model root element
+ */
+ public EObject getModel() {
+ return model;
+ }
+
+ /**
+ * Updates the registry used for looking up a package based namespace, in the resource set.
+ *
+ * @param resourceSet
+ * is the resource set
+ * @generated
+ */
+ private void registerPackages(ResourceSet resourceSet) {
+ resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.ocl.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE.getNsURI(), org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(MtlPackage.eINSTANCE.getNsURI(), MtlPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put("http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore", getOCLStdLibPackage());
+ }
+
+ /**
+ * Returns the package containing the OCL standard library.
+ *
+ * @return The package containing the OCL standard library.
+ * @generated
+ */
+ private EPackage getOCLStdLibPackage() {
+ EcoreEnvironmentFactory factory = new EcoreEnvironmentFactory();
+ EcoreEnvironment environment = (EcoreEnvironment)factory.createEnvironment();
+ return (EPackage)EcoreUtil.getRootContainer(environment.getOCLStandardLibrary().getBag());
+ }
+
+ /**
+ * Updates the registry used for looking up resources factory in the given resource set.
+ *
+ * @param resourceSet
+ * The resource set that is to be updated.
+ * @generated
+ */
+ private void registerResourceFactories(ResourceSet resourceSet) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("emtl", new org.eclipse.acceleo.model.mtl.resource.EMtlResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+ }
+
+ /**
+ * The main method.
+ *
+ * @param args
+ * are the arguments
+ * @generated
+ */
+ public static void main(String[] args) {
+ try {
+ if (args.length < 2) {
+ System.out.println("Arguments not valid : {model, folder}.");
+ } else {
+ URI modelURI = URI.createFileURI(args[0]);
+ File folder = new File(args[1]);
+ List<String> arguments = new ArrayList<String>();
+ for (int i = 2; i < args.length; i++) {
+ arguments.add(args[i]);
+ }
+ Init generator = new Init(modelURI, folder, arguments);
+ generator.doGenerate();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Launches the generation.
+ *
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public void doGenerate() throws IOException {
+ if (!targetFolder.exists()) {
+ targetFolder.mkdirs();
+ }
+ for (int i = 0; i < TEMPLATE_NAMES.length; i++) {
+ AcceleoService.doGenerate(module, TEMPLATE_NAMES[i], model, arguments, targetFolder, false);
+ }
+ }
+
+ /**
+ * Loads a model from an {@link org.eclipse.emf.common.util.URI URI} in a given {@link ResourceSet}.
+ * <p>
+ * This will return the first root of the loaded model, other roots can be accessed via the resource's
+ * content.
+ * </p>
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The model loaded from the URI.
+ * @throws IOException
+ * If the given file does not exist.
+ * @generated
+ */
+ private EObject load(URI modelURI, ResourceSet resourceSet) throws IOException {
+ EObject result = null;
+ final Resource modelResource = createResource(modelURI, resourceSet);
+ final Map<String, String> options = new HashMap<String, String>();
+ options.put(XMLResource.OPTION_ENCODING, System.getProperty("file.encoding"));
+ modelResource.load(options);
+ if (modelResource.getContents().size() > 0) {
+ result = modelResource.getContents().get(0);
+ }
+ return result;
+ }
+
+ /**
+ * This will create a {@link Resource} given the model extension it is intended for and a ResourceSet.
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The {@link Resource} given the model extension it is intended for.
+ * @generated
+ */
+ private Resource createResource(URI modelURI, ResourceSet resourceSet) {
+ String fileExtension = modelURI.fileExtension();
+ if (fileExtension == null || fileExtension.length() == 0) {
+ fileExtension = Resource.Factory.Registry.DEFAULT_EXTENSION;
+ }
+ final Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
+ final Object resourceFactory = registry.getExtensionToFactoryMap().get(fileExtension);
+ if (resourceFactory != null) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ resourceFactory);
+ } else {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ new XMIResourceFactoryImpl());
+ }
+ return resourceSet.createResource(modelURI);
+ }
+
+}
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Parser.java b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Parser.java
new file mode 100644
index 0000000..857693e
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/Parser.java
@@ -0,0 +1,293 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2009 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.acceleo.module.ecore2python;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+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.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
+import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
+import org.eclipse.acceleo.model.mtl.Module;
+import org.eclipse.acceleo.model.mtl.MtlPackage;
+import org.eclipse.acceleo.engine.service.AcceleoService;
+import org.eclipse.ocl.ecore.EcoreEnvironment;
+import org.eclipse.ocl.ecore.EcoreEnvironmentFactory;
+
+/**
+ * Entry point of the 'Parser' generation module.
+ *
+ * @author <a href="mailto:jonathan.musset@obeo.fr">Jonathan Musset</a>
+ */
+public class Parser {
+
+ /**
+ * The name of the module.
+ *
+ * @generated
+ */
+ public static final String MODULE_FILE_NAME = "parser";
+
+ /**
+ * The name of the templates that are to be generated.
+ *
+ * @generated
+ */
+ public static final String[] TEMPLATE_NAMES = { "generateParser", };
+
+ /**
+ * The root element of the module.
+ */
+ private Module module;
+
+ /**
+ * The model.
+ */
+ private EObject model;
+
+ /**
+ * The output folder.
+ */
+ private File targetFolder;
+
+ /**
+ * The other arguments.
+ */
+ List<? extends Object> arguments;
+
+ /**
+ * Constructor.
+ *
+ * @param modelURI
+ * is the URI of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public Parser(URI modelURI, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = Parser.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ model = load(modelURI, resourceSet);
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param model
+ * is the root element of the model.
+ * @param targetFolder
+ * is the output folder
+ * @param arguments
+ * are the other arguments
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public Parser(EObject model, File targetFolder, List<? extends Object> arguments) throws IOException {
+ ResourceSet resourceSet = model.eResource().getResourceSet();
+ registerResourceFactories(resourceSet);
+ registerPackages(resourceSet);
+ URL templateURL = Parser.class.getResource(MODULE_FILE_NAME + ".emtl");
+ if (templateURL == null) {
+ throw new IOException("'" + MODULE_FILE_NAME + ".emtl' not found");
+ } else {
+ URI templateURI = createTemplateURI(templateURL.getPath());
+ module = (Module)load(templateURI, resourceSet);
+ this.model = model;
+ this.targetFolder = targetFolder;
+ this.arguments = arguments;
+ }
+ }
+
+ /**
+ * Creates the template URI.
+ *
+ * @param entry
+ * is the local path of the EMTL file
+ * @generated NOT
+ */
+ protected URI createTemplateURI(String entry) {
+ return URI.createFileURI(entry);
+ }
+
+ /**
+ * Gets the model.
+ *
+ * @return the model root element
+ */
+ public EObject getModel() {
+ return model;
+ }
+
+ /**
+ * Updates the registry used for looking up a package based namespace, in the resource set.
+ *
+ * @param resourceSet
+ * is the resource set
+ * @generated
+ */
+ private void registerPackages(ResourceSet resourceSet) {
+ resourceSet.getPackageRegistry().put(org.eclipse.emf.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.emf.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.ecore.EcorePackage.eINSTANCE.getNsURI(), org.eclipse.ocl.ecore.EcorePackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE.getNsURI(), org.eclipse.ocl.expressions.ExpressionsPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put(MtlPackage.eINSTANCE.getNsURI(), MtlPackage.eINSTANCE);
+ resourceSet.getPackageRegistry().put("http://www.eclipse.org/ocl/1.1.0/oclstdlib.ecore", getOCLStdLibPackage());
+ }
+
+ /**
+ * Returns the package containing the OCL standard library.
+ *
+ * @return The package containing the OCL standard library.
+ * @generated
+ */
+ private EPackage getOCLStdLibPackage() {
+ EcoreEnvironmentFactory factory = new EcoreEnvironmentFactory();
+ EcoreEnvironment environment = (EcoreEnvironment)factory.createEnvironment();
+ return (EPackage)EcoreUtil.getRootContainer(environment.getOCLStandardLibrary().getBag());
+ }
+
+ /**
+ * Updates the registry used for looking up resources factory in the given resource set.
+ *
+ * @param resourceSet
+ * The resource set that is to be updated.
+ * @generated
+ */
+ private void registerResourceFactories(ResourceSet resourceSet) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("emtl", new org.eclipse.acceleo.model.mtl.resource.EMtlResourceFactoryImpl());
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
+ }
+
+ /**
+ * The main method.
+ *
+ * @param args
+ * are the arguments
+ * @generated
+ */
+ public static void main(String[] args) {
+ try {
+ if (args.length < 2) {
+ System.out.println("Arguments not valid : {model, folder}.");
+ } else {
+ URI modelURI = URI.createFileURI(args[0]);
+ File folder = new File(args[1]);
+ List<String> arguments = new ArrayList<String>();
+ for (int i = 2; i < args.length; i++) {
+ arguments.add(args[i]);
+ }
+ Parser generator = new Parser(modelURI, folder, arguments);
+ generator.doGenerate();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Launches the generation.
+ *
+ * @throws IOException
+ * Thrown when the output cannot be saved.
+ * @generated
+ */
+ public void doGenerate() throws IOException {
+ if (!targetFolder.exists()) {
+ targetFolder.mkdirs();
+ }
+ for (int i = 0; i < TEMPLATE_NAMES.length; i++) {
+ AcceleoService.doGenerate(module, TEMPLATE_NAMES[i], model, arguments, targetFolder, false);
+ }
+ }
+
+ /**
+ * Loads a model from an {@link org.eclipse.emf.common.util.URI URI} in a given {@link ResourceSet}.
+ * <p>
+ * This will return the first root of the loaded model, other roots can be accessed via the resource's
+ * content.
+ * </p>
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The model loaded from the URI.
+ * @throws IOException
+ * If the given file does not exist.
+ * @generated
+ */
+ private EObject load(URI modelURI, ResourceSet resourceSet) throws IOException {
+ EObject result = null;
+ final Resource modelResource = createResource(modelURI, resourceSet);
+ final Map<String, String> options = new HashMap<String, String>();
+ options.put(XMLResource.OPTION_ENCODING, System.getProperty("file.encoding"));
+ modelResource.load(options);
+ if (modelResource.getContents().size() > 0) {
+ result = modelResource.getContents().get(0);
+ }
+ return result;
+ }
+
+ /**
+ * This will create a {@link Resource} given the model extension it is intended for and a ResourceSet.
+ *
+ * @param modelURI
+ * {@link org.eclipse.emf.common.util.URI URI} where the model is stored.
+ * @param resourceSet
+ * The {@link ResourceSet} to load the model in.
+ * @return The {@link Resource} given the model extension it is intended for.
+ * @generated
+ */
+ private Resource createResource(URI modelURI, ResourceSet resourceSet) {
+ String fileExtension = modelURI.fileExtension();
+ if (fileExtension == null || fileExtension.length() == 0) {
+ fileExtension = Resource.Factory.Registry.DEFAULT_EXTENSION;
+ }
+ final Resource.Factory.Registry registry = Resource.Factory.Registry.INSTANCE;
+ final Object resourceFactory = registry.getExtensionToFactoryMap().get(fileExtension);
+ if (resourceFactory != null) {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ resourceFactory);
+ } else {
+ resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(fileExtension,
+ new XMIResourceFactoryImpl());
+ }
+ return resourceSet.createResource(modelURI);
+ }
+
+}
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/common.mtl b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/common.mtl
new file mode 100644
index 0000000..3271934
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/common.mtl
@@ -0,0 +1,24 @@
+[comment]
+ Copyright © 2008 Obeo
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License 1.0
+
+ Any license can be applied to the files generated with this template
+ and Acceleo.
+[/comment]
+[module common('http://www.eclipse.org/emf/2002/Ecore')/]
+
+[comment]
+This will return all of the super-elements of a given modelElement, excluding itself.
+[/comment]
+[query public allSuperElements(element : EModelElement) : Sequence(T) = if (element.eContainer().oclIsUndefined()) then Sequence{} else allSuperElements(element.eContainer().oclAsType(EModelElement)) endif/]
+
+[comment]
+This will return the qualified name of the given element, python style.
+[/comment]
+[query public qualifiedName(element : ENamedElement) : String = allSuperElements(element).oclAsType(ENamedElement)->iterate(named : ENamedElement; qualified : String = element.name.javaToPythonName() | named.name.javaToPythonName().concat('.').concat(qualified))/]
+
+[comment]
+This will convert the given name to python style name (thus a class name 'EcoreClass' would become 'ecore_class').
+[/comment]
+[query public javaToPythonName(name : String) : String = name.toLowerFirst().replaceAll('(\p{Lu})', '_$1').toLower()/] \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/names.mtl b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/names.mtl
new file mode 100644
index 0000000..ab547b4
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/names.mtl
@@ -0,0 +1,54 @@
+[comment]
+ Copyright © 2008 Obeo
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License 1.0
+
+ Any license can be applied to the files generated with this template
+ and Acceleo.
+[/comment]
+[module names('http://www.eclipse.org/emf/2002/Ecore')/]
+[import common/]
+
+[template public moduleCommon(packaje : EPackage)]
+ [packaje.moduleFullName().trim()/]/__common__.py
+[/template]
+
+[template public moduleFactory(packaje : EPackage)]
+ [packaje.moduleFullName().trim()/]/__factory__.py
+[/template]
+
+[template public moduleInit(packaje : EPackage)]
+ [packaje.moduleFullName().trim()/]/__init__.py
+[/template]
+
+[template public parserName(packaje : EPackage)]
+ [packaje.moduleFullName().trim()/]/__parser__.py
+[/template]
+
+[template public baseClass(packaje : EPackage)]
+ [packaje.name.concat('Base').javaToPythonName().toUpperFirst()/]
+[/template]
+
+[template public moduleName(packaje : EPackage)]
+ [packaje.name.javaToPythonName()/]
+[/template]
+
+[template public relationBaseClass(packaje : EPackage)]
+ [packaje.name.concat('RelationBase').javaToPythonName().toUpperFirst()/]
+[/template]
+
+[template public resourceClass(packaje : EPackage)]
+ [packaje.name.concat('Resource').javaToPythonName().toUpperFirst()/]
+[/template]
+
+[template public factoryClassName(packaje : EPackage)]
+ [packaje.name.concat('Factory').javaToPythonName().toUpperFirst()/]
+[/template]
+
+[template public resourceFactory(packaje : EPackage)]
+ [packaje.name.concat('ResourceFactory').javaToPythonName().toUpperFirst()/]
+[/template]
+
+[template private moduleFullName(packaje : EPackage)]
+ [packaje.qualifiedName().substituteAll('.', '/')/]
+[/template] \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/types.mtl b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/types.mtl
new file mode 100644
index 0000000..2b1dcfd
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/common/types.mtl
@@ -0,0 +1,21 @@
+[comment]
+ Copyright © 2008 Obeo
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License 1.0
+
+ Any license can be applied to the files generated with this template
+ and Acceleo.
+[/comment]
+[module types('http://www.eclipse.org/emf/2002/Ecore')/]
+
+[template public typeInitialization(dataType : EDataType)]
+ [if (dataType.name = 'EString')]
+ "..."
+ [elseif (dataType.name = 'EInt')]
+ 0
+ [elseif (dataType.name = 'EBoolean')]
+ False
+ [else]
+ None
+ [/if]
+[/template] \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/commonClass.mtl b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/commonClass.mtl
new file mode 100644
index 0000000..d33e41a
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/commonClass.mtl
@@ -0,0 +1,58 @@
+[comment]
+ Copyright © 2008 Obeo
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License 1.0
+
+ Any license can be applied to the files generated with this template
+ and Acceleo.
+[/comment]
+[module commonClass('http://www.eclipse.org/emf/2002/Ecore')/]
+[import names/]
+
+[template public packageToPythonCommonFile(packaje : EPackage)]
+ [comment @main /]
+ [file (packaje.moduleCommon().trim(), false)]
+ class [packaje.baseClass().trim()/]:
+ """
+ [packaje.baseClass().trim()/] is the base class of all elements in the [packaje.moduleName().trim()/] module.
+ """
+ def __init__(self):
+ pass
+ self.__internal_resource__ = None
+
+ def __eResource__(self):
+ pass
+
+ class [packaje.relationBaseClass().trim()/](list):
+ """
+ Base class for relations
+ """
+ pass
+
+ class [packaje.resourceClass().trim()/]:
+ """
+ The [packaje.resourceClass().trim()/] is responsible for model serialization.
+ """
+ def __init__(self,uri):
+ # type here your specific code
+ self.__content__ = ['[]'/]
+ self.__uri__ = uri
+
+ def load(self,options=dict()):
+ pass
+
+ def save(self,options=dict()):
+ pass
+
+ class [packaje.resourceFactory().trim()/]:
+ """
+ The [packaje.resourceFactory().trim()/] is responsible for creating resource.
+ """
+ def __init__(self):
+ # type here your specific code
+ pass
+
+ def create(self,uri,options=dict()):
+ pass
+ [/file]
+[/template] \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/factory.mtl b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/factory.mtl
new file mode 100644
index 0000000..1896874
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/factory.mtl
@@ -0,0 +1,74 @@
+[comment]
+ Copyright © 2008 Obeo
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License 1.0
+
+ Any license can be applied to the files generated with this template
+ and Acceleo.
+[/comment]
+[module factory('http://www.eclipse.org/emf/2002/Ecore')/]
+[import names/]
+
+[template public packageToPythonFactoryFile(packaje : EPackage)]
+ [comment @main /]
+ [file (packaje.moduleFactory().trim(), false)]
+ [for (c : EClassifier | packaje.eClassifiers) ? (c.oclIsKindOf(EClass) and not c.oclAsType(EClass).abstract)]
+ from [packaje.moduleName().trim()/] import [c.name/]
+ [/for]
+ [packaje.packageToPythonFactoryClass()/]
+ [packaje.packageToPythonFactorytests()/]
+ [/file]
+[/template]
+
+[template public packageToPythonFactoryClass(packaje : EPackage)]
+ class [packaje.factoryClassName().trim()/]:
+ """ Factory to create elements from [packaje.name/]
+ """
+
+ def create(self,name):
+ """ generic method to create elements.
+ This method is able to create:
+ [for (c : EClassifier | packaje.eClassifiers) ? (c.oclIsKindOf(EClass) and not c.oclAsType(EClass).abstract)]
+ [c.name/]
+ [/for]
+
+ """
+ f = getattr(self,"create%s" % name)
+ return f()
+
+ [for (c : EClassifier | packaje.eClassifiers) ? (c.oclIsKindOf(EClass) and not c.oclAsType(EClass).abstract)]
+ def create[c.name/](self):
+ """
+ Create an instance of [c.name/].
+ """
+ instance = [c.name/]()
+ # type here special initialization code
+ return instance
+ [/for]
+[/template]
+
+[template public packageToPythonFactorytests(packaje : EPackage)]
+ import unittest
+
+ class Test_[packaje.moduleName().trim()/]_factory(unittest.TestCase):
+ [for (c : EClassifier | packaje.eClassifiers) ? (c.oclIsKindOf(EClass) and not c.oclAsType(EClass).abstract)]
+ def test[c.name/]Creation(self):
+ """
+ Test the direct instanciation of a [c.name/].
+ """
+ d = [c.name/]()
+ self.assertTrue(d!=None)
+
+ def test[c.name/]CreationFactory(self):
+ """
+ Test the instanciation of a [c.name/] through the factory.
+ """
+ factory = [packaje.factoryClassName().trim()/]()
+ d = factory.create("[c.name/]")
+ self.assertTrue(d != None)
+ self.assertTrue(isinstance(d, [c.name/]))
+ [/for]
+
+ if __name__ == '__main__':
+ unittest.main()
+[/template] \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/init.mtl b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/init.mtl
new file mode 100644
index 0000000..ba3473d
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/init.mtl
@@ -0,0 +1,57 @@
+[comment]
+ Copyright © 2008 Obeo
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License 1.0
+
+ Any license can be applied to the files generated with this template
+ and Acceleo.
+[/comment]
+[module init('http://www.eclipse.org/emf/2002/Ecore')/]
+[import names/]
+[import types/]
+
+[template public toModuleInit(packaje : EPackage)]
+ [comment @main /]
+ [file (packaje.moduleInit().trim(), false)]
+ Module [packaje.name/]
+
+ Sample usage :
+ [if (packaje.eClassifiers->size() > 0)]
+ >>> from [packaje.name.toLower()/] import [packaje.eClassifiers->first().name/]
+ [packaje.eClassifiers->first().oclAsType(EClass).sampleClassUsage()/]
+ [/if]
+
+ """
+
+ [for (sub : EPackage | packaje.eSubpackages) before('#import subpackages')]
+ import [sub.moduleName().trim().substituteAll('/', '.')/]
+ [/for]
+
+ from [packaje.moduleName().trim()/] import *
+
+ from __factory__ import [packaje.factoryClassName().trim()/]
+ """
+ Initialize the default instances factory
+ """
+ factory = [packaje.factoryClassName().trim()/]()
+ # here you may redefine the module singletons or do some special tricks
+
+ from __common__ import [packaje.resourceFactory().trim()/]
+ resourceFactory = [packaje.resourceFactory().trim()/]()
+ [/file]
+[/template]
+
+[template public sampleClassUsage(c : EClass)]
+ >>> [c.name.toLower()/] = [c.name/]()
+ [for (att : EAttribute | c.eAttributes)]
+ >>> [c.name.toLower()/].[att.name/] = [att.eAttributeType.typeInitialization().trim()/]
+ [/for]
+ [for (ref : EReference | c.eReferences) separator ('\n')]
+ [ref.sampleReferenceUsage()/]
+ [/for]
+[/template]
+
+[template public sampleReferenceUsage(reference : EReference)]
+ >>> [reference.eContainingClass.name.toLower()/].[reference.name/].append([reference.eType.name/]())
+ >>> [reference.eType.name.toLower()/] = [reference.eContainingClass.name.toLower()/].[reference.name/]['[0]'/]
+[/template] \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/parser.mtl b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/parser.mtl
new file mode 100644
index 0000000..83db5f7
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/src/org/eclipse/acceleo/module/ecore2python/parser.mtl
@@ -0,0 +1,62 @@
+[comment]
+ Copyright © 2008 Obeo
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License 1.0
+
+ Any license can be applied to the files generated with this template
+ and Acceleo.
+[/comment]
+[module parser('http://www.eclipse.org/emf/2002/Ecore')/]
+[import names/]
+
+[template public generateParser(packaje : EPackage)]
+ [comment @main /]
+ [file (packaje.parserName().trim(), false)]
+ from xml.sax import ContentHandler, make_parser
+
+ class MyHandler(ContentHandler):
+ def __init__(self):
+ "initialization"
+ pass
+
+ def startDocument(self):
+ "Called when the parser is on the first element"
+ pass
+
+ def startElement(self, name, attrs):
+ "Called when the parser encouters a tag opening"
+ pass
+
+ def endElement(self, name):
+ "Called when the parser encouters a tag closing"
+ pass
+
+ def characters(self, chrs, offset, length):
+ "Called when the parser encouters data in an element"
+ pass
+
+ def endDocument(self):
+ "Called when the parser encouters the very last element"
+ pass
+
+ doc = MyHandler()
+ saxparser = make_parser()
+ saxparser.setContentHandler(doc)
+
+ def load(filename):
+ datasource = open(filename, "r")
+ saxparser.parse(datasource)
+
+ def dump(root, filename):
+ pass
+
+ import unittest
+
+ class TestParser(unittest.TestCase):
+ def testLoading(self):
+ load("data/test.xmi")
+
+ if __name__ == '__main__':
+ unittest.main()
+ [/file]
+[/template] \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.readme b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.readme
new file mode 100644
index 0000000..62fe18b
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.readme
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Rename this file, put it in the target project and call it with "External Tools > Run As > Ant Build" -->
+<!-- You have to change the MODEL and the TARGET values -->
+
+<project basedir="." default="commonClassSample" name="org.eclipse.acceleo.module.example.ecore2pythonSample">
+ <import file="../org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.xml"/>
+ <property name="MODEL" value="${basedir}/model/file.xmi"/>
+ <property name="TARGET" value="${basedir}/src-gen"/>
+ <target name="commonClassSample" description="Generate files in '${TARGET}'">
+ <antcall target="commonClass" >
+ <param name="model" value="${MODEL}"/>
+ <param name="target" value="${TARGET}"/>
+ </antcall>
+ </target>
+</project> \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.xml b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.xml
new file mode 100644
index 0000000..83d7af8
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/commonClass.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project default="commonClass" name="org.eclipse.acceleo.module.example.ecore2python">
+ <property name="ECLIPSE_HOME" value="../../"/>
+ <property name="ECLIPSE_WORKSPACE" value="../"/>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath">
+ <pathelement location="../org.eclipse.acceleo.module.example.ecore2python/bin"/>
+
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.osgi_3.4.0.v20080529-1200.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.common_3.4.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.jobs_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20070717/runtime_registry_compatibility.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.registry_3.4.0.v20080516-0950.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.preferences_3.2.200.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.contenttype_3.3.0.v20080414.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.app_1.1.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.common_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore.xmi_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl_1.2.0.v200806091438.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/net.sourceforge.lpg.lpgjavaruntime_1.1.0.v200803061910.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl.ecore_1.2.0.v200805130238.jar"/>
+ </path>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <path refid="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath"/>
+ </path>
+
+ <target name="commonClass">
+
+ <java classname="org.eclipse.acceleo.module.ecore2python.CommonClass" classpathref="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <arg value="${model}"/>
+ <arg value="${target}"/>
+ </java>
+
+ </target>
+
+</project>
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.readme b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.readme
new file mode 100644
index 0000000..24e4cc2
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.readme
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Rename this file, put it in the target project and call it with "External Tools > Run As > Ant Build" -->
+<!-- You have to change the MODEL and the TARGET values -->
+
+<project basedir="." default="factorySample" name="org.eclipse.acceleo.module.example.ecore2pythonSample">
+ <import file="../org.eclipse.acceleo.module.example.ecore2python/tasks/factory.xml"/>
+ <property name="MODEL" value="${basedir}/model/file.xmi"/>
+ <property name="TARGET" value="${basedir}/src-gen"/>
+ <target name="factorySample" description="Generate files in '${TARGET}'">
+ <antcall target="factory" >
+ <param name="model" value="${MODEL}"/>
+ <param name="target" value="${TARGET}"/>
+ </antcall>
+ </target>
+</project> \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.xml b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.xml
new file mode 100644
index 0000000..f61f230
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/factory.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project default="factory" name="org.eclipse.acceleo.module.example.ecore2python">
+ <property name="ECLIPSE_HOME" value="../../"/>
+ <property name="ECLIPSE_WORKSPACE" value="../"/>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath">
+ <pathelement location="../org.eclipse.acceleo.module.example.ecore2python/bin"/>
+
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.osgi_3.4.0.v20080529-1200.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.common_3.4.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.jobs_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20070717/runtime_registry_compatibility.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.registry_3.4.0.v20080516-0950.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.preferences_3.2.200.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.contenttype_3.3.0.v20080414.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.app_1.1.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.common_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore.xmi_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl_1.2.0.v200806091438.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/net.sourceforge.lpg.lpgjavaruntime_1.1.0.v200803061910.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl.ecore_1.2.0.v200805130238.jar"/>
+ </path>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <path refid="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath"/>
+ </path>
+
+ <target name="factory">
+
+ <java classname="org.eclipse.acceleo.module.ecore2python.Factory" classpathref="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <arg value="${model}"/>
+ <arg value="${target}"/>
+ </java>
+
+ </target>
+
+</project>
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.readme b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.readme
new file mode 100644
index 0000000..f906976
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.readme
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Rename this file, put it in the target project and call it with "External Tools > Run As > Ant Build" -->
+<!-- You have to change the MODEL and the TARGET values -->
+
+<project basedir="." default="initSample" name="org.eclipse.acceleo.module.example.ecore2pythonSample">
+ <import file="../org.eclipse.acceleo.module.example.ecore2python/tasks/init.xml"/>
+ <property name="MODEL" value="${basedir}/model/file.xmi"/>
+ <property name="TARGET" value="${basedir}/src-gen"/>
+ <target name="initSample" description="Generate files in '${TARGET}'">
+ <antcall target="init" >
+ <param name="model" value="${MODEL}"/>
+ <param name="target" value="${TARGET}"/>
+ </antcall>
+ </target>
+</project> \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.xml b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.xml
new file mode 100644
index 0000000..006e9c6
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/init.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project default="init" name="org.eclipse.acceleo.module.example.ecore2python">
+ <property name="ECLIPSE_HOME" value="../../"/>
+ <property name="ECLIPSE_WORKSPACE" value="../"/>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath">
+ <pathelement location="../org.eclipse.acceleo.module.example.ecore2python/bin"/>
+
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.osgi_3.4.0.v20080529-1200.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.common_3.4.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.jobs_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20070717/runtime_registry_compatibility.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.registry_3.4.0.v20080516-0950.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.preferences_3.2.200.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.contenttype_3.3.0.v20080414.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.app_1.1.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.common_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore.xmi_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl_1.2.0.v200806091438.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/net.sourceforge.lpg.lpgjavaruntime_1.1.0.v200803061910.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl.ecore_1.2.0.v200805130238.jar"/>
+ </path>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <path refid="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath"/>
+ </path>
+
+ <target name="init">
+
+ <java classname="org.eclipse.acceleo.module.ecore2python.Init" classpathref="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <arg value="${model}"/>
+ <arg value="${target}"/>
+ </java>
+
+ </target>
+
+</project>
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.readme b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.readme
new file mode 100644
index 0000000..ba4660c
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.readme
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Rename this file, put it in the target project and call it with "External Tools > Run As > Ant Build" -->
+<!-- You have to change the MODEL and the TARGET values -->
+
+<project basedir="." default="parserSample" name="org.eclipse.acceleo.module.example.ecore2pythonSample">
+ <import file="../org.eclipse.acceleo.module.example.ecore2python/tasks/parser.xml"/>
+ <property name="MODEL" value="${basedir}/model/file.xmi"/>
+ <property name="TARGET" value="${basedir}/src-gen"/>
+ <target name="parserSample" description="Generate files in '${TARGET}'">
+ <antcall target="parser" >
+ <param name="model" value="${MODEL}"/>
+ <param name="target" value="${TARGET}"/>
+ </antcall>
+ </target>
+</project> \ No newline at end of file
diff --git a/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.xml b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.xml
new file mode 100644
index 0000000..9025f90
--- /dev/null
+++ b/examples/org.eclipse.acceleo.module.example.ecore2python/tasks/parser.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project default="parser" name="org.eclipse.acceleo.module.example.ecore2python">
+ <property name="ECLIPSE_HOME" value="../../"/>
+ <property name="ECLIPSE_WORKSPACE" value="../"/>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath">
+ <pathelement location="../org.eclipse.acceleo.module.example.ecore2python/bin"/>
+
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.osgi_3.4.0.v20080529-1200.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.common_3.4.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.jobs_3.4.0.v20080512.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.200.v20070717/runtime_registry_compatibility.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.registry_3.4.0.v20080516-0950.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.preferences_3.2.200.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.core.contenttype_3.3.0.v20080414.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.equinox.app_1.1.0.v20080421-2006.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.common_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.emf.ecore.xmi_2.4.0.v200806091234.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl_1.2.0.v200806091438.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/net.sourceforge.lpg.lpgjavaruntime_1.1.0.v200803061910.jar"/>
+ <pathelement location="${ECLIPSE_HOME}/plugins/org.eclipse.ocl.ecore_1.2.0.v200805130238.jar"/>
+ </path>
+ <path id="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <path refid="org.eclipse.acceleo.module.example.ecore2python.libraryclasspath"/>
+ </path>
+
+ <target name="parser">
+
+ <java classname="org.eclipse.acceleo.module.ecore2python.Parser" classpathref="org.eclipse.acceleo.module.example.ecore2python.classpath">
+ <arg value="${model}"/>
+ <arg value="${target}"/>
+ </java>
+
+ </target>
+
+</project>