Archive for the 'Programming' Category

Genesis Studio: an IDE for AjGenesis

Thanks to the excellent work of  Jonathan Cisneros, now we have an IDE to use with AjGenesis. Developed with CSharp2, it edits projects, model and template files, even with syntax color!!.

It’s an application, ready to use, without rough edges. It will evolve: Jonathan has some ideas for extensions, to complete its program.

You can download Genesis Studio from the group Code Generation page:

Code Generation Google Groups

or you can try this link. In that group there are many files to download, with new templates, models and examples. Genesis Studio is at:

It comes with source code, in a Visual Studio 2005 solution. It’s compilation is easy, it have all the required libraries:

With this application we can edit a project directory, its entities, model, technologies. Remeber, AjGenesis has a free model that you can define for each project. Genesis Studio can read and edit template ant task files.

Some options:

When you choose a project directory, a project explorer appears, showing folders and content:

XML, templates and task files have sintax color support:

 

My thanks to Jonathan Cisneros, for this useful application.

Code generation is technique that has power uses. In an technology change environment, with complex application, it is important to delegate the menial and repetitive tasks to the software itself.

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

Application Generation using AjGenesis

These days, I wrote new examples for my open source project AjGenesis

http://www.ajlopez.com/ajgenesis
http://www.codeplex.com/ajgenesis

Using AjGenesis, we can produce, starting from our own model, applications for ASP.NET 1.x/2.x, JSP, using SQL Server in .NET, with ADO.NET or NHibernate, or MySql with Java and Hibernate. The sample generated applications use a layered architecture (but remember: these are sample applications, you can write and use your own models, tasks, and templates). Other option: it can generate layers following ideas from Eric Evans’ Domain-Driven Design.

I’m still writing those examples, but now, you can download the current version from

AjGenesisExamples3New.zip

The examples require the use of AjGenesis last release:

AjGenesis Version 0.4.3

but you can try the current version under development:

AjGenesis Version 0.5

In this post, I want to comment how AjGenesis works and some of its inner structure, using one of those examples. Although I will concentrate in producing VB.NET code, you’ll find that the example is able to produce C Sharp and Java/JSP solutions, as well.

First, let’s review first some points about the project. The big picture:

AjGenesis Version 0.4.3 is written using VB.NET V1.x, but version 0.5 is the current version under development, and it was rebuilt using .NET 2.0. The project is open source, and has a BSD-like license, that allows to use it in any project what you want: you only need to comply with the license (in short, put some reference to the original project). It is possible to be used like a library, invoked from your own project, or it is possible to be invoked from command line, or even it can be used from using NAnt (this tool gives you a better organization of the code generation tasks).

There are several samples in the page of the project (inside the project zip source file and in additional files). They generate code from a model, invoking tasks and processing templates. The samples generate code PHP, Java, JSP, VB.NET, C#, ASP.NET, and even scripts of procedure and data base stored. I want to emphasize two points:

- The model to use is totally definible by you. It’s a free model, it’s not a fixed one. You can model what you want to model.

- The tasks and templates to apply are totally programmable and controlable. You are in charge. 

That’s make a difference from other generators. We can create our own model, and its own templates and tasks, to generate any text artifacts. Other systems start from the data base, and they only generate a group of predefined text files (as POJOs, plain old java objects, or DAOs, Data Objects Access). But with AjGenesis you can generate any text file you need.

In order to better understandind the free model concept, read a previous post:

Generating Code Hello World with AjGenesis

In that post, the initial steps are described, using a free model, totally oriented to the domain to represent: a typical Hello World application, implemented in different technologies.

Creating an application

Let’s do something more complete in this post. Suppose we need to create a simple solution simple, with two tables, in a MS SQL Server databse, source code in VB.NET 2,0, web interface, layer of services, layer of data, business components and business entities a la Microsoft. We want to generate the solution, the projects, scripts for database creation, and stored procedures. This example is included in the examples AjGenesisExamples3New.zip. First step: to write the model.

The project

