Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EMF/Recipes"

< EMF
m
Line 3: Line 3:
 
== Code generation recipes ==
 
== Code generation recipes ==
  
=== Recipe: Generating EMF-free API===
+
=== Recipe: Generating Pure API With No Visible EMF Dependencies===
  
 
'''Problem'''
 
'''Problem'''
  
You want to generate code from an EMF model but you don't want any references to EMF types in your API.
+
You want to generate code for an EMF model but you don't want any references to EMF types in your API or anything else that reveals that the API is implemented by EMF.
  
 
'''Solution'''
 
'''Solution'''
Line 13: Line 13:
 
In your genmodel:
 
In your genmodel:
  
* set the 'Suppress EMF Types' property to 'true' and standard Java types will be used rather than EMF types for all operations;
+
* Set the 'Suppress EMF Types' property to 'true'; standard Java types will be used rather than EMF types for all accessors and operations. Features of type 'EObject' will be surfaced as 'java.lang.Object' instead.  If the model includes feature maps, you will need to use the properties 'Feature Map Wrapper Class', 'Feature Map Wrapper Interface', and 'Feature Map Wrapper Internal Interface' to provide an alternative API. You can look as the support for SDO's Sequence API as the example.
* clear or set the value of the 'Root Extends Interface' generator model property. If cleared the generated domain API will not depend on anything, or it can be set to an interface of your choosing
+
* Clear or set the value of the 'Root Extends Interface' generator model property. If cleared, the generated domain API will not depend on anything, or it can be set to an interface of your choosing so that root interfaces will extend this specified interface.
* the 'Root Extends Class' and 'Root Implements Interface' properties allow you to control the generation of the implementation. But if you clear the first or set it so the generated implementation is not a subclass of EObjectImpl the generated code will be invalid as it will have unresolved references to inherited methods that will not be available, such as eGet, eSet, eUnset, eIsSet and eIsProxy. Generating an implementation that is EMF-free is not possible with the default templates.
+
* Set 'Suppress EMF Metadata' to 'true' so that only a package implementation class is generated, but no interface, and so that the generated factory interface will not extend EFactory and will have an INSTANCE instead of an eINSTANCE field.  Alternatively, set the generator package's 'Metadata' property to redirect the package and factory interfaces to a different Java subpackage.
 +
* Set the 'Suppress EMF Model Tags' property to 'false' to eliminate the generation of the @model tags in the Javadoc.
 +
* Set the 'Root Extends Class' and 'Root Implements Interface' properties to control the generation of the implementation, but if you clear the first one or set it so the generated implementation is not a subclass of EObjectImpl, the generated code will be invalid as it will have unresolved references to inherited methods that will not be available, e.g., eGet, eSet, eUnset, eIsSet and eIsProxy. Generating an implementation that is pure Java is not possible with the default templates but can be achieved with dynamic templates.
  
 
'''Related recipes'''
 
'''Related recipes'''

Revision as of 09:14, 12 August 2007

This topic gathers recipe-style solutions for common needs developers using EMF have.

Code generation recipes

Recipe: Generating Pure API With No Visible EMF Dependencies

Problem

You want to generate code for an EMF model but you don't want any references to EMF types in your API or anything else that reveals that the API is implemented by EMF.

Solution

In your genmodel:

  • Set the 'Suppress EMF Types' property to 'true'; standard Java types will be used rather than EMF types for all accessors and operations. Features of type 'EObject' will be surfaced as 'java.lang.Object' instead. If the model includes feature maps, you will need to use the properties 'Feature Map Wrapper Class', 'Feature Map Wrapper Interface', and 'Feature Map Wrapper Internal Interface' to provide an alternative API. You can look as the support for SDO's Sequence API as the example.
  • Clear or set the value of the 'Root Extends Interface' generator model property. If cleared, the generated domain API will not depend on anything, or it can be set to an interface of your choosing so that root interfaces will extend this specified interface.
  • Set 'Suppress EMF Metadata' to 'true' so that only a package implementation class is generated, but no interface, and so that the generated factory interface will not extend EFactory and will have an INSTANCE instead of an eINSTANCE field. Alternatively, set the generator package's 'Metadata' property to redirect the package and factory interfaces to a different Java subpackage.
  • Set the 'Suppress EMF Model Tags' property to 'false' to eliminate the generation of the @model tags in the Javadoc.
  • Set the 'Root Extends Class' and 'Root Implements Interface' properties to control the generation of the implementation, but if you clear the first one or set it so the generated implementation is not a subclass of EObjectImpl, the generated code will be invalid as it will have unresolved references to inherited methods that will not be available, e.g., eGet, eSet, eUnset, eIsSet and eIsProxy. Generating an implementation that is pure Java is not possible with the default templates but can be achieved with dynamic templates.

Related recipes

None so far.

References



Back to the top