User:Lindenb/Notebook/UMR915/20110517
From OpenWetWare

EMF
learning EMF -eclipse modeling framework- http://www.eclipse.org/modeling/emf/
Select project location
The new project is created:
~/tmp/workspace20110401> find ./EMFDataStore/ ./EMFDataStore/ ./EMFDataStore/.classpath ./EMFDataStore/META-INF ./EMFDataStore/META-INF/MANIFEST.MF ./EMFDataStore/src ./EMFDataStore/model ./EMFDataStore/.project ./EMFDataStore/bin
cat ./EMFDataStore/.classpath
<?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/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
cat ./EMFDataStore/.project
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EMFDataStore</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>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>
Then : create new Ecore Model:
We want to generate a whole package:
find ./EMFDataStore/ -type f ./EMFDataStore/.classpath ./EMFDataStore/META-INF/MANIFEST.MF ./EMFDataStore/model/emfdatastore.ecore ./EMFDataStore/.project
cat ./EMFDataStore/model/emfdatastore.ecore <?xml version="1.0" encoding="UTF-8"?> <ecore:EPackage xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmi:version="2.0" name=""/>
Create EMF Generator Model
create a generator model
create model for ECore
select the emfdatastore.ecore in the workspace
find ./EMFDataStore/ -type f ./EMFDataStore/.classpath ./EMFDataStore/META-INF/MANIFEST.MF ./EMFDataStore/model/emfdatastore.genmodel ./EMFDataStore/model/emfdatastore.ecore ./EMFDataStore/.project
xmllint --format ./EMFDataStore/model/emfdatastore.genmodel
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmlns:xmi="http://www.omg.org/XMI" xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" xmi:version="2.0" modelDirectory="/EMFDataStore/src" modelPluginID="EMFDataStore" modelName="Emfdatastore" importerID="org.eclipse.emf.importer.ecore" complianceLevel="6.0" copyrightFields="false">
<foreignModel>emfdatastore.ecore</foreignModel>
<genPackages prefix="DataStore" disposableProviderFactory="true" ecorePackage="emfdatastore.ecore#/">
<genEnums typeSafeEnumCompatible="false" ecoreEnum="emfdatastore.ecore#//Gender">
<genEnumLiterals ecoreEnumLiteral="emfdatastore.ecore#//Gender/UNKNOWN"/>
<genEnumLiterals ecoreEnumLiteral="emfdatastore.ecore#//Gender/MALE"/>
<genEnumLiterals ecoreEnumLiteral="emfdatastore.ecore#//Gender/FEMALE"/>
</genEnums>
</genPackages>
</genmodel:GenModel>
content generated
EMFDataStore.edit
find EMFDataStore.edit -type f EMFDataStore.edit/.classpath EMFDataStore.edit/plugin.xml EMFDataStore.edit/META-INF/MANIFEST.MF EMFDataStore.edit/src/DataStore/provider/EmfdatastoreEditPlugin.java EMFDataStore.edit/.project EMFDataStore.edit/plugin.properties EMFDataStore.edit/bin/DataStore/provider/EmfdatastoreEditPlugin$Implementation.class EMFDataStore.edit/bin/DataStore/provider/EmfdatastoreEditPlugin.class EMFDataStore.edit/build.properties
xmllint --format EMFDataStore.edit/plugin.xml <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <!-- <copyright> </copyright> $Id$ --> <plugin> </plugin>
cat EMFDataStore.edit/META-INF/MANIFEST.MF Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: EMFDataStore.edit;singleton:=true Bundle-Version: 1.0.0 Bundle-ClassPath: . Bundle-Activator: DataStore.provider.EmfdatastoreEditPlugin$Implementation Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: DataStore.provider Require-Bundle: org.eclipse.core.runtime, EMFDataStore;visibility:=reexport, org.eclipse.emf.edit;visibility:=reexport Bundle-ActivationPolicy: lazy
cat EMFDataStore.edit/plugin.properties
# <copyright>
# </copyright>
#
# $Id$
pluginName = Emfdatastore Edit Support
providerName = www.example.org
_UI_CreateChild_text = {0}
_UI_CreateChild_text2 = {1} {0}
_UI_CreateChild_text3 = {1}
_UI_CreateChild_tooltip = Create New {0} Under {1} Feature
_UI_CreateChild_description = Create a new child of type {0} for the {1} feature of the selected {2}.
_UI_CreateSibling_description = Create a new sibling of type {0} for the selected {2}, under the {1} feature of their parent.
_UI_PropertyDescriptor_description = The {0} of the {1}
_UI_Unknown_type = Object
_UI_Unknown_datatype= Value
_UI_Unknown_feature = Unspecified
_UI_Gender_UNKNOWN_literal = UNKNOWN
_UI_Gender_MALE_literal = MALE
_UI_Gender_FEMALE_literal = FEMALE
cat EMFDataStore.edit/src/DataStore/provider/EmfdatastoreEditPlugin.java
/**
* <copyright>
* </copyright>
*
* $Id$
*/
package DataStore.provider;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.util.ResourceLocator;
/**
* This is the central singleton for the Emfdatastore edit plugin.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public final class EmfdatastoreEditPlugin extends EMFPlugin {
/**
* Keep track of the singleton.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static final EmfdatastoreEditPlugin INSTANCE = new EmfdatastoreEditPlugin();
/**
* Keep track of the singleton.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private static Implementation plugin;
/**
* Create the instance.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EmfdatastoreEditPlugin() {
super
(new ResourceLocator [] {
});
}
/**
* Returns the singleton instance of the Eclipse plugin.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the singleton instance.
* @generated
*/
@Override
public ResourceLocator getPluginResourceLocator() {
return plugin;
}
/**
* Returns the singleton instance of the Eclipse plugin.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the singleton instance.
* @generated
*/
public static Implementation getPlugin() {
return plugin;
}
/**
* The actual implementation of the Eclipse <b>Plugin</b>.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static class Implementation extends EclipsePlugin {
/**
* Creates an instance.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Implementation() {
super();
// Remember the static instance.
//
plugin = this;
}
}
}
cat EMFDataStore.edit/build.properties
# <copyright>
# </copyright>
#
# $Id$
bin.includes = .,\
icons/,\
META-INF/,\
plugin.xml,\
plugin.properties
jars.compile.order = .
source.. = src/
output.. = bin/
EMFDataStore.editor
find ./EMFDataStore.editor -type f ./EMFDataStore.editor/.classpath ./EMFDataStore.editor/plugin.xml ./EMFDataStore.editor/META-INF/MANIFEST.MF ./EMFDataStore.editor/src/DataStore/presentation/EmfdatastoreEditorPlugin.java ./EMFDataStore.editor/.project ./EMFDataStore.editor/plugin.properties ./EMFDataStore.editor/bin/DataStore/presentation/EmfdatastoreEditorPlugin$Implem entation.class ./EMFDataStore.editor/bin/DataStore/presentation/EmfdatastoreEditorPlugin.class ./EMFDataStore.editor/build.properties
xmllint --format ./EMFDataStore.editor/plugin.xml <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <!-- <copyright> </copyright> $Id$ --> <plugin> </plugin>
cat ./EMFDataStore.editor/META-INF/MANIFEST.MF Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: EMFDataStore.editor;singleton:=true Bundle-Version: 1.0.0 Bundle-ClassPath: . Bundle-Activator: DataStore.presentation.EmfdatastoreEditorPlugin$Implementation Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: DataStore.presentation Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources;visibility:=reexport, EMFDataStore.edit;visibility:=reexport, org.eclipse.emf.ecore.xmi;visibility:=reexport, org.eclipse.emf.edit.ui;visibility:=reexport, org.eclipse.ui.ide;visibility:=reexport Bundle-ActivationPolicy: lazy
cat ./EMFDataStore.editor/src/DataStore/presentation/EmfdatastoreEditorPlugin.java
/**
* <copyright>
* </copyright>
*
* $Id$
*/
package DataStore.presentation;
import org.eclipse.emf.common.EMFPlugin;
import org.eclipse.emf.common.ui.EclipseUIPlugin;
import org.eclipse.emf.common.util.ResourceLocator;
/**
* This is the central singleton for the Emfdatastore editor plugin.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public final class EmfdatastoreEditorPlugin extends EMFPlugin {
/**
* Keep track of the singleton.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static final EmfdatastoreEditorPlugin INSTANCE = new EmfdatastoreEditorPlugin();
/**
* Keep track of the singleton.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
private static Implementation plugin;
/**
* Create the instance.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EmfdatastoreEditorPlugin() {
super
(new ResourceLocator [] {
});
}
/**
* Returns the singleton instance of the Eclipse plugin.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the singleton instance.
* @generated
*/
@Override
public ResourceLocator getPluginResourceLocator() {
return plugin;
}
/**
* Returns the singleton instance of the Eclipse plugin.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the singleton instance.
* @generated
*/
public static Implementation getPlugin() {
return plugin;
}
/**
* The actual implementation of the Eclipse <b>Plugin</b>.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static class Implementation extends EclipseUIPlugin {
/**
* Creates an instance.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Implementation() {
super();
// Remember the static instance.
//
plugin = this;
}
}
}
cat ./EMFDataStore.editor/plugin.properties
# <copyright>
# </copyright>
#
# $Id$
pluginName = Emfdatastore Editor
providerName = www.example.org
_UI_DataStoreEditor_menu = &DataStore Editor
_UI_CreateChild_menu_item = &New Child
_UI_CreateSibling_menu_item = N&ew Sibling
_UI_ShowPropertiesView_menu_item = Show &Properties View
_UI_RefreshViewer_menu_item = &Refresh
_UI_SelectionPage_label = Selection
_UI_ParentPage_label = Parent
_UI_ListPage_label = List
_UI_TreePage_label = Tree
_UI_TablePage_label = Table
_UI_TreeWithColumnsPage_label = Tree with Columns
_UI_ObjectColumn_label = Object
_UI_SelfColumn_label = Self
_UI_NoObjectSelected = Selected Nothing
_UI_SingleObjectSelected = Selected Object: {0}
_UI_MultiObjectSelected = Selected {0} Objects
_UI_OpenEditorError_label = Open Editor
_UI_Wizard_category = Example EMF Model Creation Wizards
_UI_CreateModelError_message = Problems encountered in file "{0}"
_UI_DataStoreModelWizard_label = DataStore Model
_UI_DataStoreModelWizard_description = Create a new DataStore model
_UI_DataStoreEditor_label = DataStore Model Editor
_UI_DataStoreEditorFilenameDefaultBase = My
_UI_DataStoreEditorFilenameExtensions = datastore
_UI_Wizard_label = New
_WARN_FilenameExtension = The file name must end in ''.{0}''
_WARN_FilenameExtensions = The file name must have one of the following extensions: {0}
_UI_ModelObject = &Model Object
_UI_XMLEncoding = &XML Encoding
_UI_XMLEncodingChoices = UTF-8 ASCII UTF-16 UTF-16BE UTF-16LE ISO-8859-1
_UI_Wizard_initial_object_description = Select a model object to create
_UI_FileConflict_label = File Conflict
_WARN_FileConflict = There are unsaved changes that conflict with changes made outside the editor. Do you wish to discard this editor's changes?
cat ./EMFDataStore.editor/build.properties
# <copyright>
# </copyright>
#
# $Id$
bin.includes = .,\
icons/,\
META-INF/,\
plugin.xml,\
plugin.properties
jars.compile.order = .
source.. = src/
output.. = bin/
EMFDataStore.tests
find ./EMFDataStore.tests/ -type f ./EMFDataStore.tests/.classpath ./EMFDataStore.tests/META-INF/MANIFEST.MF ./EMFDataStore.tests/src/DataStore/tests/EmfdatastoreAllTests.java ./EMFDataStore.tests/src/DataStore/tests/DataStoreExample.java ./EMFDataStore.tests/src/DataStore/tests/DataStoreTests.java ./EMFDataStore.tests/.project ./EMFDataStore.tests/plugin.properties ./EMFDataStore.tests/bin/DataStore/tests/EmfdatastoreAllTests.class ./EMFDataStore.tests/bin/DataStore/tests/DataStoreExample.class ./EMFDataStore.tests/bin/DataStore/tests/DataStoreTests.class ./EMFDataStore.tests/build.properties
cat ./EMFDataStore.tests/META-INF/MANIFEST.MF Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: EMFDataStore.tests;singleton:=true Bundle-Version: 1.0.0 Bundle-ClassPath: . Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: DataStore.tests Require-Bundle: org.eclipse.core.runtime, EMFDataStore;visibility:=reexport, org.eclipse.emf.ecore.xmi;visibility:=reexport, org.junit;visibility:=reexport Bundle-ActivationPolicy: lazy
cat ./EMFDataStore.tests/src/DataStore/tests/EmfdatastoreAllTests.java
/**
* <copyright>
* </copyright>
*
* $Id$
*/
package DataStore.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* <!-- begin-user-doc -->
* A test suite for the '<em><b>Emfdatastore</b></em>' model.
* <!-- end-user-doc -->
* @generated
*/
public class EmfdatastoreAllTests extends TestSuite {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static void main(String[] args) {
TestRunner.run(suite());
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static Test suite() {
TestSuite suite = new EmfdatastoreAllTests("Emfdatastore Tests");
return suite;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EmfdatastoreAllTests(String name) {
super(name);
}
} //EmfdatastoreAllTests
cat ./EMFDataStore.tests/src/DataStore/tests/DataStoreExample.java
/**
* <copyright>
* </copyright>
*
* $Id$
*/
package DataStore.tests;
import DataStore.DataStorePackage;
import java.io.File;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
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.Diagnostician;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
/**
* <!-- begin-user-doc -->
* A sample utility for the '<em><b>DataStore</b></em>' package.
* <!-- end-user-doc -->
* @generated
*/
public class DataStoreExample {
/**
* <!-- begin-user-doc -->
* Load all the argument file paths or URIs as instances of the model.
* <!-- end-user-doc -->
* @param args the file paths or URIs.
* @generated
*/
public static void main(String[] args) {
// Create a resource set to hold the resources.
//
ResourceSet resourceSet = new ResourceSetImpl();
// Register the appropriate resource factory to handle all file extensions.
//
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
(Resource.Factory.Registry.DEFAULT_EXTENSION,
new XMIResourceFactoryImpl());
// Register the package to ensure it is available during loading.
//
resourceSet.getPackageRegistry().put
(DataStorePackage.eNS_URI,
DataStorePackage.eINSTANCE);
// If there are no arguments, emit an appropriate usage message.
//
if (args.length == 0) {
System.out.println("Enter a list of file paths or URIs");
}
else {
// Iterate over all the arguments.
//
for (int i = 0; i < args.length; ++i) {
// Construct the URI for the instance file.
// The argument is treated as a file path only if it denotes an existing file.
// Otherwise, it's directly treated as a URL.
//
File file = new File(args[i]);
URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()): URI.createURI(args[i]);
try {
// Demand load resource for this file.
//
Resource resource = resourceSet.getResource(uri, true);
System.out.println("Loaded " + uri);
// Validate the contents of the loaded resource.
//
for (EObject eObject : resource.getContents()) {
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
if (diagnostic.getSeverity() != Diagnostic.OK) {
printDiagnostic(diagnostic, "");
}
}
}
catch (RuntimeException exception) {
System.out.println("Problem loading " + uri);
exception.printStackTrace();
}
}
}
}
/**
* <!-- begin-user-doc -->
* Prints diagnostics with indentation.
* <!-- end-user-doc -->
* @param diagnostic the diagnostic to print.
* @param indent the indentation for printing.
* @generated
*/
protected static void printDiagnostic(Diagnostic diagnostic, String indent) {
System.out.print(indent);
System.out.println(diagnostic.getMessage());
for (Diagnostic child : diagnostic.getChildren()) {
printDiagnostic(child, indent + " ");
}
}
} //DataStoreExample
cat ./EMFDataStore.tests/src/DataStore/tests/DataStoreTests.java
/**
* <copyright>
* </copyright>
*
* $Id$
*/
package DataStore.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* <!-- begin-user-doc -->
* A test suite for the '<em><b>DataStore</b></em>' package.
* <!-- end-user-doc -->
* @generated
*/
public class DataStoreTests extends TestSuite {
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static void main(String[] args) {
TestRunner.run(suite());
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public static Test suite() {
TestSuite suite = new DataStoreTests("DataStore Tests");
return suite;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public DataStoreTests(String name) {
super(name);
}
} //DataStoreTests
cat ./EMFDataStore.tests/plugin.properties # <copyright> # </copyright> # # $Id$ pluginName = Emfdatastore Tests providerName = www.example.org
cat ./EMFDataStore.tests/build.properties
# <copyright>
# </copyright>
#
# $Id$
bin.includes = .,\
META-INF/,\
plugin.properties
jars.compile.order = .
source.. = src/
output.. = bin/












