Welcome to jMDA

To generate software automatically has been a strong ambition since the early days of software development.

jMDA is a new approach in this area. It streamlines proven, widely known and accepted open source technologies into a most comprehensible and easy to use set of Java libraries that are extremely powerful and flexible at the same time. The main purpose of jMDA is

  • to leverage a comprehensible and easy to use modelling environment,

  • to provide convenient and complete access to modelling information and

  • to make available easy to use software generator facilities.

The introduction will briefly explain the main drivers behind this project, the jMDA book provides more detailed information about the most important concepts and the open source software is available here.

sample: create a source code generator with 4 lines of code

This quickstart example shows how easy it is to work with the jmda.gen generator framework and how much fun it is to configure your own Java source code generator. It will demonstrate some basic techniques by creating a generator for the famous "Hello World" Java program.

Let's start with the basic definition of a Java class generator:


  ClassGenerator generator = new DefaultClassGenerator();
  System.out.println(generator.generate());

These two lines produce the following output:


  class DEFAULT_TYPE_NAME
  {
  }

This might not be too impressive, however we already have a syntactically correct class that indeed does not do anything meaningful but it perfectly compiles already! Let's continue by giving a name to our generated class:


  ClassGenerator generator = new DefaultClassGenerator();
  generator.setClassName("HelloWorld");
  System.out.println(generator.generate());


The new output looks as expected:


  class HelloWorld
  {
  }


We go on by defining a main method for the generated class:


  ClassGenerator generator = new DefaultClassGenerator();
  generator.setClassName("HelloWorld");
  generator.setMainMethod("System.out.println(\"hello jmda.gen\");");
  System.out.println(generator.generate());


And now our generator produces this:


  class HelloWorld
  {
    public static void main(String[] args)
    {
      System.out.println("hello jmda.gen");
    }
  }


So, here we are, a Java code generator producing a working Java source file with four lines of code. OK, the example can hardly be more simplistic but it shows a few general concepts for the work with the jmda.gen framework, for example:
  • rely on reasonable default behaviour
  • create generators with configuration by exception
I'd be happy if you find this stuff interesting enough to try it out yourself. If so, I'd be even more happy about your feedback. You will find out quickly how easy it is to specify a package, modify the visibility or add further methods to the generated class. You can download all you need in a single file from here.

No comments:

Post a Comment