In a directory of projects of the examples that accompany this article, there is a Projects/AjFirstExample directory.

In that directory it is the Project.xml file that contains the model.

<Project>
    <Name>AjFirstExample</Name>
    <Description>First Example
    using AjGenesis</Description>
    <Prefix>AjFE</Prefix>
    <Domain>com.ajlopez</Domain>
    <CompanyName>ajlopez</CompanyName>
    <Model>
        <Entities>
            <Entity
            Source="Entities/Customer.xml"/>
            <Entity
            Source="Entities/Supplier.xml"/>
        </Entities>
    </Model>
</Project>

Remember: the model is free. Here we define the templates that we are going to use. The model contains two simple entities: customers and suppliers.

The entities

The XML file is not terribly long: AjGenesis allows that any node of the model is specified apart in a file. This is a criterion that I have used to define how the model is written: the resulting XML does not have to hurt at sight, must be understandable and abarcable in a reading.

In the Project.xml, that feature is used in the case of the entities, with the Source attribute. Let us examine an entity, written in Entities/Customer.xml:

<Entity>
    <Name>Customer</Name>
    <Description>Customer Entity</Description>
    <SetName>Customers</SetName>
    <Descriptor>Customer</Descriptor>
    <SetDescriptor>Customers</SetDescriptor>
    <SqlTable>customers</SqlTable> 

    <Properties> 

        <Property>
            <Name>Id</Name>
            <Type>Id</Type>
        </Property> 

        <Property>
            <Name>Name</Name>
            <Type>Text</Type>
            <SqlType>varchar(200)</SqlType>
        </Property> 

        <Property>
            <Name>Address</Name>
            <Type>Text</Type>
            <SqlType>text</SqlType>
        </Property> 

        <Property>
            <Name>Notes</Name>
            <Type>Text</Type>
            <SqlType>text</SqlType>
        </Property> 

    </Properties>
</Entity> 

There are attributes of the entities, like its name and description, in plural and singular. This data serve to name them in the resulting pages, or within the code. The properties are the fields to maintain in each entity..

Aside from the entities, in another directory, Technologies, specifies the dependent model of the technology, like VbNet2:

The templates

The templates to use are at the Templates/VbNet2 directory:

They are the templates for generation of code VB.Net 2.0. Also we will find groups for C# 1/2, Vb.NET 1,2, Java (although I’m thinking to drop templates for .NET 1.x: I don’t see any reason to maintain these). There are templates to use Nhibernate, Hibernate, JSP, MySql, and concepts of Domain-Driven Design, too. Let’s review a template as an example, the one that generates the organization in Visual BASIC, EntityVb.tpl:

<# 

message "Generating Entity ${Entity.Name}" 

include    "Templates/VbNet2/VbFunctions.tpl" 

include    "Templates/VbNet2/Prologue.tpl"
#> 

'
'    Project ${Project.Name}
'        ${Project.Description}
'    Entity    ${Entity.Name}
'        ${Entity.Description}
'    
'

Public Class ${Entity.Name} 

'    Private Fields

<#
for each Property in Entity.Properties
    message    "Procesando Campo ${Property.Name}"
#>
    Private m${Property.Name} as ${VbType(Property)}
<#
end for
#> 

'    Default Constructor

    Public Sub New()
    End Sub 

'    Public Properties

<#
for each Property in Entity.Properties
    message    "Procesando Propiedad ${Property.Name}"
#>
    Public Property ${Property.Name}() as ${VbType(Property)}
        Get
            Return m${Property.Name}
        End Get
        Set(ByVal Value As ${VbType(Property)})
            m${Property.Name} = Value
        End Set
    End Property
<#
end for
#> 

End Class 

Like before, control structures are used. XML is the serialized format of the model. During the code generation process, the model is loaded in memory, ready to be accesible via dynamic variables.

The steps

