Dynemf
Simple and small library to ease Eclipse Modeling Framework (EMF) dynamic instance manipulations (load/save/creation...) for standalone and non-standalone usage
Install / Use
/learn @aranega/DynemfREADME
DynEMF
This small library (only 3 dependencies) is designed to help you quickly prototype EMF applications using EMF dynamic instances. This library provides wrappers around EMF basic concepts. To sum up, this lib is here to ease the use of Dynamic EMF.
EMF dynamic instances
EMF is a powerful framework for metamodels/models handling. It provides a many facilities to create/build applications using metamodels and models. A strong feature of EMF is this ability to deal with dynamic instances, i.e. manipulating model instances without generating the Java code derived from a metamodel. Using dynamic instances, you can quickly messing around with models and prototyping stuffs before going to the EMF metamodel code generation process.
Unfortunately, this feature require advanced skills to deal with. Moreover, for the new user, the ResourceSet/Resource layer along with the metamodel registering/generation, Eclipse plugins... can be a very difficult to tame. This little library as vocation of providing various facilities to handle dynamic instances and hide a little bit these layers.
Examples
[source, java] .Registering a metamodel (contained in an .ecore file) and loading a model
// Register the metamodel ResourceSetWrapper rset = rset().register("src/test/resources/metamodels/simple.ecore");
// Load an existing model that conforms to the previously loaded metamodel ResourceWrapper r = rset.open("src/test/resources/models/01.xmi");
// Display its root System.out.println(r.root());
[source, java] .Registering a metamodel, getting the metamodel and creating instances.
// Register the metamodel ResourceSetWrapper rset = rset().register("src/test/resources/metamodels/simple.ecore");
// Get the metamodel using its nsURI EPackageWrapper mm = rset.ePackage("http://DynEMF/simple/1.0");
// Create an A instance from this metamodel and sets this feature "name" to "test" EObjectWrapper<EObject> a = mm.create("A").set("name", "test");
// Create a resource to carry the created elements ResourceWrapper r = rset.creates("target/gen/model01.xmi").add(a).save();
// Add a new instance to "a" a.add("a", mm.create("A"));
// Save the model into another file r.saveAs("target/gen/model02.xmi");
[source, java] .From an existing and well parametered 'rset' (see previous examples), creates two binary files.
ResourceWrapper r2 = rset.create("target/A.bin").add(mm.create("A").set("name", "testA")).save(); r2.clear().add(simplemm.create("A").set("name", "testB")).saveAs("target/B.bin");
Also, you don't have to wrap averything. You can use the same API with existing EObjects. [source, java] .Referencing an existing EObject
EObject eobj1 = ....; // My EObject not wrapped EObject eobj2 = ...; // My second one m.create("A").add("a", eobj1, eobj2);
License
MIT License - see the LICENSE file in the source distribution
