Jump to: navigation, search

EMF/FAQ

In addition to the FAQ below, see also:


Contents

Newbie /General

What is EMF?

The Eclipse Modeling Framework is a Java/XML framework for generating tools and other applications based on simple class models. EMF helps you rapidly turn models into efficient, correct, and easily customizable Java code. It is intended to provide the benefits of formal modeling, but with a very low cost of entry. In addition to code generation, it provides the ability to save objects as XML documents for interchange with other tools and applications. Models can be created using annotated Java, XML documents, or modeling tools like Rational Rose, then imported into EMF. The code generator turns a model into a set of Java implementation classes. These classes are extensible and regenerable - you can modify them by adding user-defined methods and instance variables. When the model changes, you can regenerate the implementation classes, and your modifications will be retained. This works both ways - changes in the Java code can be used to update the model.

Where can I get EMF?

Publically available builds are always listed on the EMF website.

To download them, go to the downloads page or install them via update manager.

Details about what was fixed in a given build can be seen on our release notes page.

How do I get started with EMF?

Start by reading the overview documents and the tutorials, followed by downloading the driver.

After going through the tutorial, you will have generated a completely working editor from nothing but a picture of the object model (i.e., the simple libarary model shown in the tutorial). If you run the generated editor, you can add and remove books and authors, edit the properties (e.g., the book title), copy, paste, drag-and-drop, etc. All with unlimited undo/redo. You can also save the document (the default framework serialization format is XMI).

The purpose of the tutorial is to illustrate the power of a model driven architecture (MDA). By providing a model for the data your application will manipulate, you can use EMF to generate a Java implementation for you. EMF.Edit can leverage the same model (meta) data to generate view support and even a working editor. Read the overview documents for more details.

What version of Eclipse do I need for EMF, SDO and XSD? Which EMF version will run on my Eclipse version?

The most recent version requirements and bleeding edge information about requirements can be seen on the EMF Downloads page.

  • EMF 2.4.x runs on Eclipse 3.4.x.
  • EMF 2.3.x runs on Eclipse 3.3.x.
  • EMF 2.2.x runs on Eclipse 3.2.x.
  • EMF 2.1.x runs on Eclipse 3.1.x.
  • EMF 2.0.2 through 2.0.5 run on Eclipse 3.0.2. EMF 2.0 & 2.0.1 run on Eclipse 3.0 & 3.0.1.
  • EMF 1.0 & 1.1 run on Eclipse 2.0 & 2.1.

What minimum version of Java do I need?

  • EMF 2.4.x requires JRE 1.5 or later.
  • EMF 2.3.x requires JRE 1.5 or later.
  • EMF 2.2.x requires JRE 1.4.2 or later.
  • EMF 2.1.x requires JRE 1.4.2 or later.
  • EMF 2.0.x requires JRE 1.3.1 or later.
  • EMF 1.x requires JRE 1.3.1 or later.

Are there any "real" example EMF models in Eclipse?

Well, for starters, EMF itself contains two interesting models. The Ecore model serves as the meta-model for any EMF model you create -- it is the model that describes the structure of your models. The Genmodel controls generation of an EMF model. In fact, the generator UI that is used in the tutorial is the EMF.Edit editor for the Genmodel, which explains why it looks so much like the library editor in the tutorial. If you want to explore Ecore and Genmodel further, you'll find their Rose models and Java code in the EMF source package available on our download page. Of course, the code produced by the EMF generator is meant to be a starting place, so you'll see that much functionality has been manually added to both of these models. But, it's quite easy to see the same sort of generated patterns that appear in the simple library example. Ecore is in the org.eclipse.emf.ecore plugin, the Genmodel is in org.eclipse.emf.codegen.ecore, and its editor UI is in org.eclipse.emf.codegen.ecore.ui. You'll find the Rose models in the "model" subdirectory of the source for the former two plugins.

Finally, an even more complex example of an EMF model is XSD, the XML Schema Infoset Model, a subproject of the Eclipse Technology Project. XSD models the concrete and abstract relationships expressed in an XML schema document, providing an API to manipulate the model and an XML-schema-specific replacement for EMF's default XMI serialization. Of course, there's also an EMF.Edit-based XML schema editor built on it. For more on XML Schema, see the XSD FAQ.

How does EMF perform in regard to serializing to relational databases? I am wondering if this framework suits central repository servers, where hundreds of thousand of instances are present. When is it mandatory to have a relational database as the EMF's object serialization target?

There is no out of the box EMF support for RDB persistence, but several people have done or are doing such things themselves. It involves customized resources, or in the case of SDO - mediators. See also CDO and Teneo.

If using EMF in a non-Eclipse environment is feasible (licensing issues), what if any, advantages does using EMF have over using JAXB?

EMF and XSD are definitely intended to support standalone execution outside of Eclipse.Only the EMF jars are needed for standalone execution (as described in the FAQ).Within IBM, you should discuss licensing issues with the IBM Eclipse SDK folks, since that's the supported distribution vehicle for EMF and XSD within IBM.I don't believe there are any issues as long as you stick to using released (i.e., supported) drivers.

JAXB produces a simple Java API given an XML Schema and it does so using essentially a black box design.EMF produces an Ecore model given an XML Schema and then uses template-based generator technology to generate a rich Java API (of hand written quality).The XML Schema to Ecore conversion can be tailored, the templates used to generate the Java API can be tailored, and the resulting Java API can be tailored.The generator supports merging regeneration so that it will preserve your hand written changes.In other words, EMF is far richer and more flexible, and supports a broader subset of XML Schema (especially in 2.0, where wildcards and mixed content will be supported). See http://www.theserverside.com/tt/articles/article.tss?l=BindingXMLJava for more details.

Why does EMF need a GenModel as well as an Ecore model to generate code?

The GenModel is a decorator model for the Ecore model. It specifies information not available in the Ecore model and gives fine grained control over what's generated. For example, the Ecore model doesn't indicate where the code should be generated and what the plugin ID (if any) for that target should be; that's specified in the GenModel. The GenModel also lets you choose among various generation patterns. For example, do you want root interfaces to extend EObject, nothing, or something of your own choosing? And do you want to generate an editor that targets the Eclipse Rich Client Platform versus the Eclipse Integrated Development Environment? So you can think of the GenModel as a giant parameter for controlling and tailoring the code generation process.

Development

EMF is failing to load a resource. How can I make it recognize a non-standard archive URI scheme? Why does EMF fail to load resources when running on an application server or other specialized runtime?

