Angel \”Java\” Lopez on Blog

September 28, 2008

Textual model for code generation in AjGenesis

Filed under: AjGenesis, Code Generation — ajlopez @ 4:41 pm

I was working adding a feature to my code generation project AjGenesis. The system manage a user-defined model, that can be loaded from .xml files. AjGenesis can process the model, completing it, invoking .NET objects, creating directories, files, and applying templates to create code and text artifacts.

But the model resides in memory: the deserialization from XML is only a choice of implementation. I’ve committed the new work in the source repository at Codeplex: now, every AjGenesis user can express his/her model in plain text

Now, a model can be expressed in simple text files. Let explore an example.

The simplest example I can imagine is a model for a Hello World application in AjGenesis. The model in XML is like:

<Project Company="ajlopez.com"> <Message>Hello, World</Message> </Project>

Now, you can express the same model in a text file:

Project Company = "ajlopez.com" Message = "Hello, World" End Project

If you need more message, you write in XML:

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

but in text, the same model could be expressed as:

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

You can load the model from the console line indicating a .txt or .xml file:

..\..\..\bin\AjGenesis.Console Model.txt ModuleVb.tpl HelloWorld.vb

..\..\..\bin\AjGenesis.Console Model.xml ModuleVb.tpl HelloWorld.vb

You can explore more examples at:

Hello world Examples

In a more realistic model, you can express entities in XML:

<?xml version="1.0" encoding="utf-8" ?> <!-- An Entity with Properties --> <Entities> <Entity Name="Customer"> <Description>A Customer</Description> <Properties> <Property Name="Id" Type="Id"/> <Property Name="Name" Type="Text"/> <Property Name="Address" Type="Text"/> </Properties> </Entity> <Entity Name="Supplier"> <Description>A Supplier</Description> <Properties> <Property Name="Id" Type="Id"/> <Property Name="Name" Type="Text"/> <Property Name="Address" Type="Text"/> </Properties> </Entity> </Entities>

or from text (it’s not the same model):

Entities Entity Customer Description = "Customer Entity" Properties Property Id Type="Id" Property Name Type="Text" Property Address Type="Text" End Properties End Entity Entity Supplier Description = "Supplier Entity" Properties Property Id Type="Id" Property Name Type="Text" Property Address Type="Text" End Properties End Entity End Entities

Once the model is loaded in memory, AjGenesis process it as usual, without regarding its original form, text or XML.

More about AjGenesis:

Posts about AjGenesis (English)
Posts sobre AjGenesis (Spanish)

Loosely related, but interesting:

Problems for Textual Model Notations

Angel “Java” Lopez
http://www.ajlopez.com/en

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 68 other followers