Chapter 6. Customizing Code Generation Recipes

Table of Contents

1. Customizing Code Generation Configuration
2. Customizing Code Generation Templates
3. Extending the Code Generation Framework

The Spring DSL is a formalized set of EMF models and extensions that represents the building blocks of an Spring MVC or WebFlow application. The Spring DSL is the language that the application developer uses to specify the implementation of the desired application. The Spring DSL is appropriate for defining complete Spring applications, but it is also suitable for defining parts of a Spring application. As the developer defines their application using the Spring DSL, the meta-data backing the DSL serves as the input into the code generation engine. Ultimately, the meta-data needs to be converted into a concrete Spring application, and there are two aspects related to code generation: configuration and templates.

1. Customizing Code Generation Configuration

PROBLEM

When it comes to application development, the reality is that there is variation in development standards and styles. Many code generators advocate (force you to use) the standards and styles from the code generators authors. Skyway Software feels that development accelerators shouldn't force you to compromise on your own coding standards. A frequent generalization (and criticism) of code generation has been the inability for code generators to adapt to company and/or project standards.

SOLUTION

The Skyway Builder approach is to follow the principle of convention over configuration. Skyway Builder will generate according to a set of conventions, but the developer has the flexibility to reconfigure as needed. The default conventions are derived from large, enterprise-level Spring implementations and Spring best practices, and they’ve been vetted by Spring developers/architects and certified by SpringSource. If the defaults don’t conform to your project standards, then the Skyway Builder code generation engine for Spring can be customized to adapt to different standards.

HOW IT WORKS

Prior to Skyway Builder 6.3 the coding conventions could be customized by developing custom Eclipse plugins which extend the Skyway Builder code generator. Since version 6.3 all editions of Skyway Builder support project-level and artifact-level customization, which is simpler than developing EMF-based Eclipse plugins and provides an expanded set of customization options. Project-level and artifact-level customization is accomplished by using the Code Generation tab which is available on all Spring DSL editors.

Here’s a summary of the code generation customization options:

  1. Full code generation configuration – The target file name, package (if applicable), file path, and project for primary and secondary code generation artifacts can be configured.

  2. Project-level customization – The code generation can be customized at the project-level and applied to all application artifacts in the project. IDE-level customization (through Eclipse plugins) is still supported.

  3. Artifact-level customization - A specific application artifact can be customized on an artifact-by-artifact basis (as opposed to inheriting project-level customizations)

  4. Non-plugin based customization – Eclipse plugin and EMF development experience is not required. There’s no need to develop Eclipse plugins to customize the code generation, however, IDE-level customization is still supported.

  5. Customization for all editions – The code generation standards of all editions can be customized, including the Community Edition and all commercial editions.

  6. Enable/Disable code generation – The code generation of an individual artifact or type of artifact can be enabled or disabled. Each application artifact in the Spring DSL has a Code Generation tab for configuring the code generation.