EMF recognizes a couple of well known archive schemes, such as "zip" and "jar", so everything will work fine if the URI of an archived resource starts, for example, with "zip:".Although most applications probably use one of these recognized schemes, you may find that certain runtimes use a different one.For example, when running in the IBM WebSphere Application Server, Class.getResource(String) may return a URL with a "wsjar" scheme, like "wsjar:file:/C:/dev/ws/default/sample_app/xsd.resources.jar!/org/eclipse/xsd/plugin.properties".
By default, EMF will not recognize this as an archive URI and will fail to handle it correctly, probably resulting in multiple unregistered resources errors and/or null pointer exceptions. If you are facing this problem, you will need to change EMF's set of recognized archive schemes. This is done by defining a property named "org.eclipse.emf.common.util.URI.archiveSchemes", whose value is the desired space-separated list of archive schemes.Here's an example of how you could define it when invoking your Java application:

java MyApp -Dorg.eclipse.emf.common.util.URI.archiveSchemes="wsjar wszip jar zip"

Is there a built-in facility to check whether a given value is valid compared to the effective facets of its type?

To determine if a literal is valid with respect to a simple type, you can use either XSDSimpleTypeDefinition.isValidLiteral or XSDSimpleTypeDefinition.assess.

I have a simple model consisting of a root that contains a single EList of children.The child type contains several attributes.I would like to create a custom editor such that the model is completely displayed in a table. How should I start? Overload getText() on the child item provider, and just return null for a property descriptor?

Try working within the generated editor and updating the tab with existing table viewer support there until you have it working nicely. You might want a plain table or a table tree.You can add some more columns in the editor for the table/table tree and then use your item provider's implementation of ITableItemLabelProvider to populate the additional columns.Property descriptors will only be used when they are needed, so you don't have to do anything to hide them.

How big a job would it be to get the EMF editor generator to spit out Swing editor code instead of SWT/JFace code?

You'd want something similar to org.eclipse.emf.edit.ui, but for binding the platform independent .edit support to Swing instead of to Eclipse, and you'd want to replace the editor templates with stuff for Swing. It's not a trivial task, but not a huge one either.

Are there any examples of EMF used standalone?

Yes, definitely. In fact, SDO (Service Data Objects) is a standalone application of EMF. Javadoc, Download.

Is it possible to convert back from EMF model (ecore files or generated Java code?) to UML?

It's possible in theory, but we don't have anything like the working in practice.It shouldn't be too difficult to do the Ecore to UML2 conversion using Eclipse's EMF-based UML2 model.

Check the uml2 newsgroup. They may have plans or already have an Ecore model importer.

As of EMF 2.0.0.I20040408, it seems like the code templates in chapter 14.2.3 in the emf-book needs to be rewritten. Is this already done and published somewhere?

The existing mechanisms should continue to work, but will result in deprecation warnings for 2.0. The framework was generalized so that a number of places where only EReference was supported, now EStructuralFeature is supported. It would certainly be a FAQ worthy addition to outline the places where such changes would be made.

Can I link parts of UML diagrams to portions of the code in the EMF editor?

Yes, but the UML2 project should be able to provide you with most of the "model" code that you need, and the GEF project will give you a huge head-start when it comes to creating the "view" and "controller" bits.

I would guess that the best approach when it comes to linking your model and code would be via the JET framework which is part of EMF, this will handle most of the merging issues for you.

Is there an electronic version of the EMF book?

There's an IBM "RedBook" on GEF which also has some chapters on EMF in it, it's a free download at http://www.redbooks.ibm.com/redbooks/pdfs/sg246302.pdf.

You can buy an electronic copy of the book here: http://www.awprofessional.com/titles/0131425420.

Is there a clean way to use an EMF model's generated editor in a standalone application?

The .edit projects can be used standalone (although you'd need to put the plugin.properties and icons into a resource jar), but the .editor projects are tightly integrated Eclipse components that will only function within an Eclipse environment.

For more information on working outside Eclipse, see the question "How do I use EMF in standalone applications (such as an ordinary main)?]".

I want to use EMF, SDO, or XSD in my standalone project, or include only a working subset of the code. What libraries (jar files) do I need in my CLASSPATH?

Eclipse Modeling Framework (EMF) provides the infrastructure to run the generated models and dynamic model based on existing ecore files. It also provides XMI/XML serialization and deserialization.

The following jars can be used in standalone mode. Jars are found under the plugins directory of your Eclipse installation, e.g. org.eclipse.emf.common_2.3.0.v200706262000.jar.

Add to the following jars to your CLASSPATH or copy them into your project. For EMF 2.3.0, this includes, but is not limited to:

  • org.eclipse.emf.common_2.3.0.v200706262000.jar
  • org.eclipse.emf.ecore_2.3.0.v200706262000.jar
  • org.eclipse.emf.ecore.change_2.3.0.v200706262000.jar
  • org.eclipse.emf.ecore.xmi_2.3.0.v200706262000.jar

Service Data Objects (SDO) is an API specification in the format of Java interfaces and the EMF implementation that requires the EMF jars above and the following jars to be used in standalone mode:

  • org.eclipse.emf.commonj.sdo_2.3.0.v200706262000.jar
  • org.eclipse.emf.ecore.sdo_2.3.0.v200706262000.jar

XML Schema Infoset Model (XSD) is a reference library for use with any code that manipulates XML schemas and requires the EMF jars above and the following jars to be used in standalone mode:

  • org.eclipse.xsd_2.3.0.v200706262000.jar

For more information on working outside Eclipse, see the question How do I use EMF in standalone applications (such as an ordinary main)?. See also Standalone Zip removed in EMF 2.3. For EMF 2.1 standalone, see the archives.

Does it matter what node in the genmodel tree I invoke Generate from?

Definitely. To do a full generation, you need to invoke "Generate" or "Generate EMF.Edit" from the root node in the genmodel editor. If you invoke Generate lower down, you'll only generate the files associated with the selected subtree.

Can model classes be in the Java default package?

No. EMF does not allow model classes to be in the default Java package because it would need to be handled specially in the code generator, and since it's not a good Java convention anyway, we don't think it is worth supporting. Make sure that if you load your model from annotated Java that all the interfaces and classes with an @model tag also have an explicit package declaration.

Can annotated Java files use * imports?

Currently no. Until our Java name lookup mechanisms are improved, we really rely on explicit imports to resolve names, i.e., two * imports would confuse the code. It's best to entirely avoid * imports for the time being. We will improve identifier lookup in the coming weeks.

Does regeneration/merge work for properties and plugin.xml files?

Not yet. The current generator does not support merge for the plugin.properties and plugin.xml files, so it will not overwrite them if they exist. If you want to regenerate them, you'll need to remove or rename them before regenerating. This will also be improved in the future.

How do I use EMF in standalone applications (such as an ordinary main)?

An EMF model can be used without change in a standalone application with couple of exceptions.

Default resource factories are not registered in the standalone EMF environment. Therefore, for each file extension or scheme your application wants to load or save, you need to register the corresponding resource factory. For example, to load and save XMI documents, add a line similar to the one below to your main program:

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("library", new XMIResourceFactoryImpl());

To load and save XML documents, register the following factory:

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());

In the above examples, the model is registered using the global static resource factory registry instance. You can also register factories local to the ResourceSet being used, e.g:

ResourceSet rs = new ResourceSet();
rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());

