Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavidms2006-11-10 18:04:27 -0500
committerdavidms2006-11-10 18:04:27 -0500
commitab4c227208e9a610a980e1f9b22b9d765e3983d8 (patch)
tree93f58603385acb37e7b7a5d9e14d99b9f6bab590 /examples/org.eclipse.emf.examples.generator.validator
parent8aa2a17530c03e0d2ed7a9c11924cc79394ec2ab (diff)
downloadorg.eclipse.emf-ab4c227208e9a610a980e1f9b22b9d765e3983d8.tar.gz
org.eclipse.emf-ab4c227208e9a610a980e1f9b22b9d765e3983d8.tar.xz
org.eclipse.emf-ab4c227208e9a610a980e1f9b22b9d765e3983d8.zip
[164193] A generator extension example plug-in
Diffstat (limited to 'examples/org.eclipse.emf.examples.generator.validator')
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/.classpath7
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/.cvsignore6
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/.jetproperties4
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/.project34
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/about.html29
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/build.properties15
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/plugin.properties24
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/plugin.xml14
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/readme.txt16
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenClassValidatorGeneratorAdapter.java92
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenModelValidatorGeneratorAdapter.java90
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorAdapterFactory.java44
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorPlugin.java82
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorUtil.java137
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/ModelDescription.java115
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/Validator.java63
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/templates/Header.javajetinc6
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/templates/model/ModelDescription.txtjet41
-rw-r--r--examples/org.eclipse.emf.examples.generator.validator/templates/model/Validator.javajet21
20 files changed, 847 insertions, 0 deletions
diff --git a/examples/org.eclipse.emf.examples.generator.validator/.classpath b/examples/org.eclipse.emf.examples.generator.validator/.classpath
new file mode 100644
index 000000000..304e86186
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <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="output" path="bin"/>
+</classpath>
diff --git a/examples/org.eclipse.emf.examples.generator.validator/.cvsignore b/examples/org.eclipse.emf.examples.generator.validator/.cvsignore
new file mode 100644
index 000000000..4c49b5905
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/.cvsignore
@@ -0,0 +1,6 @@
+bin
+bin.tasks
+build.xml
+ant_tasks
+temp.folder
+*.jar
diff --git a/examples/org.eclipse.emf.examples.generator.validator/.jetproperties b/examples/org.eclipse.emf.examples.generator.validator/.jetproperties
new file mode 100644
index 000000000..5585019b3
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/.jetproperties
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jet-settings>
+ <template-container>templates</template-container> <source-container>src</source-container>
+</jet-settings>
diff --git a/examples/org.eclipse.emf.examples.generator.validator/.project b/examples/org.eclipse.emf.examples.generator.validator/.project
new file mode 100644
index 000000000..de837a743
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.examples.generator.validator</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.emf.codegen.JETBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <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>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.emf.codegen.jet.IJETNature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/org.eclipse.emf.examples.generator.validator/.settings/org.eclipse.jdt.core.prefs b/examples/org.eclipse.emf.examples.generator.validator/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..763b59025
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Fri Nov 10 17:25:19 EST 2006
+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.emf.examples.generator.validator/about.html b/examples/org.eclipse.emf.examples.generator.validator/about.html
new file mode 100644
index 000000000..6fa3d8fec
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/about.html
@@ -0,0 +1,29 @@
+<!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>
+
+<p>November 10, 2006</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>
+
+</body>
+</html>
diff --git a/examples/org.eclipse.emf.examples.generator.validator/build.properties b/examples/org.eclipse.emf.examples.generator.validator/build.properties
new file mode 100644
index 000000000..245e118bb
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/build.properties
@@ -0,0 +1,15 @@
+bin.includes = about.html,\
+ plugin.properties,\
+ plugin.xml,\
+ META-INF/,\
+ templates/,\
+ generator.validator.jar,\
+ .project,\
+ build.properties,\
+ src/,\
+ .classpath,\
+ .jetproperties
+jars.compile.order = generator.validator.jar
+exclude.generator.validator.jar = **/doc-files/**
+source.generator.validator.jar = src/
+output.generator.validator.jar = bin/
diff --git a/examples/org.eclipse.emf.examples.generator.validator/plugin.properties b/examples/org.eclipse.emf.examples.generator.validator/plugin.properties
new file mode 100644
index 000000000..8646025ba
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/plugin.properties
@@ -0,0 +1,24 @@
+# /**
+# * <copyright>
+# *
+# * Copyright (c) 2006 IBM Corporation and others.
+# * 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:
+# * IBM - Initial API and implementation
+# *
+# * </copyright>
+# *
+# * $Id: plugin.properties,v 1.1 2006/11/10 23:04:27 davidms Exp $
+# */
+
+# NLS_MESSAGEFORMAT_VAR
+
+pluginName = Validator Generator Extension
+providerName = Eclipse.org
+
+GeneratingModelDescription.message = Generating model description
+GeneratingValidator.message = Generating validator {0}
diff --git a/examples/org.eclipse.emf.examples.generator.validator/plugin.xml b/examples/org.eclipse.emf.examples.generator.validator/plugin.xml
new file mode 100644
index 000000000..c579ff93f
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/plugin.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+ <extension point="org.eclipse.emf.codegen.ecore.generatorAdapters">
+ <!-- Adapter Factory -->
+ <adapterFactory class="org.eclipse.emf.examples.generator.validator.ValidatorGeneratorAdapterFactory"/>
+ <!-- Single Adapter -->
+ <!--
+ <adapter modelClass="GenModel" class="org.eclipse.emf.examples.generator.validator.GenModelValidatorGeneratorAdapter"/>
+ <adapter modelClass="GenClass" class="org.eclipse.emf.examples.generator.validator.GenClassValidatorGeneratorAdapter"/>
+ -->
+ </extension>
+
+</plugin>
diff --git a/examples/org.eclipse.emf.examples.generator.validator/readme.txt b/examples/org.eclipse.emf.examples.generator.validator/readme.txt
new file mode 100644
index 000000000..cc3b6c22d
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/readme.txt
@@ -0,0 +1,16 @@
+This plug-in demonstrates the org.eclipse.emf.codegen.ecore.generatorAdapters
+extension point, showing how it can be used to extend EMF's code generator.
+
+It adds two types of artifacts to those usually generated in a model plug-in:
+
+1. a validator interface for each modeled class
+2. a text description of the model.
+
+These artifacts are added by the GenClassValidatorGeneratorAdapter.java
+GenModelValidatorGeneratorAdapter.java generator adapters, and are generated
+using the Validator.javajet and ModelDescription.txtjet templates.
+
+The generator adapters are registered, by default, via an adapter factory
+that creates them. They can also be registered directly, with no functional
+change in behaviour. To do so, simply comment out the adapterFactory element
+and uncomment the adapter elements in plugin.xml.
diff --git a/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenClassValidatorGeneratorAdapter.java b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenClassValidatorGeneratorAdapter.java
new file mode 100644
index 000000000..c9e56bb47
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenClassValidatorGeneratorAdapter.java
@@ -0,0 +1,92 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: GenClassValidatorGeneratorAdapter.java,v 1.1 2006/11/10 23:04:27 davidms Exp $
+ */
+package org.eclipse.emf.examples.generator.validator;
+
+import java.util.List;
+
+import org.eclipse.emf.codegen.ecore.generator.GeneratorAdapterFactory;
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
+import org.eclipse.emf.codegen.jet.JETEmitter;
+import org.eclipse.emf.codegen.jet.JETException;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.Monitor;
+
+public class GenClassValidatorGeneratorAdapter extends GenBaseGeneratorAdapter
+{
+ protected static final int VALIDATOR_ID = 0;
+
+ protected static final JETEmitterDescriptor[] JET_EMITTER_DESCRIPTORS =
+ {
+ new JETEmitterDescriptor("model/Validator.javajet", "org.eclipse.emf.examples.generator.validator.templates.model.Validator")
+ };
+
+ protected JETEmitterDescriptor[] getJETEmitterDescriptors()
+ {
+ return JET_EMITTER_DESCRIPTORS;
+ }
+
+ public GenClassValidatorGeneratorAdapter()
+ {
+ }
+
+ public GenClassValidatorGeneratorAdapter(GeneratorAdapterFactory generatorAdapterFactory)
+ {
+ super(generatorAdapterFactory);
+ }
+
+ public boolean canGenerate(Object object, Object projectType)
+ {
+ return MODEL_PROJECT_TYPE.equals(projectType) ? super.canGenerate(object, projectType) : false;
+ }
+
+ protected Diagnostic generateModel(Object object, Monitor monitor)
+ {
+ GenClass genClass = (GenClass)object;
+
+ monitor.beginTask("", 2);
+ message = ValidatorGeneratorPlugin.INSTANCE.getString("GeneratingValidator.message", new Object[] { ValidatorGeneratorUtil.getValidatorInterfaceName(genClass) });
+ monitor.subTask(message);
+
+ GenModel genModel = genClass.getGenModel();
+ ensureProjectExists
+ (genModel.getModelDirectory(), genClass, MODEL_PROJECT_TYPE, genModel.isUpdateClasspath(), createMonitor(monitor, 1));
+
+ generateJava
+ (genModel.getModelDirectory(),
+ ValidatorGeneratorUtil.getValidationPackageName(genClass.getGenPackage()),
+ ValidatorGeneratorUtil.getValidatorInterfaceName(genClass),
+ getJETEmitter(getJETEmitterDescriptors(), VALIDATOR_ID),
+ null,
+ createMonitor(monitor, 1));
+
+ return Diagnostic.OK_INSTANCE;
+ }
+
+ protected void addBaseTemplatePathEntries(List templatePath)
+ {
+ templatePath.add(ValidatorGeneratorUtil.TEMPLATE_LOCATION);
+ super.addBaseTemplatePathEntries(templatePath);
+ }
+
+ protected void addClasspathEntries(JETEmitter jetEmitter) throws JETException
+ {
+ super.addClasspathEntries(jetEmitter);
+ jetEmitter.addVariable(ValidatorGeneratorUtil.CLASSPATH_VARIABLE_NAME, ValidatorGeneratorPlugin.ID);
+ }
+}
diff --git a/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenModelValidatorGeneratorAdapter.java b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenModelValidatorGeneratorAdapter.java
new file mode 100644
index 000000000..81facc8d3
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/GenModelValidatorGeneratorAdapter.java
@@ -0,0 +1,90 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: GenModelValidatorGeneratorAdapter.java,v 1.1 2006/11/10 23:04:27 davidms Exp $
+ */
+package org.eclipse.emf.examples.generator.validator;
+
+import java.util.List;
+
+import org.eclipse.emf.codegen.ecore.generator.GeneratorAdapterFactory;
+import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
+import org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter;
+import org.eclipse.emf.codegen.jet.JETEmitter;
+import org.eclipse.emf.codegen.jet.JETException;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.Monitor;
+
+public class GenModelValidatorGeneratorAdapter extends GenBaseGeneratorAdapter
+{
+ protected static final int MODEL_DESCRIPTION_ID = 0;
+
+ protected static final JETEmitterDescriptor[] JET_EMITTER_DESCRIPTORS =
+ {
+ new JETEmitterDescriptor("model/ModelDescription.txtjet", "org.eclipse.emf.examples.generator.validator.templates.model.ModelDescription")
+ };
+
+ protected JETEmitterDescriptor[] getJETEmitterDescriptors()
+ {
+ return JET_EMITTER_DESCRIPTORS;
+ }
+
+ public GenModelValidatorGeneratorAdapter()
+ {
+ }
+
+ public GenModelValidatorGeneratorAdapter(GeneratorAdapterFactory generatorAdapterFactory)
+ {
+ super(generatorAdapterFactory);
+ }
+
+ public boolean canGenerate(Object object, Object projectType)
+ {
+ return MODEL_PROJECT_TYPE.equals(projectType) ? super.canGenerate(object, projectType) : false;
+ }
+
+ protected Diagnostic generateModel(Object object, Monitor monitor)
+ {
+ GenModel genModel = (GenModel)object;
+
+ monitor.beginTask("", 2);
+ message = ValidatorGeneratorPlugin.INSTANCE.getString("GeneratingModelDescription.message");
+ monitor.subTask(message);
+
+ ensureProjectExists
+ (genModel.getModelDirectory(), genModel, MODEL_PROJECT_TYPE, genModel.isUpdateClasspath(), createMonitor(monitor, 1));
+
+ generateText
+ (genModel.getModelProjectDirectory() + "/text/description.txt",
+ getJETEmitter(getJETEmitterDescriptors(), MODEL_DESCRIPTION_ID),
+ null,
+ true,
+ null,
+ createMonitor(monitor, 1));
+
+ return Diagnostic.OK_INSTANCE;
+ }
+
+ protected void addBaseTemplatePathEntries(List templatePath)
+ {
+ templatePath.add(ValidatorGeneratorUtil.TEMPLATE_LOCATION);
+ super.addBaseTemplatePathEntries(templatePath);
+ }
+
+ protected void addClasspathEntries(JETEmitter jetEmitter) throws JETException
+ {
+ super.addClasspathEntries(jetEmitter);
+ jetEmitter.addVariable(ValidatorGeneratorUtil.CLASSPATH_VARIABLE_NAME, ValidatorGeneratorPlugin.ID);
+ }
+} \ No newline at end of file
diff --git a/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorAdapterFactory.java b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorAdapterFactory.java
new file mode 100644
index 000000000..84eb29af1
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorAdapterFactory.java
@@ -0,0 +1,44 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ValidatorGeneratorAdapterFactory.java,v 1.1 2006/11/10 23:04:27 davidms Exp $
+ */
+package org.eclipse.emf.examples.generator.validator;
+
+import org.eclipse.emf.codegen.ecore.genmodel.generator.GenModelGeneratorAdapterFactory;
+import org.eclipse.emf.common.notify.Adapter;
+
+public class ValidatorGeneratorAdapterFactory extends GenModelGeneratorAdapterFactory
+{
+ public Adapter createGenPackageAdapter() { return null; }
+ public Adapter createGenEnumAdapter() { return null; }
+
+ public Adapter createGenModelAdapter()
+ {
+ if (genModelGeneratorAdapter == null)
+ {
+ genModelGeneratorAdapter = new GenModelValidatorGeneratorAdapter(this);
+ }
+ return genModelGeneratorAdapter;
+ }
+
+ public Adapter createGenClassAdapter()
+ {
+ if (genClassGeneratorAdapter == null)
+ {
+ genClassGeneratorAdapter = new GenClassValidatorGeneratorAdapter(this);
+ }
+ return genClassGeneratorAdapter;
+ }
+}
diff --git a/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorPlugin.java b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorPlugin.java
new file mode 100644
index 000000000..0facca977
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorPlugin.java
@@ -0,0 +1,82 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ValidatorGeneratorPlugin.java,v 1.1 2006/11/10 23:04:27 davidms Exp $
+ */
+package org.eclipse.emf.examples.generator.validator;
+
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.common.util.ResourceLocator;
+
+
+/**
+ * The <b>Plugin</b> for the Validator Generator Extension plug-in.
+ */
+public final class ValidatorGeneratorPlugin extends EMFPlugin
+{
+ /**
+ * The singleton instance of the plugin.
+ */
+ public static final ValidatorGeneratorPlugin INSTANCE = new ValidatorGeneratorPlugin();
+
+ /**
+ * The one instance of this class.
+ */
+ private static Implementation plugin;
+
+ public static final String ID = "org.eclipse.emf.examples.generator.validator";
+
+ /**
+ * Creates the singleton instance.
+ */
+ private ValidatorGeneratorPlugin()
+ {
+ super(new ResourceLocator [] { });
+ }
+
+ /*
+ * Javadoc copied from base class.
+ */
+ public ResourceLocator getPluginResourceLocator()
+ {
+ return plugin;
+ }
+
+ /**
+ * Returns the singleton instance of the Eclipse plugin.
+ * @return the singleton instance.
+ */
+ public static Implementation getPlugin()
+ {
+ return plugin;
+ }
+
+ /**
+ * The actual implementation of the Eclipse <b>Plugin</b>.
+ */
+ public static class Implementation extends EclipsePlugin
+ {
+ /**
+ * Creates an instance.
+ */
+ public Implementation()
+ {
+ super();
+
+ // Remember the static instance.
+ //
+ plugin = this;
+ }
+ }
+}
diff --git a/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorUtil.java b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorUtil.java
new file mode 100644
index 000000000..c3e417789
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/ValidatorGeneratorUtil.java
@@ -0,0 +1,137 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * 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:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: ValidatorGeneratorUtil.java,v 1.1 2006/11/10 23:04:27 davidms Exp $
+ */
+package org.eclipse.emf.examples.generator.validator;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.codegen.ecore.genmodel.GenOperation;
+import org.eclipse.emf.codegen.ecore.genmodel.GenPackage;
+import org.eclipse.emf.codegen.ecore.genmodel.GenTypedElement;
+import org.eclipse.emf.codegen.util.ImportManager;
+import org.eclipse.emf.ecore.ETypedElement;
+
+public class ValidatorGeneratorUtil
+{
+ private ValidatorGeneratorUtil()
+ {
+ }
+
+ public final static String TEMPLATE_LOCATION = ValidatorGeneratorPlugin.INSTANCE.getBaseURL().toString() + "templates";
+
+ public final static String CLASSPATH_VARIABLE_NAME = "EMF_EXAMPLES_GENERATOR_VALIDATOR";
+
+ public static String getValidationPackageName(GenPackage genPackage)
+ {
+ String basePackage = genPackage.getInterfacePackageName();
+ return basePackage.length() > 0 ? basePackage + ".validation" : "validation";
+ }
+
+ public static String getValidatorInterfaceName(GenClass genClass)
+ {
+ return genClass.getInterfaceName() + "Validator";
+ }
+
+ public static String getQualifiedValidatorInterfaceName(GenClass genClass)
+ {
+ return getValidationPackageName(genClass.getGenPackage()) + "." + getValidatorInterfaceName(genClass);
+ }
+
+ public static String getImportedValidatorInterfaceName(GenClass genClass)
+ {
+ return genClass.getGenModel().getImportedName(getQualifiedValidatorInterfaceName(genClass));
+ }
+
+ protected static String getImportedName(String qualifiedName, ImportManager importManager)
+ {
+ int index = qualifiedName.indexOf("$");
+ importManager.addImport(index == -1 ? qualifiedName : qualifiedName.substring(0, index));
+ return importManager.getImportedName(qualifiedName);
+ }
+
+ public static String getSuperTypesExpression(GenClass genClass)
+ {
+ List extendsList = genClass.getBaseGenClasses();
+ if (!extendsList.isEmpty())
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(" -> ");
+ for (Iterator i = extendsList.iterator(); i.hasNext(); )
+ {
+ result.append(((GenClass)i.next()).getName());
+ if (i.hasNext())
+ {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+ return "";
+ }
+
+ public static String getTypeExpression(GenTypedElement genTypedElement)
+ {
+ StringBuffer result = new StringBuffer();
+ result.append(genTypedElement.getTypeGenClassifier().getName());
+
+ ETypedElement eTypedElement = (ETypedElement)genTypedElement.getEcoreModelElement();
+ int lowerBound = eTypedElement.getLowerBound();
+ int upperBound = eTypedElement.getUpperBound();
+
+ if (lowerBound != 0 || upperBound != 1)
+ {
+ result.append("<<");
+ result.append(lowerBound);
+ result.append("..");
+
+ if (upperBound == ETypedElement.UNSPECIFIED_MULTIPLICITY)
+ {
+ result.append('?');
+ }
+ else if (upperBound == ETypedElement.UNBOUNDED_MULTIPLICITY)
+ {
+ result.append('*');
+ }
+ else
+ {
+ result.append(upperBound);
+ }
+ result.append(">>");
+ }
+ return result.toString();
+ }
+
+ public static String getParameterExpression(GenOperation genOperation)
+ {
+ StringBuffer result = new StringBuffer();
+ result.append('(');
+
+ for (Iterator i = genOperation.getGenParameters().iterator(); i.hasNext(); )
+ {
+ result.append(getTypeExpression(genOperation));
+ if (i.hasNext())
+ {
+ result.append(", ");
+ }
+ }
+ result.append(')');
+ return result.toString();
+ }
+
+
+}
diff --git a/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/ModelDescription.java b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/ModelDescription.java
new file mode 100644
index 000000000..b9aee359d
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/ModelDescription.java
@@ -0,0 +1,115 @@
+package org.eclipse.emf.examples.generator.validator.templates.model;
+
+import java.util.*;
+import org.eclipse.emf.codegen.ecore.genmodel.*;
+import org.eclipse.emf.examples.generator.validator.ValidatorGeneratorUtil;
+
+public class ModelDescription
+{
+ protected static String nl;
+ public static synchronized ModelDescription create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ ModelDescription result = new ModelDescription();
+ nl = null;
+ return result;
+ }
+
+ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+ protected final String TEXT_1 = "Model ";
+ protected final String TEXT_2 = NL + NL + "This model description is not a real EMF artifact. It was generated by the" + NL + "org.eclipse.emf.examples.generator.validator plug-in to illustrate how EMF's" + NL + "code generator can be extended." + NL;
+ protected final String TEXT_3 = NL + "Contains packages:";
+ protected final String TEXT_4 = NL + " ";
+ protected final String TEXT_5 = " <";
+ protected final String TEXT_6 = ">";
+ protected final String TEXT_7 = NL;
+ protected final String TEXT_8 = NL + "Package ";
+ protected final String TEXT_9 = " <";
+ protected final String TEXT_10 = ">" + NL;
+ protected final String TEXT_11 = NL + " Class ";
+ protected final String TEXT_12 = NL + " ";
+ protected final String TEXT_13 = " ";
+ protected final String TEXT_14 = "/";
+ protected final String TEXT_15 = " : ";
+ protected final String TEXT_16 = NL + " Operation ";
+ protected final String TEXT_17 = " : ";
+ protected final String TEXT_18 = NL;
+ protected final String TEXT_19 = NL + " Enum ";
+ protected final String TEXT_20 = NL + " Literal ";
+ protected final String TEXT_21 = " = ";
+ protected final String TEXT_22 = NL;
+ protected final String TEXT_23 = NL + " DataType ";
+ protected final String TEXT_24 = " <";
+ protected final String TEXT_25 = ">" + NL;
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+ GenModel genModel = (GenModel)argument;
+ stringBuffer.append(TEXT_1);
+ stringBuffer.append(genModel.getModelName());
+ stringBuffer.append(TEXT_2);
+ if (genModel.getGenPackages().size() > 1) {
+ stringBuffer.append(TEXT_3);
+ for (Iterator iter = genModel.getGenPackages().iterator(); iter.hasNext(); ) { GenPackage genPackage = (GenPackage)iter.next();
+ stringBuffer.append(TEXT_4);
+ stringBuffer.append(genPackage.getPackageName());
+ stringBuffer.append(TEXT_5);
+ stringBuffer.append(genPackage.getNSURI());
+ stringBuffer.append(TEXT_6);
+ }
+ stringBuffer.append(TEXT_7);
+ }
+ for (Iterator pIter = genModel.getGenPackages().iterator(); pIter.hasNext(); ) { GenPackage genPackage = (GenPackage)pIter.next();
+ stringBuffer.append(TEXT_8);
+ stringBuffer.append(genPackage.getPackageName());
+ stringBuffer.append(TEXT_9);
+ stringBuffer.append(genPackage.getNSURI());
+ stringBuffer.append(TEXT_10);
+ for (Iterator cIter = genPackage.getGenClassifiers().iterator(); cIter.hasNext(); ) { GenClassifier genClassifier = (GenClassifier)cIter.next();
+ if (genClassifier instanceof GenClass) { GenClass genClass = (GenClass)genClassifier;
+ stringBuffer.append(TEXT_11);
+ stringBuffer.append(genClass.getName());
+ stringBuffer.append(ValidatorGeneratorUtil.getSuperTypesExpression(genClass));
+ for (Iterator fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); ) { GenFeature genFeature = (GenFeature)fIter.next();
+ String keyword = genFeature.isReferenceType() ? "Reference" : "Attribute";
+ stringBuffer.append(TEXT_12);
+ stringBuffer.append(keyword);
+ stringBuffer.append(TEXT_13);
+ if (genFeature.isDerived()) {
+ stringBuffer.append(TEXT_14);
+ }
+ stringBuffer.append(genFeature.getName());
+ stringBuffer.append(TEXT_15);
+ stringBuffer.append(ValidatorGeneratorUtil.getTypeExpression(genFeature));
+ }
+ for (Iterator oIter = genClass.getGenOperations().iterator(); oIter.hasNext(); ) { GenOperation genOperation = (GenOperation)oIter.next();
+ stringBuffer.append(TEXT_16);
+ stringBuffer.append(genOperation.getName());
+ stringBuffer.append(ValidatorGeneratorUtil.getParameterExpression(genOperation));
+ stringBuffer.append(TEXT_17);
+ stringBuffer.append(ValidatorGeneratorUtil.getTypeExpression(genOperation));
+ }
+ stringBuffer.append(TEXT_18);
+ } else if (genClassifier instanceof GenEnum) { GenEnum genEnum = (GenEnum)genClassifier;
+ stringBuffer.append(TEXT_19);
+ stringBuffer.append(genEnum.getName());
+ for (Iterator lIter = genEnum.getGenEnumLiterals().iterator(); lIter.hasNext(); ) { GenEnumLiteral genEnumLiteral = (GenEnumLiteral)lIter.next();
+ stringBuffer.append(TEXT_20);
+ stringBuffer.append(genEnumLiteral.getName());
+ stringBuffer.append(TEXT_21);
+ stringBuffer.append(genEnumLiteral.getValue());
+ }
+ stringBuffer.append(TEXT_22);
+ } else if (genClassifier instanceof GenDataType) { GenDataType genDataType = (GenEnum)genClassifier;
+ stringBuffer.append(TEXT_23);
+ stringBuffer.append(genDataType.getName());
+ stringBuffer.append(TEXT_24);
+ stringBuffer.append(genDataType.getEcoreDataType().getInstanceClassName());
+ stringBuffer.append(TEXT_25);
+ }
+ }
+ }
+ return stringBuffer.toString();
+ }
+}
diff --git a/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/Validator.java b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/Validator.java
new file mode 100644
index 000000000..0753190c0
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/src/org/eclipse/emf/examples/generator/validator/templates/model/Validator.java
@@ -0,0 +1,63 @@
+package org.eclipse.emf.examples.generator.validator.templates.model;
+
+import java.util.*;
+import org.eclipse.emf.codegen.ecore.genmodel.*;
+import org.eclipse.emf.examples.generator.validator.ValidatorGeneratorUtil;
+
+public class Validator
+{
+ protected static String nl;
+ public static synchronized Validator create(String lineSeparator)
+ {
+ nl = lineSeparator;
+ Validator result = new Validator();
+ nl = null;
+ return result;
+ }
+
+ protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
+ protected final String TEXT_1 = "";
+ protected final String TEXT_2 = "/**" + NL + " * <copyright>" + NL + " * </copyright>" + NL + " *" + NL + " * ";
+ protected final String TEXT_3 = "Id";
+ protected final String TEXT_4 = NL + " */" + NL + "package ";
+ protected final String TEXT_5 = ";" + NL;
+ protected final String TEXT_6 = NL + NL + "/**" + NL + " * A sample validator interface for {@link ";
+ protected final String TEXT_7 = "}." + NL + " * This doesn't really do anything, and it's not a real EMF artifact." + NL + " * It was generated by the org.eclipse.emf.examples.generator.validator plug-in to illustrate how EMF's code generator can be extended." + NL + " */" + NL + "public interface ";
+ protected final String TEXT_8 = NL + "{" + NL + "\tboolean validate();" + NL;
+ protected final String TEXT_9 = NL + "\tboolean validate";
+ protected final String TEXT_10 = "(";
+ protected final String TEXT_11 = " value);";
+ protected final String TEXT_12 = NL + "}";
+ protected final String TEXT_13 = NL;
+
+ public String generate(Object argument)
+ {
+ final StringBuffer stringBuffer = new StringBuffer();
+ GenClass genClass = (GenClass)argument; GenPackage genPackage = genClass.getGenPackage(); GenModel genModel = genPackage.getGenModel();
+ stringBuffer.append(TEXT_1);
+ stringBuffer.append(TEXT_2);
+ stringBuffer.append("$");
+ stringBuffer.append(TEXT_3);
+ stringBuffer.append("$");
+ stringBuffer.append(TEXT_4);
+ stringBuffer.append(ValidatorGeneratorUtil.getValidationPackageName(genPackage));
+ stringBuffer.append(TEXT_5);
+ genModel.markImportLocation(stringBuffer);
+ stringBuffer.append(TEXT_6);
+ stringBuffer.append(genClass.getQualifiedInterfaceName());
+ stringBuffer.append(TEXT_7);
+ stringBuffer.append(ValidatorGeneratorUtil.getValidatorInterfaceName(genClass));
+ stringBuffer.append(TEXT_8);
+ for (Iterator fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); ) { GenFeature genFeature = (GenFeature)fIter.next();
+ stringBuffer.append(TEXT_9);
+ stringBuffer.append(genFeature.getAccessorName());
+ stringBuffer.append(TEXT_10);
+ stringBuffer.append(genFeature.getImportedType());
+ stringBuffer.append(TEXT_11);
+ }
+ stringBuffer.append(TEXT_12);
+ genModel.emitSortedImports();
+ stringBuffer.append(TEXT_13);
+ return stringBuffer.toString();
+ }
+}
diff --git a/examples/org.eclipse.emf.examples.generator.validator/templates/Header.javajetinc b/examples/org.eclipse.emf.examples.generator.validator/templates/Header.javajetinc
new file mode 100644
index 000000000..27becf364
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/templates/Header.javajetinc
@@ -0,0 +1,6 @@
+/**
+ * <copyright>
+ * </copyright>
+ *
+ * <%="$"%>Id<%="$"%>
+ */
diff --git a/examples/org.eclipse.emf.examples.generator.validator/templates/model/ModelDescription.txtjet b/examples/org.eclipse.emf.examples.generator.validator/templates/model/ModelDescription.txtjet
new file mode 100644
index 000000000..229147844
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/templates/model/ModelDescription.txtjet
@@ -0,0 +1,41 @@
+<%@ jet package="org.eclipse.emf.examples.generator.validator.templates.model" class="ModelDescription" imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.emf.examples.generator.validator.ValidatorGeneratorUtil"%>
+<%GenModel genModel = (GenModel)argument;%>
+Model <%=genModel.getModelName()%>
+
+This model description is not a real EMF artifact. It was generated by the
+org.eclipse.emf.examples.generator.validator plug-in to illustrate how EMF's
+code generator can be extended.
+
+<%if (genModel.getGenPackages().size() > 1) {%>
+Contains packages:
+ <%for (Iterator iter = genModel.getGenPackages().iterator(); iter.hasNext(); ) { GenPackage genPackage = (GenPackage)iter.next();%>
+ <%=genPackage.getPackageName()%> <<%=genPackage.getNSURI()%>>
+ <%}%>
+
+<%}%>
+<%for (Iterator pIter = genModel.getGenPackages().iterator(); pIter.hasNext(); ) { GenPackage genPackage = (GenPackage)pIter.next();%>
+Package <%=genPackage.getPackageName()%> <<%=genPackage.getNSURI()%>>
+
+ <%for (Iterator cIter = genPackage.getGenClassifiers().iterator(); cIter.hasNext(); ) { GenClassifier genClassifier = (GenClassifier)cIter.next();%>
+ <%if (genClassifier instanceof GenClass) { GenClass genClass = (GenClass)genClassifier;%>
+ Class <%=genClass.getName()%><%=ValidatorGeneratorUtil.getSuperTypesExpression(genClass)%>
+ <%for (Iterator fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); ) { GenFeature genFeature = (GenFeature)fIter.next();%>
+ <%String keyword = genFeature.isReferenceType() ? "Reference" : "Attribute";%>
+ <%=keyword%> <%if (genFeature.isDerived()) {%>/<%}%><%=genFeature.getName()%> : <%=ValidatorGeneratorUtil.getTypeExpression(genFeature)%>
+ <%}%>
+ <%for (Iterator oIter = genClass.getGenOperations().iterator(); oIter.hasNext(); ) { GenOperation genOperation = (GenOperation)oIter.next();%>
+ Operation <%=genOperation.getName()%><%=ValidatorGeneratorUtil.getParameterExpression(genOperation)%> : <%=ValidatorGeneratorUtil.getTypeExpression(genOperation)%>
+ <%}%>
+
+ <%} else if (genClassifier instanceof GenEnum) { GenEnum genEnum = (GenEnum)genClassifier;%>
+ Enum <%=genEnum.getName()%>
+ <%for (Iterator lIter = genEnum.getGenEnumLiterals().iterator(); lIter.hasNext(); ) { GenEnumLiteral genEnumLiteral = (GenEnumLiteral)lIter.next();%>
+ Literal <%=genEnumLiteral.getName()%> = <%=genEnumLiteral.getValue()%>
+ <%}%>
+
+ <%} else if (genClassifier instanceof GenDataType) { GenDataType genDataType = (GenEnum)genClassifier;%>
+ DataType <%=genDataType.getName()%> <<%=genDataType.getEcoreDataType().getInstanceClassName()%>>
+
+ <%}%>
+ <%}%>
+<%}%> \ No newline at end of file
diff --git a/examples/org.eclipse.emf.examples.generator.validator/templates/model/Validator.javajet b/examples/org.eclipse.emf.examples.generator.validator/templates/model/Validator.javajet
new file mode 100644
index 000000000..08bd0b418
--- /dev/null
+++ b/examples/org.eclipse.emf.examples.generator.validator/templates/model/Validator.javajet
@@ -0,0 +1,21 @@
+<%@ jet package="org.eclipse.emf.examples.generator.validator.templates.model" class="Validator" imports="java.util.* org.eclipse.emf.codegen.ecore.genmodel.* org.eclipse.emf.examples.generator.validator.ValidatorGeneratorUtil"%>
+<%GenClass genClass = (GenClass)argument; GenPackage genPackage = genClass.getGenPackage(); GenModel genModel = genPackage.getGenModel();%>
+<%@ include file="../Header.javajetinc"%>
+package <%=ValidatorGeneratorUtil.getValidationPackageName(genPackage)%>;
+
+<%genModel.markImportLocation(stringBuffer);%>
+
+/**
+ * A sample validator interface for {@link <%=genClass.getQualifiedInterfaceName()%>}.
+ * This doesn't really do anything, and it's not a real EMF artifact.
+ * It was generated by the org.eclipse.emf.examples.generator.validator plug-in to illustrate how EMF's code generator can be extended.
+ */
+public interface <%=ValidatorGeneratorUtil.getValidatorInterfaceName(genClass)%>
+{
+ boolean validate();
+
+ <%for (Iterator fIter = genClass.getGenFeatures().iterator(); fIter.hasNext(); ) { GenFeature genFeature = (GenFeature)fIter.next(); %>
+ boolean validate<%=genFeature.getAccessorName()%>(<%=genFeature.getImportedType()%> value);
+ <%}%>
+}
+<%genModel.emitSortedImports();%>

Back to the top