Models for Code Generation in AjGenesis

Today, I want to enumerate and short review the options you have to write a model in AjGenesis, my open source code generation project.

One of the basic ideas of AjGenesis is to have a free model as an starting point. It’s not a fixed one. What it means? It means that you can create and use your own model. A concrete example, if you want to model a "Hello, World”, you can start writing a simple model like this:

<Project Company="">
   <Message>Hello, World</Message>

If you want more info, extends it as in:

		<Message>Hello, World One</Message>
		<Message>Hello, World Two</Message>
		<Message>Hello, World Three</Message>

More info about this particular example in my post A Hello World Application in AjGenesis.

But XML is only the serialized version of the model. You can write it as text:

		Message = "Hello, World One"
		Message = "Hello, World Two"
		Message = "Hello, World Three"
	End Messages
End Project

More info about textual models at

Textual Model for Code Generation in AjGenesis

If you want to describe an Entity in your domain model, you can write something like this in free XML:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
			<Description>Last Name</Description>
			<Description>First Name</Description>

A more detailed description of use of such entity model at Application Generation using AjGenesis.

But if read XML hurts your eyes, you can use a in free text form (same as above example, but abbreviated)

Entity Employee
    Description = "Employee"
    SetName = "Employees"
        Property Id
        End Property
        Property Name
        End Property
    End Properties
End Entity


Not yet implemented, I’m going to add spreedsheets as models:

I wrote a short post about this idea: Another Model for AjGenesis

But sometimes, you want to use an existing source for model metadata. And with AjGenesis, you can! One of the most “popular” starting pseudo-models is the database. In my opinion, it’s not the ideal model, but, depending on the project and your needs, it could be a pragmatic solution (remember, AjGenesis and code generation is a pragmactic solution to some problems in software development, so, I don’t hesitate to adopt pragmatic sources, but be aware of their limitations).

I wrote about some examples at: Generating a Model From the Database Using AjGenesis and AjGenesis: Generating the Model from the Database

AjGenesis was born and designed to survive “fashion development”: it’s not oriented to a particular technology, platform, framework or language. It can generate everything that is a text artifact: Java, C#, VB.NET, PHP, config files, xml, database scripts, even COBOL. You can write tasks and templates to do what you want to generate, at any moment. You can start small, and grow up, adding more abstractions and tricks. But tasks and templates are topics for another blog. Said that, you can use as a model the compiled domain. There is a description of an example written by Dario Quintana using .NET at:

AjGenesis: Generating the model from assemblies

In Java world, it was used to generate code from annotations in code (remember XDocLet). Or from configuration files: hbm2java tools in Hibernate. NHibernate, the most popular .NET open source Object Relational Mapping library, lacks such tools. As in Java, AjGenesis can use meta tags embedded in .hbm mapping files, to generate code. See:

Generating Code with AjGenesis using NHibernate Hbm Mapping Files

(I have a more complete example in trunk, that generates a complete solution using ASP.NET and NHibernate).

You can download the project from the source code trunk at:

Next topics: tasks, templates, abstractions vs technicalities, in-memory models, model to model transformations, completing the model, decisions, expert systems and artificial intelligence applied to code generation and AjGenesis.

Stay tuned!

Angel "Java" Lopez

7 thoughts on “Models for Code Generation in AjGenesis

  1. Pingback: Code generation with AjGenesis in a Real Project « Angel “Java” Lopez on Blog

  2. Pingback: AjGenesis and Language Workbench Competition 2011 « Angel “Java” Lopez on Blog

  3. Pingback: Code Generation and Artificial Intelligence « Angel “Java” Lopez on Blog

  4. Pingback: Generación de Código e Inteligencia Artificial - Angel "Java" Lopez

  5. Pingback: Models in Excel | Modeling Languages

  6. Pingback: AjGenesis: Basis of its Implementation « Angel “Java” Lopez on Blog

  7. Pingback: Code Generation and Artificial Intelligence | Angel ”Java” Lopez on Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s