In addition, you'll also need to register your package, which happens as a side effect of accessing XyzPackage.eINSTANCE. For example, to register the library model, add the following line to your main program:

LibraryPackage.eINSTANCE.eClass();

You need to add to the CLASSPATH all the jars for the plugins (and their dependent plugins) that you want to use standalone. The list is dependent on exactly what plugins you want to use and is available by looking at the runtime libraries in their plugin.xml files. This includes, but is not limited to:

  • org.eclipse.emf.common_2.3.0.v200706262000.jar
  • org.eclipse.emf.ecore_2.3.0.v200706262000.jar
  • org.eclipse.emf.ecore.xmi_2.3.0.v200706262000.jar

The jars are found under the plugins directory of your Eclipse installation. There will be a release number appended to the plugin name, e.g. org.eclipse.emf.common_2.3.0.v200706262000.

For EMF.Edit you would also have to add the following jar files to your classpath:

  • org.eclipse.emf.common.ui_2.3.0.v200706262000.jar
  • org.eclipse.emf.edit_2.3.0.v200706262000.jar


See also EMF/FAQ#I want to use EMF, SDO, or XSD in my standalone project, or include only a working subset of the code. What libraries (jar files) do I need in my CLASSPATH? and Standalone Zip removed in EMF 2.3. For EMF 2.1 standalone, see the archives.

I get a PackageNotFoundException: e.g., "Package with uri 'http://com.example.company.ecore' not found." What do I need to do?

When an EMF model instance (or SDO data graph) is loaded from its serialized form, the resource needs to obtain the correct metamodel, which is to be instantiated. The metamodel, represented by EMF as an EPackage, must be available (either in memory, or in serialized form), and EMF must be able to locate it from its namespace URI, which appears in the serialized model instance.
There are number of different ways this can occur, depending on a number of factors:

  • Static or dynamic: static means code has been generated at development time to implement the model; dynamic means no code has been generated and the metamodel is built in memory.
  • Eclipse or standalone: you may be running your code under or outside of Eclipse. The latter is referred to as standalone.
  • EMF or SDO: you may be using non-SDO EMF, or SDO.

When using static SDO standalone, it is recommended to follow the instructions described under "Do I have to pre-register my static, generated package when running standalone (outside of Eclipse)?"

If you are using static EMF, the generated package interface (e.g. CompanyPackage) will include a static field called eINSTANCE. Accessing this field will cause the package to be initialized and registered in the global package registry, allowing any resource to locate it. For example, the following code accesses the eINSTANCE field of CompanyPackage:

CompanyPackage packageInstance = CompanyPackage.eINSTANCE;

When running under Eclipse, this step is unnecessary, as a plug-in manifest file drives automatic package registration.

In SDO, the package can be included in the serialized data graph, along with the instance data that requires it. This is one option with dynamic, for example. To do so, refer to "How do I serialize the model of an SDO data graph?"

To register a dynamic model, refer to "How do I register a dynamic package?" Alternatively, the metamodel can be automatically loaded from its serialized form. For details, refer to "Do I have to initialize and pre-register my dynamic packages?"

I get a DanglingHREFException: e.g., "org.eclipse.emf.ecore.xmi.DanglingHREFException: The object 'com.example.Foo@2f5dda ()' is not contained in a resource." What do I need to do?

All objects need to be contained by a resource in order to be serialized. That implies that for EObject x to be serialized, it must be the case that x.eResource() != null. The resource will be non-null if either x is directly contained by a resource, i.e., if for Resource r, r.getContents().contains(x), or if x has a container that in turn is contained by a resource, i.e., if for Resource r, r.getContents().contains(x.eContainer()). This definition is recursive. So an object must be contained by a resource directly, or indirectly by virtue of being part of a containment reference where, recursively, the container too must be contained by a resource.

So if you get the above exception, that means you have some object x contained by a resource r that refers to another object y, that is not directly or indirectly contained by any resource. It's possible to make the EReference feature used by x to refer to y be transient, so that it's not saved at all, or to make it a containment reference, so that y is contained by the same resource as x, but barring changes to the Ecore model itself, the one and only way to solve this problem is to add y to some resource, i.e., r.getContents().add(y), or to add/set it to some containment reference of an object z, i.e., z.getYs().add(y), where z is already contained by a resource, i.e., z.eResource() != null.

Do I have to pre-register my static, generated package when running standalone (outside of Eclipse)?

No. Use the OPTION_SCHEMA_LOCATION_IMPLEMENTATION option to avoid pre-registration of your generated packages. This is the recommended approach to using static SDO.

When a model instance is saved with this option set, an xsi:schemaLocation attribute will be added to the document element, associating the package's namespace URI with the qualified name of the generated package interface. When the package is needed at load-time, the eINSTANCE field of that interface will be reflectively accessed to obtain it.

The following code shows how to set the option in the resource associated with an SDO data graph:

((XMLResource)eDataGraph.getDataGraphResource()).getDefaultSaveOptions()
.put(XMLResource.OPTION_SCHEMA_LOCATION_IMPLEMENTATION, Boolean.TRUE);

How do I register a dynamic package?

In order for EMF to locate a dynamic package that has been built up programmatically, it must be registered in a package registry. For example, the following code globally registers companyPackage:

EPackage.Registry.INSTANCE.put(companyPackage.getNsURI(), companyPackage);

Each resource set has its own local package registry, which is consulted before the global registry. To avoid collisions, you may prefer to register the dynamic package locally, instead of globally:

ResourceSet set = new ResourceSetImpl();
set.getPackageRegistry().put(companyPackage.getNsURI(), companyPackage);

Do I have to initialize and pre-register my dynamic packages?

No. The package needed to load a model instance will be automatically loaded from its serialized form, if available.

The simplest approach is to use an accessible URL as the package's namespace URI, and to make the package serialization available at that location (for example, via HTTP). If found, the package will be loaded with no additional effort.

If the package is available at a different physical location, whether public or on the local filesystem, you can serialize the model instance with the OPTION_SCHEMA_LOCATION to include that location, so that it can be found at load-time.

First, create a resource and add your package to it. For example:

ResourceSet set = new ResourceSetImpl();
Resource packageResource = set.createResource(URI.createURI("file:///c:/data/company.ecore"));
packageResource.getContents().add(companyPackage);
packageResource.save(null);

Then, use the OPTION_SCHEMA_LOCATION when you serialize your model instance:

Resource resource = set.createResource(URI.createURI("file:///c:/data/company.xml"));
Resource.getContents.add(company);
Map options = new HashMap();
options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
resource.save(options);

This adds an xsi:schemaLocation attribute to company.xml, associating the company package's namespace URI with the physical URI "company.ecore" (this relative URI is automatically computed, allowing the two files to be relocated, together).

How can I ensure that an xsi:schemaLocation is serialized for my packages?

