Developer Guide

Extension Points

Introduction

JEAF Generator is extensible. First of all there is the possibility to use your own templates as extension or replacement of the provided ones.

However, there might be cases where the standard templates are fine for you in general, but you would like to have a small modification. In such cases writing your own templates might not be the desired option.

For such cases JEAF Generator has build in so called Extension Points. Extension Points are hooks which are called by JEAF Generator during the code generation process.

Current version of JEAF Generator Extension API is 2

Extension Points

The following table describes the extension points as they are defined by version 2 of the JEAF Generator Extension Point API.

Extension Point Description Target Output / Applicable UML element types
AnnotationExtensionPoint Extension Point can be used to add custom annotations to generated Java code. It can be used for types (e.g. classes, enumerations) as well as

Example:
- Add custom deprecation annotation to a class or property
Java /
NamedElement
ClassExtensionPoint.xpt Extension point can be used to customize generated classes in the following ways:
- Implemented interfaces
- Add code before and after every class property from the UML model
- Add custom operation to class or builder class
- Add code before and after every builder property from the UML model

For further details please have a look on the documentation in the sources.
Java /
POJO , ServiceObject
JavaEnumerationExtensionPoint.xpt Extension point can be used to add literals to an enumeration that are not present in the UML model (aka “dynamic literals”). It’s also supported that an enumeration has literals that are defined in the UML model and some others are added dynamically.

Example:
- Literals are dynamically resolved based on model elements that are tagged with a custom stereo
Java /
JEAFEnumeration
OpenAPIEnumExtensionPoint.ext Extension point can be used to add dynamic literals to enumeration definitions inside an OpenAPI specification.

Example:
- Literals are dynamically resolved based on model elements that are tagged with a custom stereo
OpenAPI /
OpenAPIEnumeration
OpenAPISpecificationExtensionPoint.ext Extension point can be used to customize generated OpenAPI specifications

Example:
- Add additional properties to the info section of an OpenAPI specification
OpenAPI /
OpenAPI3Specification
ServiceInterfaceExtensionPoint.xpt Extension point can be used to customize generated service interfaces

Examples:
- Add custom annotations to service interface or operations
- Add custom default implementation for service operations
Java /
JEAFService

How to implement extension points


General considerations

Implementation of extension points is rather easy. All available extension points are located in resource directory jeafgenerator/api. For all extension points there is a default implementation that will be used when they are not overwritten.

These default implementation are also intended to be your starting point. You can find there her: JEAF Generator Extension API

In order to avoid version clashes the JEAF Generator API is versioned in a very simple way. There is a special function in JEAFGeneratorExtensionAPI.ext that declares by using a simple integer value which version of extension API is supported by your implementation.

Currently version 2 is the latest version of the extension API.


Steps to provide a custom implementation of extension points

Step Details  
1. It’s mandatory that you place your implementation of the extension points also in a resource directory with path jeafgenerator/api. Only then your templates etc. can be detected.

Same as with custom templates also your extension points need to be added to class path of JEAF Generator Maven Plugin
 
2. You always have to implement extension point JEAFGeneratorExtensionAPI.ext so that JEAF Generator knows which version of the extension API is supported:  
3. Now you can pick the extension point that you want to customize from the list above.

For that, copy complete file with the default implementation of the extension point to your resources. Make sure to only change the functions / templates that should be customized. All the others need to be preserved as they are.