We have more files to generate: from the pages ASPX, and their associated code, the projects of facade on watch, organizations, access to data, the file of solution, and more. In order to automate this generation, the example has several files of tasks, in the Tasks directory, where the steps are described to execute. There are two great tasks: the steps to execute independently of the chosen technology, like completing the model, reviewing it, and the employees of the technology, like generating such file JSP or ASPX, depending on if we want Java or .NET.

The task of completing the model is in charge of Tasks\BuildProject.ajg, that begins with:

'
' Build Project
'    Complete the Project Data
'    Project must be loaded in global variable Project
'

PrintLine "Completing Project ${Project.Name}" 

include "Templates/EntityFunctions.tpl"
include "Templates/Utilities.tpl" 

if not Project.Title then
    Project.Title = Project.Name
end if 

if not Project.Version then
    Project.Version = "1.0.*"
end if 

if not Project.SystemName then
    Project.SystemName = Project.Name
end if 

The template includes some auxiliary functions, and then, it begins to complete the model that resides in the Project variable. For example: if the project lacks Project.Title the program set Project.Name as Project.Title. The program continues:

for each Entity in Project.Model.Entities
    PrintLine "Entity " + Entity.Name 

    for each Property in Entity.Properties
        PrintLine "Property " & Property.Name
        if Property.Type="Id" and not Property.SqlType then
            Property.SqlType="int"
        end if
        if Property.SqlType and not Property.SqlColumn then
            Property.SqlColumn = Property.Name
        end if
        if Property.Type="Id" and not Entity.IdProperty then
            Entity.IdProperty = Property
        end if
        if Property.Reference then
...

After that process, the technology tasks are executed. The example use Tasks\BuildVbNet2.ajg, here a fragment:

<# 

include "Templates/Utilities.tpl"
include "Templates/VbNet2/UtilitiesVb.tpl" 

message "Creating Directories..." 

FileManager.CreateDirectory(Project.BuildDir)
FileManager.CreateDirectory("${Project.BuildDir}/Sql")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Entities")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Entities/My Project")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Data")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Data/My Project")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Services")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Services/My Project")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Business")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.Business/My Project")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.WebClient")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.WebClient/App_Themes")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.WebClient/App_Themes/Default")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.WebClient/Admin")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.WebClient/Controls")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.WebClient/MasterPages")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.WebServices")
FileManager.CreateDirectory("${Project.BuildDir}/Src/${Project.Name}.RemoteServices") 

message "Defining Solution and Projects..." 

...

In this fragment, the directories necessary are created to lodge the solution. The name of the directory is extracted of the model from Project.BuildDir. Note that ${ } in a string is used to expand the inside expression into the string value.

Technology Model

Under the directory Project\AjFirstExample\Technologies they are some models that describes the technology parameters to use:

 

Let’s examine VbNet2.xml:

<Technology>
    <Programming>
        <Dialect>VbNet2</Dialect>
    </Programming>
    <Database>
        <Dialect>MsSql</Dialect>
        <Name>AjFirstExample</Name>
        <Username>sa</Username>
        <Prefix>ajfe_</Prefix>
        <Host>(local)</Host>
    </Database>
</Technology>

These data is used during the template generation phase. It indicates the language, and the database to use.

Generating the solution

We could send the tasks from the command line, but we have a .build file for Nant, one for each technology to generate. We execute the tasks build, buildsql, and deploysql of AjFirstExampleVbNet2.build with the command line:

nant -buildfile:AjFirstExampleVbNet2.build build buildsql

(You must adjust the line

<property name=”ajgenesis.dir” value=”…./AjGenesis-0.5″/>

to reflect your AjGenesis installation directory)

Note the following lines in the build file:

    <target name="loadtasks" description="loads AjGenesis tasks">
        <loadtasks assembly="${nanttasks.dir}/AjGenesis.NAnt.dll" />
    </target> 

    <target name="init" depends="loadtasks" description="init the AjGenesis model, create build directory">
        <mkdir dir="${build.dir}"/>
        <loadmodel model="${project.dir}/Project.xml"/>
        <loadmodel model="${project.dir}/Technologies/${technology}.xml"/>
        <executetask task="${tasks.dir}/BuildProject.ajg"/>
        <executetask task="${tasks.dir}/BuildTechnology.ajg"/>
    </target> 