The save option XMLResource.OPTION_SCHEMA_LOCATION must be used to indicate that you want to serialize schema location information. Even when this option is used, the schema location is serialized only if the ePackage.getNsURI() is different from ePackage.eResource().getURI() to avoid useless schema locations of the form xsi:schemaLocation="http://www.example.org/Xyz http://www.example.org/Xyz". For a generated package, the initializePackageContents contains this:

// Create resource
createResource(eNS_URI);

Adding a method like this:

@Override
protected Resource createResource(String uri)
{
  return super.createResource("http://www.example.org/Xyz.ecore");
}

is a good way to specify a physical location of the schema. It's best to specify an absolute URI as the location. EMF will serialize a relative location if there is a relative path from the URI of document being serialized to the schema location itself.

See also: Saving the xsi:schemaLocation into EMF XMI file - Eclipse Driven Rich Application Development Blog

Is there a built-in facility to check whether a given value is valid compared to the effective facets of its type?

To determine if a literal is valid with respect to a simple type, you can use either XSDSimpleTypeDefinition.isValidLiteral or XSDSimpleTypeDefinition.assess

I'm generating EMF models from xsd files. To generate relations between entities I use the following syntax, with the ecore:reference attribute on xsd:element...

<xsd:complexType name="Writer">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="books" type="xsd:anyURI" ecore:reference="lib:Book"/>
</xsd:sequence>
</xsd:complexType>

... but I have to generate this XSD schema and for this I need the schema that defines the ecore namespace. Where can I find this schema?

I don't think you actually need it in order to generate a schema like the one below.The XML Schema spec defines the wildcard for these "non-schema namespace attributes" like this:

<xs:anyAttribute namespace="##other" processContents="lax"/>

so no schema needs to exist for that namespace in order for the schema to be valid, you only need to ensure that the prefix is defined.

I have an element that comprises four sub-elements derived from type <xs:string>. How can I examine the contents of an <xs:complexType>? How could I programmatically determine its restrictions/enumerations/etc.?

Here's snippet of code that does some of the things you mention:

 void handle(XSDElementDeclaration xsdElementDeclaration)
  {
  XSDTypeDefinition xsdTypeDefinition =
  xsdElementDeclaration.getTypeDefinition();
  if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition)
  {
  XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
   (XSDSimpleTypeDefinition)xsdTypeDefinition;
  for (XSDFacet xsdFacet : xsdSimpleTypeDefinition.getFacets())
  {
   if (xsdFacet instanceof XSDEnumerationFacet)
   {
  for (Object enumerator : ((XSDEnumerationFacet)xsdFacet).getValue())
  {
  }
   }
   else if (xsdFacet instanceof XSDPatternFacet)
   {
   }
   // ...
  }
  }
  else
  {
  XSDComplexTypeDefinition xsdComplexTypeDefinition =
   (XSDComplexTypeDefinition)xsdTypeDefinition;
  switch (xsdComplexTypeDefinition.getContentTypeCategory().getValue())
  {
   case XSDContentTypeCategory.EMPTY:
   {
  break;
   }
   case XSDContentTypeCategory.SIMPLE:
   {
  XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
  (XSDSimpleTypeDefinition)xsdComplexTypeDefinition.getContentType();
  break;
   }
   case XSDContentTypeCategory.ELEMENT_ONLY:
   case XSDContentTypeCategory.MIXED:
   {
  XSDParticle xsdParticle =
  (XSDParticle)xsdComplexTypeDefinition.getContentType();
  XSDTerm xsdTerm = xsdParticle.getTerm();
  if (xsdTerm instanceof XSDModelGroup)
  {
  XSDModelGroup xsdModelGroup = (XSDModelGroup)xsdTerm;
  for (XSDParticle childXSDParticle : xsdModelGroup.getParticles())
  {
  }
  }
  else if (xsdTerm instanceof XSDElementDeclaration)
  {
  }
  else if (xsdTerm instanceof XSDWildcard)
  {
  }
  break;
   }
  }
  }
 }

How does setIncrementalUpdate() work?

You can use XSDSchema.setIncrementalUpdate(false) to turn off the expensive global updates and set it back to true, or call XSDSchema.update(), afterwards. Calling update() does not cause setIncrementalUpdate(true). Attached to this state is the warning that names will no longer be re-resolved and non-concrete relations will no longer be recomputed.If you aren't relying on these to drive your actions, it won't matter.

How can I load a XSDSchema from a simple Java String or from a DOM Tree?

Assuming you do something much like what's in XSDMainTest in org.eclipse.xsd.test, this should do the trick:

ResourceSet resourceSet = new ResourceSetImpl();
XSDResourceImpl xsdMainResource =
(XSDResourceImpl)resourceSet.createResource(URI.createURI("*.xsd"));
xsdMainResource.setURI(uri);
if (fromString)
{
 xsdMainResource.load(/* ByteArrayInputStream created from
 String */, resourceSet.getLoadOptions());
}
else
{
 XSDSchema xsdSchema =
 XSDPackage.eINSTANCE.createXSDSchema();
 xsdSdchema.setElement(/* your <schema> element */);
 xsdMainResource.getContents().add(xsdSchema);
}

How do I convert code that runs in an Eclipse environment to a standalone environment?

In an Eclipse environment the EPackage.Registry.INSTANCE is populated at startup time by the registrations of the models in the plugin.xml, e.g.,

<extension
point="org.eclipse.emf.ecore.generated_package">
<package
uri = "http://www.eclipse.org/xsd/2002/XSD"
class = "org.eclipse.xsd.XSDPackage" />
</extension>

But in a standalone environment, this doesn't happen, so you need to register each package explicitly.

If you have a package Xyz, accessing XyzPackage.eINSTANCE will create the package and register it in the registry.

So if you add the line XyzPackage.eINSTANCE.getEFactoryInstance() to your initialization code, the Xyz package will be properly registered.

How do I create a Map in EMF?

An EMap is basically a List of java.util.Map$Entry instances. Therefore to create a Map you need to first model your map entry by following these steps:

  1. Create an EClass with the name [Type1]To[Type2]Map where [Type1] represents the key's type and the [Type2] represents the value's type.
  2. Set the Instance Class Name property of the newly created EClass to java.util.Map$Entry.
  3. Create an EAttribute or EReference named "key" and set the EDataType or EClass for it.
  4. Create an EAttribute or EReference called "value" and set the EDataType or EClass for it.



Now, when you create an EReference somewhere that uses this map entry class as its EClass, the EMF code generator will detect this special case and generate a properly typed EMap getter/setter for you instead of a normal EList getter/setter. For example, in any EClass where you would like to have a map using the map entry type you defined above, do the following:

  1. Create an EReference with its EClass set to be the map-entry class you created above.
  2. Set the Containment property of your EReference to be true.
  3. Set the upper-bound of your EReference to be -1 (unbounded).



Generate the code and see your map work.

