The Talon Manual

Skip to end of metadata
Go to start of metadata

In This Section

Introduction: The Listener API

Code generation for ADM is run by using com.neeve.tools.AdmCodeGenerator class. It is possible to supply listener to AdmCodeGenerator instance to subscribe to events that are fired at certain points in code generation run. The events are given in AdmCodeGenerator.CodeGenerateEventType enum which is defined as shown below.

Event Types

Event listener can be given to AdmCodeGenerator instance directly through CODEGEN_EVENT_LISTENERS parameter. Maven plugin exposes it through codegenListenerClassName configuration parameter. This parameter accepts full qualified name of the class that implements listener interface.Listener interface is defined in AdmCodeGenerator.CodegenListener as shown below. So, while AdmCodeGenerator can accept multiple listeners, maven plugin accepts only one class name and will create only one instance of that listener class per execution. The class shpuld be in project's build classpath (either in project being built or in one of its dependencies).

Listener Interface

The event data is passed in AdmCodeGenerator.CodeGenerateEvent class instance. the interesting methods from event objects are given below.

Event Object Important Methods

 

Example Usage: Running Additional Model Validations

Developers may tap into listener mechanism to perform additional model validations as given in example below. The example demonstrates how to use the listener mechanism to enforce globally unique field ids (meaning both the model for which code is generated and all its imports recursively).

Pseudocode Demonstrating External Validation

 In pom.xml we may use this listener as follows:

Sample usage in pom.xml

 

 

  • No labels