These tasks load an AjGenesis NAnt tasks, load the models, and execute the tasks.

In the Build/AjFirstExample/VbNet2/Sql directory they are left scripts of creation of the base and stored procedures. And in the directory Src brother, surprise! We’ll have the generated solution:

There were generated several projects, into a solution. We can load the solution into the Visual Studio 2005:

Using another NAnt file, AjFirstExampleCSharp2.build, we can generate the same solution in CSharp:

You will find other projects and examples of .build files, that generate solutions using NHibernate, Hibernate use, JSP, and concepts of Domain-Driven Desing a la Eric Evans.

Reflections

Sure, everything cannot be generated automatically. It is important to remember always that fact. But in the day to day, we recognize that we have amount of repetitive text, tasks that we can well delegate to software.

A key point: the model in AjGenesis is free. The presented examples are only examples: we can general the model that we want, and to write the templates we need. It is important to write the templates so that the generated code is similar to what we had manually generated. If we don’t feel comfortable with the generated code, if it does not have our style, our experience, we’ll end up generating something that we do not understand.

Another thinking: the model must be independent of the technology. In the final example, we have seen how, from the same model, we can generate solutions for VB.NET, CSharp and other technologies.

Software can help us to generate software. More: it MUST help us. Our experience counts: what we learned to make applications, we can overturn it in this species of expert system, code generation tools. In the future, I hope to be able to incorporate to the project, in the templates and tasks, more decision making: as well as we gain experience in writing of applications, we can incorporate our accumulated knowledge on patterns, architecture and styles of programming.

And as it is an open source project, AjGenesis allows us extend it, to our taste and necessity.

Suggestions, use case stories, comments are welcome. You can write as comments to this post, or write directly to me. Thanks to all that tested and adopted this project, and helped me to write it.

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

Installing Squeak

In the last century, sometimes I was studying Squeak. Now, in these days I have returned to visit it, and wanted to write a simple, introductory article, on its easy installation.

Squeak is an open source implementation of Smalltalk, that has been developed for years. The internal implementation of its virtual machine is interesting, to a great extent written in Smalltalk, with tools to produce its own virtual machine.

Like in other implementations, one needs to install the virtual machine of the operating system that will use. In this article, we will install a version (the 3,9) for Windows. Also we will need an image, a file with the state of the active instances. Smalltalk has been characterized from always, by being able to write and to raise an image, a species of “snapshot” of the state of the system.

The page of Squeak is

http://www.squeak.org

For somebody not warned of the existence of virtual machines and images, it is a little confused explanation of its installation:

http://www.squeak.org/Download/

because there are several options. For example, to lower the versions from

http://ftp.squeak.org

But there is multitude of archives. The one that we are going to use is a file .zip that contains the virtual machine for Windows and image 3,9 (at the moment already there is a developing image 3,10), directly from:

http://ftp.squeak.org/3.9/win/Squeak3.9-win32.zip

This file contains:

We see a Squeak.exe, that it is the feasible virtual machine. The SqueakV39.sources file is of text, of more than 4 megas of size. It contains the source code of the classes that compose this version. The file Squeak3.9-end-7067.image is the image, “snapshot” that contains the instances of this system.

We can expand the content of this .zip in a directory, and make double click on the feasible one of the virtual machine Squeak.exe. Automatically it detects the image. Alternatively, we could drag from the Explorer de Windows the file image on the file .exe. It appears our first welcome to the Squeak world:

All within this window, is created by the own Squeak. Following the tradition of the original Smalltalk, the graphical aspect, the controls, windows, and others “widgets” are drawn by the own system. The appearance of this window and its contents, then, is independent of the operating system.

In the right lapel titled tools, we found a series of tools. Raising the classic one “to browser” of Smalltalk, we found:

The four superior lists, show, in sequence:

  • categories of classes
  • classes of the selected category
  • categories of methods (of instance or class)
  • methods
  • In the screen capture it appears the classic Object, of Kernel-Objects.

    If you have interest on the virtual machine, can visit

    http://www.squeakvm.org

    He is interesting to see the instructions to produce a virtual machine, in Win32:

    http://www.squeakvm.org/win32/compiling.html

    Well, for today, enough. I hope that it serves to you, as an start in the use of this implementation of Smalltalk.

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

    Call for Papers Object Oriented Technologies 2007

    I’ve received this information, looks interesting:

    Call for Papers
    =========
    5th Object Oriented Technologies 2007
    (Recently .NET Technologies)
    International Conference in Central Europe on Object Oriented Technologies
    http://OOT.zcu.cz
    —————— CUT HERE ——————–
    5th Object Oriented Technologies’2007
    ——————————————-
    International Conference in Central Europe on Object Oriented Technologies
    http://OOT.zcu.cz/
    May 28 - 31, 2007
    to be held at
    University of West Bohemia
    Campus-Bory, Plzen (Pilsen)
    close to Prague - the Golden European city
    Czech Republic
    Conference Co-Chairs
    ————————
    Jens Knoop, Vienna University of Technology, Austria
    Vaclav Skala, University of West Bohemia, Czech Republic
    Keynote Speakers
    ——————–
    Kenneth Tan,Terry Moreland: Technical and Scientific Computing Performance: Today and Tomorrow, Optima Numerics Ltd., U.K.
    Other agreements pending
    MAIN TOPICS
    —————
    * SOFTWARE ENGINEERING software components, large-scale software, multi-language programming
    * PARALLEL AND DISTRIBUTED COMPUTING multithreading, distributed applications, high-performance computing, web services
    * PROGRAMMING LANGUAGES AND TECHNIQUES object-oriented techniques, programming paradigms, assertion support
    * EDUCATIONAL ASPECTS teaching object-oriented paradigm, educational software
    * ASPECT ORIENTED PROGRAMMING AND DEVELOPMENT
    * VIRTUAL MACHINES and BYTECODE etc.
    * HUMAN COMPUTER INTERFACES - computer graphics, visualization, virtual reality using Object Oriented Technologies
    * ALGORITHMS AND DATA STRUCTURES
    * SOFTWARE SECURITY
    * Object Oriented Technologies DEVELOPMENT ON DIFFERENT PLATFORMS
    * GRID Computing and its applications
    * INDUSTRIAL APPLICATIONS of Object Oriented Technologies
    * all relevant research/application papers relevant to Object Technology
    Deadlines EXTENDED
    ———–
    Paper submission:  March 15, 2007 13:00 GMT (London time)
    Acceptance notification (expected): April 17, 2007
    Final upload (expected): April 30, 2007 13:00 GMT (London time)
    Venue: May 28 - 31, 2007
    Submitted papers (FULL SIZE) will be peer-to-peer anonymously reviewed by at least three referees. Presented full, short communication papers and posters will be published in conference proceeding with ISBN.
    The best selected papers will be published in the Journal of Object Oriented Technologies, printed version ISSN 1802-3126, electronic version ISSN 1802-3134.
    The conference proceedings and the Journal of Object Oriented Technologies will be sent to INSPEC (IEE), ISI and others for citations index and other purposes.
    Information on previous and forthcoming Object Oriented Technologies
    (recently .NET Technologies) events can be found at:
    http://OOT.zcu.cz
    Conference Office and Contact
    ———————————-
    Vaclav Skala, c/o University of West Bohemia, Computer Science Department
    Univerzitni 8, CZ 306 14 Plzen, Czech Republic
    skala@kiv.zcu.cz http://herakles.zcu.cz   FAX: +420-37-78 22 578
    Conference supported by
    —————————-
    * Sun Microsystems Czech http://cz.sun.com/about/czech.html
    * Microsoft Czech Rep. http://www.microsoft.com/cze/
    * University of West Bohemia, Faculty of Applied Sciences, Dept.of Computer Science and Engineering http://www.kiv.zcu.cz
    * Vienna University of Technology http://www.complang.tuwien.ac.at
    * Center of Computer Graphics&Visualization, Microsoft Laboratory of Excellence http://herakles.zcu.cz

    Free .NET Tutorials and Technical Articles

    David Hayden have a post with a list of his published articles:

    http://www.davidhayden.com/davidhayden/articles.aspx

    There are many topics in the list: Agile, ADO.NET 2.0, ASP.NET, Back to Basics, Blog Engines, C# 3.0 Tutorials, Design Patterns, Enterprise Library 2.0 y 3.0, C# Business Objects, patrones GRASP, High Performance ASP.NET Web Sites, Object Oriented Principles, SQL Server, SQL Server Management Objects. Great work!

    Go and learn!

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

    AjSite: my new open source project

    In these days, during my sabbatical week, I’m working on a new open source project, that I had started the last year. It’s based on ideas that I’ve implemented in my personal website http://www.ajlopez.com using PHP4, that were useful for years. Initially, my need was a web site that organize my favourites links, notes, and every piece of information that I generate or use. Now, with more experience and clearer requirements, I decide to write a similar solution with .NET.

    The new project is an ASP.NET website, written in C# 2.0, that use a MS SQL Server database. The initial code was generated with my code generation project AjGenesis. The project is interesting, because it serves as a testbed for my new .NET 2.0 templates. I’m very exciting with the power of code generation, and AjGenesis is an ideal framework to explore the open possibilities.

    The site manages

    - Items
    - Categories
    - Tags

    An item could be an uploaded document, an external link, an internal page, or a composite item. It can be associated to zero, one or more categories and/or tags. Like in my site, categories are organized under a hierarchy, forming a category tree.

    This is the project’s initial page (yes, I’m a programmer, not a web designer… :-)

    No downloads yet…. keep tuned!

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

    Online Tutorials on Ajax, JSTL, iBatis, Struts, WebWork and more

    I just discovered the site

    http://www.learntechnology.net/

    You’ll encounter free online tutorials, using Ajax, iBatis (persistence library), JavaServer Faces (JSF), Java Standard Tag Library (JSTL), Struts, WebWork (now Struts 2.0). From the front page of the site:

    One of the unique things about this site is that you’ll notice several “CRUD” applications that all deal with the same concept of updating mock Employee information (CRUD refers to the typical application’s dealing with create, retrieve, update, and delete actions.) The nice thing about these CRUD applications is that they all use the same simple in-memory persistence daos and the behavior and look-and-feel of all of the applications is the same! This makes it really nice for comparing how different web frameworks handle the same type of CRUD concepts in a web application. If you are comfortable with Struts and understand the Struts CRUD example, you might want to then look at WebWorks, Wicket, or JSF CRUD examples.

    Thanks, Rick, for the site!

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

    Free book on Algorithms

    A free pdf book titled “Algorithms”, by S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani, can be downloaded from

    Entire book (draft)

    More info at

    http://www.cse.ucsd.edu/users/dasgupta/mcgrawhill/

    According to Cedric’s Blog

    The book is very extensive and covers the most important algorithms you will ever come across in your life as a developer, starting with the introduction of the “big O” notation, and then progressively moving to more complex topics such as graphs, dynamic programming (nothing to do with dynamic languages), linear programming and culminating this area with the Simplex algorithm (I loved this section).

    A Table of contents with downloads:
    Preface
    Chapter 0: Prologue
    Chapter 1: Algorithms with numbers
    Chapter 2: Divide-and-conquer algorithms
    Chapter 3: Decompositions of graphs
    Chapter 4: Paths in graphs
    Chapter 5: Greedy algorithms
    Chapter 6: Dynamic programming
    Chapter 7: Linear programming
    Chapter 8: NP-complete problems
    Chapter 9: Coping with NP-completeness
    Chapter 10: Quantum algorithms

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