A similar approach works with XML Schema. You need to make the ecore:instanceClass of the <complexType> be java.util.Map$Entry and you need to ensure that there is a feature called "key" and a feature called "value". If the complex type does not contain an element or attribute with these names, an ecore:name annotation can be used to give an element or attribute an Ecore name different from the one that will be used to read and write the XML instance. Here's an example that assumes that the ecore prefix is defined as xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore":

 <xsd:complexType ecore:instanceClass="java.util.Map$Entry" name="StringToStringMapEntry">
   <xsd:attribute name="source" ecore:name="key" type="xsd:string"/>
   <xsd:attribute name="target" ecore:name="value" type="xsd:string"/>
 </xsd:complexType>

With help from Marco and Malai!

In Annotated Java, some care must be taken to have a Map being modeled equivalent to the above, i.e., an EReference to an (automatically generated) [Type1]To[Type2]MapEntry class:

/**
 * @model keyType="java.lang.String" valueType="java.lang.String" 
 */
Map<String, String> getScoScoMap();

Omitting the keyType and valueType annotations would result in the Map being modeled as an EAttribute, which would get serialized in XML as a hex value using Java serialization, unless you specialize the createFromString and convertToString methods for the map EDataType. In the above correct example, the type information in the annotations and Java type parameters is redundant; generally one would specify a reference to the exact EDataType rather than just repeating the Java type information, i.e., org.eclipse.emf.ecore.EString or org.eclipse.emf.ecore.xml.type.String. The desired result in the Ecore model looks like this:

    <eStructuralFeatures xsi:type="ecore:EReference" name="scoScoMap" upperBound="-1"
        eType="#//EStringToEStringMapEntry" containment="true" resolveProxies="false"/>

The above could also be specified using this approach of explicitly referring to the map entry EClass:

/**
 * @model mapType="org.eclipse.emf.ecore.EStringToStringMapEntry<org.eclipse.emf.ecore.EString, org.eclipse.emf.ecore.EString>"
 */
Map<String, String> getScoScoMap();

For completeness, another form is supported:

/**
 * @model kind="reference"  
 */
Map<String, String> getScoScoMapNoTypeAnnotations();

This results in:

<eStructuralFeatures xsi:type="ecore:EReference" name="scoScoMapNoTypeAnnotations">
    <eGenericType eClassifier="#//Map">
      <eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
      <eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    </eGenericType>
</eStructuralFeatures>

So, for best results, it is recommended to use keyType and valueType annotations or a mapType annotation for Maps in annotated Java code.

See also: http://tweakeclipse.blogspot.com/2009/02/create-maps-in-emf-other-way.html

What are Dynamic Templates?

Dynamic Templates allow overriding of the built-in EMF templates. They are called "dynamic" because the code generators are dynamically created from the templates. The built-in templates are considered "static" as the code generators were already generated when EMF shipped.

How do I use Dynamic Templates?

  1. Open the EMF Generator editor on a .genmodel file
  2. Right click in the editor and select Show Properties View
  3. Under Templates & Merge do the following:
    1. Change Dynamic Templates to true
    2. Optionally change Force Overwrite to true
    3. Set Template Directory to the new templates directory, e.g. <project name>/templates
  4. Now you can selectively override the built-in templates by copying the templates from plugins/org.eclipse.emf.codegen.ecore_<version>.jar/templates. Make sure you keep the same template folder structure.

How can I easily listen to changes for a specific object?

Given eObject of type EObject you can listen to its changes like this:

eObject.eAdapters().add
  (new AdapterImpl()
   {
     @Override
     public void notifyChanged(Notification msg)
     {
       // Look at notification to see what's changed.
     } 
   });

Any modeled object can be cast to EObject, even if it doesn't extend EObject in its generated interface. Keep in mind that you will often need to clean up these adapters, i.e., remove them from the eAdapters() list, when they are no longer needed, i.e., when the view that adds them is disposed.

How can I retrieve an object and all of the objects it references(regardless of the kind of reference) and save them as a single resource?

these methods show one way of doing that. this is, for instance, especially useful when creating a client-server architecture, where objects can be stored and edited on the client- as well as the server-side. The created resource can easily be serialized as a string, f.e. for transmission via XMLRPC.


  • [method for loading all referenced objects from the filesystem]

info:

  • this method takes a resource as param and locates all references for all objects in it.

public Resource collectAll(Resource resource){
	//get the resourceset
	ResourceSet resourceSet = resource.getResourceSet();
 
	//search for other resources containing referenced objects
	List<Resource> resources = new ArrayList<Resource>();
	resources.add(resource);
        for(Resource r : resources){
        	for(Iterator<EObject> j = r.getAllContents(); j.hasNext(); ){
        		for(Object object : j.next().eCrossReferences()){
        			EObject eObject = (EObject)object;
        			Resource otherResource = eObject.eResource();
        			if(otherResource != null && !resources.contains(otherResource)){
        				resources.add(otherResource);
        			}
        		}
        	}
        }
 
        //create resource to hold all objects
        //replace .lobj with your own model extension!
        File tempFile = new File("completeTree.lobj");
        Resource complete_resource = resourceSet.createResource(URI.createFileURI(tempFile.getAbsolutePath()));
 
        //move all objects into one resource
        Collection cl = new ArrayList();
        for(Resource resource2 : resources){
        	cl.addAll(resource2.getContents());
	}
        complete_resource.getContents().addAll(EcoreUtil.copyAll(cl));
 
        return complete_resource;
}


  • [method for loading all referenced objects from a datastore, using teneo]

info:

  • the below method(readReferences) does not work for featuremaps and map.
  • don't use this when selecting via a HibernateResource(or other types of db-resources supported by teneo), use queries to select your object.

usage:

//create session and transaction
Session session = getSession();
Transaction tx = session.getTransaction();
 
//Create a resourceset and a resource to hold the loaded objects
//always use an absolute path as uri, so relative paths can be built
//from it when moving objects around between resources
ResourceSet resourceSet = getResourceSet();
 
 
//replace .lobj with your own model extension!
File tempFile = new File("completeTree.lobj");
Resource rs = resourceSet.createResource(URI.createFileURI(tempFile.getAbsolutePath()));
 
tx.begin();
 
// query for object by ID
Query qry = session.createQuery("from "+eclassname+" where id='"+id+"'");
List list = qry.list();
 
tx.commit();
 
//fetch object and add it to the resource
EObject myObj = (EObject)list.get(0);
rs.getContents().add(myObj);
 
HashSet<EObject> preventCycles = new HashSet<EObject>();
ArrayList<EObject> rootList = new ArrayList<EObject>();
 
//collect all referenced & proxied objects	
readReferences(myObj, preventCycles, rootList);
 
//add the collected referenced objects to the resource
rs.getContents().addAll(rootList);

