HEAD PREVIOUS

Chapter 20
Tooling

This chapter attempts to answer the question: are tools available specifically for assisting developers in writing JMatter applications?

20.1  Reverse Engineering an Existing Schema

Jim Slack graciously contributed this code to the JMatter project. Here is a brief description of this tool from Jim:
I became very interested in JMatter after reading your book and playing around with the demos, but was disappointed in the lack of a way to use a legacy database. Therefore, I just finished writing a Java program that creates JMatter Java source files from a database. It seems to work fine, although using it is a bit tricky because it involves a few manual steps: run the program, update the schema, then run an SQL script.
So here are the instructions for how to use it.
  1. Make a backup copy of your database
  2. Create a new project as usual using the ant target new-project-ui
  3. Navigate (cd) to your newly-created project and edit the file resources/hibernate.properties to point to the database schema in question
  4. Invoke the ant target reveng-db which stands for Reverse Engineer Database. You have the option of specifying the name of the Java package that the generated source code will belong to with -Dreveng-pkgname=my.pkg.name (otherwise the code will default to org.jmatter.app)
  5. You can now invoke the schema-update target which will do two things:
    1. it will invoke the genhbm target that will generate the hibernate mapping files from the generated source code; and
    2. it will update the existing database schema to include version and createdOn columns and additional jmatter-specific tables
  6. At the present time, there's one other simple matter to address. JMatter does not deal well with null initial values for the version and createdOn columns. Step [4] above creates the sql script aptly named reveng_update_script.sql that you can manually invoke to rectify this issue. Here's an example of how I do this with postgreSQL:
psql databasename
$ i reveng_update_script
$ q
That's it. You're now ready to either run your JMatter application and to layer behavior on to your existing application.
Jim: Thank you very much!

20.2  IDEA Productivity Templates

I have developed a set of IntelliJ IDEA templates that constitutes a lightweight productivity solution for building JMatter apps. I can no longer write JMatter applications without them.
This tool is included with the JMatter distribution in jmatter/tools/IDEA. Follow the instructions in the README file to install the templates into the IDE. The tool thus far consists of one basic file template and a number of live templates that can significantly assist the development of JMatter applications within IDEA.

20.2.1  How it works

After creating a Java project, you can create basic JMatter model objects in a manner similar to the creation of new classes:
  1. Select a package in the side bar
  2. Right-click "New-ACO" (ACO stands for AbstractComplexEObject)
  3. Specify the class name
For example, for a class named Car, this basic template will be created:
package com.u2d.issuemgr;
import com.u2d.model.AbstractComplexEObject;
import com.u2d.model.Title;
import com.u2d.type.atom.StringEO;
import com.u2d.persist.Persist;
@Persist
public class Car extends AbstractComplexEObject
{
   private final StringEO name = new StringEO();
   public Car() {}
   public StringEO getName()
   {
      return name;
   }
   public Title title()
   {
      return name.title();
   }
}
In the IDEA project settings, enter the "Live Templates" section. You can inspect the various live templates defined for jmatter under the "jmatter" tree node.
Some examples include:
Key Description
fo expands to the metadata specification for fieldOrder
flat expands to the flattenIntoParent metadata specification
bprop will write the bound property getter and setter methods for you
tv expands to specify the tabViews metadata
plu will write the pluralName() method to override the plural name for a type

20.3  Ultraviolet and UMLC

Ultraviolet is a UML class editor. A copy is packaged with and integrated into JMatter. One way to launch it is by invoking the ultraviolet target from the framework build file:
$ cd jmatter
$ ant ultraviolet
See the accompanying screenshot of Ultraviolet in action.
figures/UltraViolet.jpg
Figure 20.1: Ultraviolet
With this editor, you can define the set of classes in your model and their interrelationships. One can specify associations, their cardinality, whether they're bidirectional. Much of JMatter's metadata can be specified directly via each class's property sheet: class name, plural name, icon, color code, fields, commands, as well as field and command metadata. One can also model inheritance.
Ultraviolet will generate a .umlc file for your model: a complete description of your model in the umlc language. Finally, the tool will automatically translate the model into a JMatter application. Technically, the only aspects of development that you do outside of Ultraviolet is the implementation of the commands.
This tool is inspiring and shows the power of domain-driven design and implementation. One can go from a simple idea to a model to a running application in minutes.
Both Ultraviolet and umlc were developed entirely by Ryan Ramage. This tool is open source and has its own home page: http://code.google.com/p/umlc/ and http://code.google.com/p/umlc/.

HEAD NEXT