Applying Code Generation Approach in Fabrique
So it's time to have a more detailed look at Fabrique's design and major component parts to see how they solve these issues. Refer to the following diagram:
Visual Fabrique – an IDE for creating, editing, and refactoring the Fabrique Application Model. Visual Fabrique is based on IntelliJ IDEA™. In addition to IDEA's intelligent capabilities for Java code editing, Fabrique provides visual editors for model languages. Of course, it fully supports specific its own languages with code search across the project, code completion, error highlighting. etc.
Fabrique Application Model – a high-level platform-independent description of a Fabrique Application. It's described with various declarative as well as imperative languages (which we will consider further later on).
Fabrique Compiler – a code generator. It generates all necessary Java source code ready for compiling into a deployable application, and runs the Java compiler for those sources. The generator always generates two kinds of source code:
- Platform-independent code which is safe to use from the application model
- Platform-dependent code which extends the above, and is invisible to the application developer
Fabrique Core Frameworks – contains runtime code which drives the built and deployed Fabrique application. It contains the following parts:
- Web Framework – a collection of ready-for-use web controls and an event system
- Business Objects Framework– a set of technologies for transaction and persistence management as well as the application’s business logic
So the two extra players mentioned previously are:
- Platform-independent API, generated irrespective of any platform so that hand-written code may depend on that API rather than on something that changes when we change a code generator (and the respective platform)
- Visual Fabrique, which handles all refactoring issues including changes affecting both hand-written code and its generated counterpart
Fabrique Application Model
The point of application model is that it’s a platform-independent description of an application. A Fabrique application model can consist of:
- FabScript – a simple Java-based language for describing business logic. FabScript is designed so that scripts are compact for easy inlining to other parts of the model.
- Java code – can also be used for describing business logic, but cannot be inlined to the model
- FabQL - a query language for Business Object Model. FabQL is an extension of EJB QL with some improvements that make it simpler in use in Fabrique
- Business Object Model - describes persistent objects, their attributes, methods and relationships. Business Object Model is described in an XML-based language where the following languages are inlined:
- FabScript is used for describing bodies of methods
- FabQL is used for defining finder methods for business objects.
- Web Page Model – describes the application’s web pages, their structure and reactions to events. FabScript can be inlined in many places on the page.
- Business Service Model – describes business logic, which is exposed via a global access point.
It's the job of Fabrique Compiler to generate all of the above into compliable Java code, to run the Java compiler against that generated code, and to prepare a deployable application.
Active Libraries
Needless to say, extensibility of an application is an important thing. In Fabrique there’s a notion of Active Library, which is the way to contribute to Fabrique. We can contribute lots of things: from the runtime appearance of controls to a new editor for Visual Fabrique. An independent vendor can, for example, provide a new language for defining whatever it wants, a visual editor for that language, and a code generator to make it sensible at runtime.
Separation of Development Aspects
So, the whole point of Fabrique is clear separation of several development aspects:
- High-level description of an application (Fabrique Model). You don’t have to decide on a platform before development, and you are free to change platforms later.
- Visual editing for Fabrique Model (with Visual Fabrique). Since Fabrique Model is a high-level description, the editors have the ability to be more intelligent because they know about much more than just plain Java classes.
- A pluggable code generator that generates target platform-dependent implementations of things described in Fabrique Model (Fabrique Compiler). We only need to select and easy configure the code generator for the platform we want our application to run on.
- A runtime library (Core Frameworks) that handles all difficult, routine (and boring!) tasks such as web controls rendering and behavior, transaction management, and so forth.
The rest of this article is devoted to an overview of Fabrique’s Business Object Framework (BOF). With this example I will try to show benefits of this separation of development aspects as well as the code generation approach in general.