/**
* Recursively read all objects which are referenced from the passed eobject.
* The objects which do not have an econtainer are added to the rootList.
* The resulting rootList can be added to the contents of a resource.
*/
    private void readReferences(EObject eobject, HashSet<EObject> preventCycles, List<EObject> rootList) {
        if(preventCycles.contains(eobject)){ // been here get away
            return;
        }
        preventCycles.add(eobject);
        if(eobject.eContainer() != null){
            readReferences(eobject.eContainer(), preventCycles, rootList);
        }else{ // a root object
            rootList.add(eobject);
        }
        for(Object erefObj : eobject.eClass().getEAllReferences()){
            EReference eref = (EReference)erefObj;
            final Object value = eobject.eGet(eref);
            if (value == null) {
                continue;
            }
            if(value instanceof List){
                for(Object obj : (List<?>)value){
                    readReferences((EObject)obj, preventCycles, rootList);
                }
            }else{ // an eobject
                readReferences((EObject)value, preventCycles, rootList);
            }
        }
    }

How do I serialize a resource to a String instead of a file?

public static String resourceToString(Resource rs, String encoding){
        Map options = new HashMap();
        //change as needed according to the type of resource
        //you are using
	options.put(XMIResource.OPTION_ENCODING, "UTF-8");
 
	StringWriter sw = new StringWriter();
	URIConverter.WriteableOutputStream uws = new URIConverter.WriteableOutputStream(sw, encoding);
	try{
		rs.save(uws, options);
	}catch(IOException e){
		//TODO handle exception
	}
	String resourceString = sw.toString();
 
	return resourceString;
}

What EList implementation is generated When ?? - List of basic EList Implementations

I am documenting the most commonly generated list of EList that you may find in your EMF generated model code along with the condition under which it would be generated.

Types of Elist When will it be generated
EDataTypeEList If you define a Attribute with multiplicity more than 1
EDataTypeUniqueEList If you define a Attribute with multiplicity more than 1 and set UNIQUE = true
EObjectResolvingEList If you have an Ereference with multiplicity more than 1 defined with ResolveProxies = true
EObjectEList If you have an Ereference with multiplicity more than 1 defined
EObjectWithInverseResolvingEList If you have an Eopposite set for this Ereference with 0..* and resolveProxies = true
EObjectWithInverseEList If you have an Eopposite set for this Ereference with 0..* and resolveProxies = false
EObjectContainmentEList If your reference is a Containment

These are some of the frequently generated EList types, there are definitely more. Please do add them to this list if you find out more.

-Malai

What's the difference between the methods useIDs and useUUIDs in an XMLResourceImpl?

If useIDs returns true then the resource will maintain a map of extrinsic IDs, i.e., IDs that are not modeled directly as an EAttribute with isID true on the EObject, which we call intrinsic IDs. Extrinsic IDs are set via XMLResource.setID and fetched via XMLResource.getID. There are two-way maps to maintain them and these which are kept up-to-date if the object is removed from the resource. When useUUIDs is also true, it's assumed that the extrinsic IDs are universally unique (not just unique to the resource). In that case, a UUID is generated (EcoreUtil.generateUUID) for any object attached to the resource and this UUID is preserved when the object is moved between resources.

How can I use the EMF Ant tasks?

EMF provides a few Ant tasks that you can use in your build. The tasks are listed below, together with a short description and the CVS links to their readme file and example directory. Clicking on the name of a task opens the Javadoc of the class that implements it.

How can I split containment references across multiple resources to support cross resource containment?

Normally if you add a contained child to the contents of a resource, it will be removed from its container, i.e., EObject.eContainer() will become null. Since EMF 2.2, support was added so that if a containment reference is proxy resolving (EReference.isResolveProxies() is true), an object can be added to the contents of a resouLink titlerce without removing it from its container's proxy resolving reference. For this setting of the Ecore model to be respected by the generator, you must set the GenModel's "Containment Proxies" property to true.

The Ecore model itself has examples of this, i.e., EPackage.getEClassifiers() is proxy resolving so you can store an EClass is a separate resource from its containing EPackage. As a result, you can right click on an EClass and invoke "Control..." to specify a new resource in which to store the EClass. The "Control..." action is available in the generated editors for any object that is contained by a proxy resolving containment reference.

Is EMF thread-safe?

EMF can safely be used in multi-threaded environments; however, EMF does not, itself, ensure thread-safety in application model implementations. Data structures are unsynchronized, for performance and to avoid potential deadlock situations. The expectation is that a complete instance of the model (including resources and resource set, if present) should only be accessed by one thread at a time, and that the synchronization should be provided by the application at a higher level.

Since it is shared among multiple instances of a given application model, Ecore metadata is intended to be thread-safe for read-only access. However, there was a thread safety bug involving Ecore annotations, which is now fixed but will still affect older releases of EMF. Also, the demand initialization of SDO metadata is not thread-safe. See the following two questions for workarounds to these issues.

I get a NullPointerException from BasicEMap.entryForKey() while loading in a multi-threaded application. What's the problem?

This is a known bug involving access to Ecore metadata from multiple threads. The details map in an annotation on your model (probably an extended metadata annotation on a model originally defined as an XML Schema) is lazily initializing an index as a side-effect of being accessed for the first time. This is not thread-safe.

The problem was originally fixed in EMF 2.2 (bug 131151) and later backported to 2.0.6 and 2.1.3. If you are encountering this problem in an earlier release of EMF 2.0 or 2.1, you should move up to the latest release in the stream to pick up the fix.

Failing that, there is a workaround: you can simply ensure that you access the details map on each annotation in your model before the multiple loads start occuring. This can be done with a simple method like this:

public static void fixExtendedMetaData(EPackage ePackage)
{
  for (Iterator i = ePackage.eAllContents(); i.hasNext(); )
  {
    Object o = i.next();
    if (o instanceof EAnnotation)
    {
      ((EAnnotation)o).getDetails().get("");
    }
  }
}

If possible, you should add this directly into the generated init() method in the implementation class for each affected package. For example, for package foo, in FooPackageImpl:

/**
 * @generated NOT
 */
public static FooPackage init()
{
  ...

  // Initialize created meta-data
  theFooPackage.initializePackageContents();

  // Add this (for each package above, if there are package interdependencies)
  fixExtendedMetaData(theFooPackage);

  ...
  return theFooPackage;
}

If you don't have control over the generated model implementations yourself, you will simply need to obtain each ePackage (from the package registry, for instance) and invoke fixExtendedMetaData() on it at some point before the multi-threaded access begins.

I get a NullPointerException from EcoreUtil.getAdapter() while using SDO in a multi-threaded application. What's the problem?

This is a known limitation in EMF's implementation of SDO, which makes SDO model elements adapters on the corresponding Ecore model elements, so as to be easily retrievable. The attachment of the adapters is not thread-safe. So, when SDOUtil.adaptType() or SDOUtil.adaptProperty() is called to obtain a Type or Property for a given EClass or EStructuralFeature, it can run into trouble trying to get an adapter from the non-thread-safe adapter list.

This problem has not been fixed and probably won't be. However, there is a workaround: you can pre-initialize the SDO metadata before the multi-threaded access begins. Here is a method that does this:

