Javier Paniza, leader of the OpenXava project, an open source project with more than 140.000 downloads and used around the world for creating Java Enterprise Applications, explains the core concepts of this lightweight model-driven framework. Enter Javier.

OpenXava is a framework for rapid development of business applications using Java. It is easy to learn and one can have an application up in no time. At the same time, OpenXava is extensible, customizable and the application code is structured in a very pure object oriented way, allowing you to develop arbitrarily complex applications.

The OpenXava approach for rapid development differs from those that use visual environments (like Visual Basic or Delphi) or scripting (like PHP). Instead, OpenXava uses a model-driven development approach, where the core of your application are Java classes that model your problem. This means you can stay productive while still maintaining a high level of encapsulation.

Though OpenXava takes a very pragmatic approach to development, it is based on the refinement of two well known ideas: The very popular methodology of Model-Driven Development (MDD) and the concept of Business Component. Ideas from MDD are borrowed in a rather lightweight way. The Business Component, however, is at the very heart of OpenXava.

Let’s look at these concepts in closer detail.

Lightweight Model-Driven Development

Basically, MDD states that only the model of an application needs to be developed, and the rest is automatically generated:

OpenXava process

In the context of MDD the model is the means of representing the data and the logic of the application. It can be either a graphical notation, such as UML, or a textual notation such as a Domain-Specific Language (DSL).

Unfortunately, using MDD is very complex. It requires a big investment of time, expertise, and tooling. Still the idea behind MDD is very good and hence OpenXava uses that idea in a simplified way.

OpenXava uses plain annotated Java classes for defining the model, and instead of generating code, all functionalities are generated dynamically at runtime:


Model definition Application generation
Classic MDD UML/DSL Code generation
OpenXava Simple Java classes Dynamically at runtime

The next graphic shows why we call OpenXava a Lightweight Model-Driven Framework:

Lightweight MDD

From just plain Java classes you obtain a full-fledged application. The next section about the Business Component concept will reveal some important details about the nature of these classes.

Business Component

A Business Component is a part of an application containing all the software artifacts related to some business concept (e.g., an invoice), it is merely a way of organizing software. The orthogonal way of developing software is the paradigm of MVC (Model-View-Controller) where the code is compartmentalized by data (Model), user interface (View), and logic (Controller).

This is the organization of software artifacts in an MVC application:

MVC OpenXava

All code units associated with the creation of the user interface, like JSP pages, JSF, Swing, JavaFX, etc., are kept closely together in the view layer, and likewise, for the model and controller layers. This contrasts with a business component architecture where the software artifacts are organized around business concepts, in this way:

MVC components

Here, all software artifacts contributing to the invoice concept, like user interface, database access, and business logic, are gathered in the same place.

Which paradigm to choose depends on your needs. If your data structures and business logic are likely to change frequently, then the Business Component approach is very useful since all changes can be made in the same place instead of being scattered over multiple files.

In OpenXava the main part to develop is the Business Component, which is defined as a simple annotated Java class, exemplified as following:

* A Java class for defining a business component.

@Entity  // Database
@Table(name="GSTFCT")  // Database
@View(members=  // User interface
   "year, number, date, paid;" +
   "customer, seller;" +
   "details;" +
   "amounts [ amountsSum, vatPercentage, vat ]"
public class Invoice {

   @Id  // Database
   @Column(length=4)  // Database
   @Max(9999)  // Validation
   @Required  // Validation
   @DefaultValueCalculator(  // Declarative business logic
   private int year;  // Data structure (1)

   @ManyToOne(fetch=FetchType.LAZY)  // Database
   @DescriptionsList     // User interface
   private Seller seller;  // Data structure

   public void applyDiscounts() {  // Programmatic business logic (2)


As you can see, everything to do with the concept of invoice is defined in a single place: the Invoice class. This class contains code dealing with persistence, data structures, business logic, user interface, validation, etc.
This is accomplished using the Java metadata facility, so-called annotations. These are the annotations used in this example:


Facet Metadata Implemented by
Database @Entity, @Table, @Id, @Column, @ManyToOne JPA
User interface @View, @DescriptionsList OpenXava
Validation @Max, @Required Bean Validation, OpenXava
Business logic @DefaultValueCalculator OpenXava

Thanks to metadata you can do most of the work in a declarative way and the dirty work is done for you by JPA (the Java standard for persistence), Bean Validation (the Java standard for validation) and OpenXava.
Moreover, the code you write is plain Java, like properties (year and seller, 1) for defining the data structure, and methods (applyDiscounts(), 2) for programmatic business logic.

All you need to write about invoice is Invoice.java. It is a Business Component. The magic of OpenXava is that it transforms this Business Component into a ready to use application.

Learn more
Maybe the idea of using Java as modeling language instead of UML or a DSL is not very orthodox from a MDE viewpoint, but it’s a very practical way of developing business applications. I invite you to have a look at some companies that use OpenXava and to see the demos that include a complete ERP that is currently a commercial product offered using the SaaS formula, or just visit the OpenXava site to download and try it by yourself: http://www.openxava.org/

Want to build better software faster?

Want to build better software faster?

Read about the latest trends on software modeling and low-code development

You have Successfully Subscribed!

Pin It on Pinterest

Share This