public static void fixSDOMetaData(EPackage ePackage)
{
  for (Iterator i = ePackage.eAllContents(); i.hasNext(); )
  {
    Object o = i.next();
    if (o instanceof EClassifier)
    {
      SDOUtil.adaptType((EClassifier)o);
    }
    else if (o instanceof EStructuralFeature)
    {
      SDOUtil.adaptProperty((EStructuralFeature)o);
    }
  }
}

Like the workaround described in the previous answer, this should be done either from the generated init() method in the implementation class for each affected package or, failing that, at some other point before the multi-threaded access begins. Of course, if you are affected by both problems, you can fix them both in a single pass.

How do I preserve my property order, i. e. the order in the ecore model, in Property Sheet of the generated editor instead of default alphabetical ordering?

In your generated editor (MyEditor) find the method getPropertySheetPage() and replace it with the following piece of code:

	private class MyExtendedPropertySheetPage extends
			ExtendedPropertySheetPage {

		private class MyPropertySheetSorter extends PropertySheetSorter {

			@Override
			public void sort(IPropertySheetEntry[] entries) {
				// do nothing;
			}

		}

		public MyExtendedPropertySheetPage(
				AdapterFactoryEditingDomain editingDomain) {
			super(editingDomain);
			setSorter(new MyPropertySheetSorter());
		}

		@Override
		public void setSelectionToViewer(List<?> selection) {
			MyEditor.this.setSelectionToViewer(selection);
			MyEditor.this.setFocus();
		}

		@Override
		public void setActionBars(IActionBars actionBars) {
			super.setActionBars(actionBars);
			getActionBarContributor().shareGlobalActions(this, actionBars);
		}

		@Override
		protected void setSorter(PropertySheetSorter sorter) {
			if (!(sorter instanceof MyPropertySheetSorter))
				sorter = new MyPropertySheetSorter();

			super.setSorter(sorter);
		}

	}

	
	public IPropertySheetPage getPropertySheetPage() {
		if (propertySheetPage == null) {
			propertySheetPage = new MyExtendedPropertySheetPage(
					editingDomain);
			propertySheetPage
					.setPropertySourceProvider(new AdapterFactoryContentProvider(
							adapterFactory));
		}

		return propertySheetPage;
	}

Platform URI Scheme

In this blog entry, I've described the applications of URIs with the "platform" scheme and suggested a few ideas of how they can be used in an application. This knowledge is usually important while developing EMF applications due to the intensive use of URIs by the framework.

How do I map between an EMF Resource and an Eclipse IFile?

EMF uses platform resource URIs to access the workspace

 platform:/resource/project[/relative-path]

Be sure to encode the path when creating a URI for it, i.e., URI.createPlatformResourceURI(iFile.getPath().toString(), true). Use workspaceRoot.getFile(new Path(uri.toPlatformResourceString(true))) to convert it back to an IFile.


How do I update my Ecore and GenModel after the originating model has changed?

Once you have an existing *.genmodel resource, you can right click on it to bring up the popup, or open it the editor and from the Generator main menubar item, invoke "Reload..." to walk through the same wizard steps that were used to create the *.genmodel in the first place. The wizard will remember the choices made the last time and your GenModel's properties will be preserved during the reload processing.

How can I control which instances are available as choices when editing a property in the properties view?

You can modify the generated item provider from this

  /**
   * This adds a property descriptor for the Foo feature.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected void addFooPropertyDescriptor(Object object)
  {
    itemPropertyDescriptors.add
      (createItemPropertyDescriptor
        (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
         getResourceLocator(),
         getString("_UI_Abc_foo_feature"),
         getString("_UI_PropertyDescriptor_description", "_UI_Abc_foo_feature", "_UI_Abc_type"),
         XyzPackage.Literals.ABC__FOO,
         true,
         false,
         true,
         null,
         null,
         null));
  }

to this

  /**
   * This adds a property descriptor for the Foo feature.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   */
  protected void addFooPropertyDescriptor(Object object)
  {
    itemPropertyDescriptors.add
      (new ItemPropertyDescriptor
        (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
         getResourceLocator(),
         getString("_UI_Abc_foo_feature"),
         getString("_UI_PropertyDescriptor_description", "_UI_Abc_foo_feature", "_UI_Abc_type"),
         XyzPackage.Literals.ABC__FOO,
         true,
         false,
         true,
         null,
         null,
         null)
       {
        @Override
        public Collection<?> getChoiceOfValues(Object object)
        {
          List<Object> choiceOfValues = new ArrayList<Object>(super.getChoiceOfValues(object));
          // Filter the choices before returning them.
          return choiceOfValues;
        }
      });
  }

Downloading EMF

How do I install EMF 2.x (for Eclipse 3.x)?

Download the version of EMF, SDO and/or XSD that matches your installation of Eclipse. Generally, the version of Eclipse is one version greater than that of EMF; eg., EMF 2.3 is build against (and for) Eclipse 3.3. Exit Eclipse, then unzip into your Eclipse directory.

How do I install EMF or XSD 1.x for Eclipse 2.x?

Download the version of EMF and/or XSD that matches your installation of Eclipse. Exit Eclipse, then unzip into your Eclipse directory.

How do I get EMF, SDO or XSD source from CVS?

See Getting EMF Source.

Does EMF, SDO or XSD have a site that I can use with the Eclipse Update Manager?

Yes, as of June 21, 2004, there is an Update Manager site for EMF, SDO, and XSD.

This is only for the 2.x+ stream, not the 1.1.x stream.

IBM Internal can use:

The rest of the world can use:

If you're not familiar with Update Manager, surf to one of the above URLs and read the instructions there.

Please note, however:

  • You cannot upgrade from EMF 2.x to EMF 2.y, since you must also upgrade versions of Eclipse (3.x -> 3.y).
  • EMF's update site moved from /tools/emf/ to /modeling/emf, so old versions (2.0.x, 2.1.x) may not update properly anymore. Here are three workarounds:

Modeling Standards

What is Model Driven Architecture (MDA)?

MDA is an industry architecture proposed by the OMG that addresses full life cycle application development, data, and application integration standards that work with multiple middleware (CORBA, J2EE), languages, and interchange formats. MDA unifies some of the industry best practices in software architecture, modeling, metadata management, and software transformation technologies that allow a user to develop a modeling specification once and target multiple technology implementations by using precise transformations/mappings.

An example of the use of MDA is to use a UML model representation of a tool or application and to use this model to automate (some or all) of the Java interface, implementation, as well as any XML serialization for the modeled objects. Many of the recent OMG standards such as UML, MOF, and CWM were developed using MDA principles of using abstract models (these are also referred to as Platform Independent Models - PIM) which can be mapped to Platform Specific Models (PSM). Please note that 'platform independent' is a relative term!

or more information on MDA and related MDA specifications including UML, XMI, and MOF, please visit www.omg.org/mda.

Does EMF support OMG XMI?

EMF uses OMG XML Metadata Interchange (XMITM) 2.0 as the default XML serialization format for Ecore models and Ecore instances. The EMF framework allows the use of other serialization formats also. The XMI 2.0 document production rules are used because of more compact representation than XMI 1.2.

Can I create an EMF model using OMG XMI?

Yes. The XMI document that conforms to the EMF Ecore model can be directly edited using your favorite text or an XML editor. Alternately you can use a modeling tool that can produce the XMI document from a UML model. You can also use annotated Java interfaces to define your input model.

Can I create an EMF model using UMLTM modeling tools?

EMF models can be defined using UML modeling tools such as Rational Rose. You simply define a class model with the packages, attributes, references, data types, and operations. This class model can be imported into EMF for additional code generation. Since many Java developers are familiar with simple class modeling, this serves as a 'gentle introduction' to UML class modeling. In addition to UML class models, EMF models can be created by using annotated Java interfaces or by directly editing an XMI document using an XML editor. This approach is used to allow the benefits of model based code generation (one of the principles of the OMG Model Driven Architecture - MDA) to not just users familiar with UML, but also the larger community of developers using Java and XML.

What is the relationship of OMGTM MOFTM to the EMF Ecore model?

The OMG MOF 1.4 Model has influenced the design of the EMF Ecore model. The Ecore model evolved in parallel with the MOF 1.4 model. Implementation experience in integrating a number of tools led to an optimized implementation (focused on tool integration as opposed to the original MOF focus of metadata repositories) that uses a subset of the modeling concepts in MOF 1.4. For example, Ecore does not support 'first class' Associations. Associations are mapped to a pair of Ecore References. To minimize confusion, we have used the term 'Ecore' to refer to the object model in the EMF framework. We use the terms 'Ecore model' and 'EMF model' interchangeably in this FAQ, because the object model of the Eclipse EMF framework is the Ecore model.

The designers of EMF are participating in the OMG process to influence the design of MOF 2.0 and UML 2.0, which are still being defined.

What is the relationship of EMF to OMGTM MDATM?

One of the key goals of EMF is to use simple visual models to allow easy integration of Java and XML tools. To accomplish this you can use a UML class model as input to the EMF framework. This model is then used to drive Java interface and implementation generation for EMF instances. These Java interfaces define a consistent programming model for tools built using EMF. The same EMF model is also used to generate the XML serialization (XMI 2.0 format) for EMF instances. Essentially EMF supports the key MDA concept of using models as input to development and integration tools which produce multiple programming language (Java in the case of Eclipse EMF itself) or data interchange format (XML) representations. The code generation and XML serialization is 'driven' from the same model.

EMF supports OMG XMI 2.0 XML serialization format and the use of UML models for the analysis and design of EMF models.

What is the relationship of EMF to JMITM?

JMI (JavaTM Metadata Interface) is a mapping of the OMG MOF 1.4 to the Java language developed by the Java Community Process. The JMI spec and the Eclipse EMF model to Java mapping were developed in parallel and are not the same. The Eclipse EMF Java mappings have been optimized for in memory tool integration using Java and XML while JMI has been optimized for metadata repository usage scenarios. Eclipse EMF designers are actively involved in the ongoing development of MOF 2.0 and related mappings to XML and Java that are expected to proceed in the OMG and Java Community Process respectively.


Service Data Objects (SDO)

What are Service Data Objects (SDO)?

Service Data Objects (SDO), previously Web Data Objects (WDO), is designed to simplify and unify the way in which applications handle data. Using SDO, application programmers can uniformly access and manipulate data from heterogeneous data sources, including relational databases, XML data sources, Web services, and enterprise information systems. For more information about the goals and architecture of SDO, see the whitepaper Next-Generation Data Programming: Service Data Objects.

SDO is based on the concept of disconnected data graphs. A data graph is a collection of tree-structured or graph-structured data objects. Under the disconnected data graphs architecture, a client retrieves a data graph from a data source, mutates the data graph, and can then apply the data graph changes back to the data source. More...

What is the relationship between SDO & WDO?

Web Data Objects, or WDO, is the name of an early release of SDO shipped in IBM WebSphere Application Server 5.1 and IBM WebSphere Studio Application Developer 5.1.2. If you've spent any time with WebSphere Studio 5.1.2, you should already be somewhat familiar with SDO, although you're probably accustomed to seeing it denoted as WDO, for example in library names. WDO is now called SDO.

What is the relationship between EMF & SDO?

EMF and SDO both deal with data representation. The SDO implementation is based on EMF and is essentially a thin layer (facade) over EMF. You can get SDO from the Eclipse EMF Project Downloads page.

How do I serialize the model of an SDO data graph?

It may be convenient to serialize the package in the data graph, along with the instance data that requires it. To do so, the package's resource needs to be added to the resource set of the data graph.

For example:

EDataGraph companyGraph = SDOFactory.eINSTANCE.createEDataGraph();
ResourceSet set = companyGraph.getResourceSet();
Resource packageResource = set.createResource(URI.createURI(companyPackage.getNsURI()));
packageResource.getContents().add(companyPackage);

At load-time, the package will automatically be located with no further effort.

What is the relationship between SDO & JDO?

JDO is a Java Community Process (JCP) standard and stands for Java Data Objects. JDO looks at data programming in the Java environment and provides a common API to access data stored in various types of data sources. JDO preserves relationships between Java objects (graphs) and at the same time allows concurrent access to the data.

JDO's goal is similar to SDO's in that it wants to simplify and unify Java data programming. The main difference, however, is that JDO looks at the persistence issue only (the J2EE data tier or enterprise information system (EIS) tier), whereas SDO is more general and represents data that can flow between any J2EE tier, such as between a presentation and business tier.

SDO can be used in conjunction with JDO where JDO is a data source that SDO can access, applying the Data Transfer Object (DTO) design pattern.

What is the relationship between SDO & JAXB?

JAXB is a Java Community Process (JCP) standard and stands for Java API for XML Data Binding. As an XML binding framework for the Java language, JAXB performs marshalling/serializing (Java to XML) and unmarshalling/deserializing (XML to Java).

SDO defines a Java binding framework of its own and it goes one step further. While JAXB is only focused on a Java-to-XML binding, XML isn't the only kind of data SDO can bind to. SDO provides uniform access to data of various types through its Data Mediator Service (DMS). Examples of data types include relational databases (RDBs), entity Enterprise Java Beans (EJBs), or XML registries. SDO also offers both a static and dynamic API, whereas JAXB only provides a static binding.

What is the relationship between SDO & ADO .NET?

ADO .NET provides uniform data access between different tiers in the .NET framework.

ADO .NET and SDO share similar motivators for supporting XML and applications distributed on multiple tiers. Other than technical differences, one major difference between the two technologies is that ADO .NET is for the Microsoft .NET platform whereas SDO is for the Java (J2EE) platform.