Angel \”Java\” Lopez on Blog

January 31, 2007

AjSaaS: a sample open source Software as a Service application

Filed under: .NET, AjGenesis, ASP.NET, Code Generation, Software as a Service — ajlopez @ 5:56 pm

Today, I’ve been busy writting a new open source sample application, using ASP.NET 2.0 and MS SQL Server 200x. As usual, I began writing down the model of the application and generating the code using my AjGenesis code generation engine. I love that project! :-) It frees me from repetive and cumbersome tasks, as tedious web page creation, or long stored procedures code.

Now, I have a system with:

- Tenants
- Applications
- Users
- Roles

Each user belongs to a Tenant. There is the “main” Tenant, one that provides the AjSaaS application. You can define new applications, and create new tenants (enterprise that uses applications). A tenant can use many applications, and an application can be used by many tenants.

Each tenant has a collection of users. Each application has a collection of roles. A user can plays many roles (in differents applications, if his/her tenant has adquired many services).

This is my first day of work. I’m now working on implementing membership and role providers based on the above schema (using the provider features of ASP.NET 2.0).

After that feature, the next steps are:

 - Implement one or two sample application to put under the system (I’m planning to implement some entities with CRUD functionality).

- Implement user-defined entities as in

Building an End User Defined Data Model – Part 1
http://www.15seconds.com/issue/050324.htm
Building an End User Defined Data Model – Part 2
http://www.15seconds.com/issue/050414.htm

using some ideas published at

Multi-Tenant Data Architecture
http://msdn2.microsoft.com/en-us/library/aa479086.aspx

The final idea is to extend the system up to level 0,1,2 of the maturity model at

SaaS Simple Maturity Model
http://blogs.msdn.com/gianpaolo/archive/2006/03/06/544354.aspx

Some business rules would be implemented with customizable Workflow Foundation workflows, or something similar usign AjBasic as a Saas Code Language (a la SalesForce, they included a controlled programming language to extend their systems).

I’m in my sabbatic week. When I finished with this week, I’ll publish the first version of code, with open source license.

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

January 30, 2007

AjSite: my new open source project

Filed under: .NET, ASP.NET, Code Generation, Programming, Software Development — ajlopez @ 11:33 pm

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/

January 29, 2007

Code Generation with AjGenesis: A Hello World application

Filed under: .NET, AjGenesis, Code Generation, Java, Software Development — ajlopez @ 10:02 pm

My favourite project is AjGenesis, and I’m improving its examples every month. AjGenesis is a code generation engine, written in VB.NET. It’s an open source project, with a BSD-like license. The license allows you to use in any of your projects, commercial or not. It can be used as a library, invoked from your own application, or it can be run from the command line. It can be launched with NAnt tasks, so you can write powerful scripts to generate, compile, and deploy solutions in different technologies (not only .NET).

At the project page http://www.ajlopez.com/ajgenesis (and in the project .zip itself), there are lot of examples, that generates text artifacts and source code, starting from a free-form model. The generation process uses templates, written in an interpreted language, affectously named AjBasic. The examples generate PHP, Java, JSP, VB.NET, C#, ASP.NET code, and database scripts, with stored procedures and more. You can modify or create your own templates, at any moment. I want to stress two points:

- The model is form-free: you can define in any way you want

- The tasks and templates to run and apply are totally programmable and under your full control

This makes a difference with other code generation tools. You can define your own model, your own templates, to generate the text artifacts of your preference. Other tools start from the database schema, only to produce few code, as entities and DAOs. But with AjGenesis, sky (a textual sky) is the limit! :-) .

Lets take an example. This post is dedicated to model an application, as a proof on concept for the power of this tool. The target is to produce the most citated application: a Hello World app (my first encounter with such app was with the mytical book “The C Programming Language”, by Kernighan and Ritchie).

The example can be download from HelloWorld1.zip

First, the model. The model is a simplification of reality. A model, for example, a map, is not the territory, the reality. For AjGenesis, we need to write a model that manages the variable part of our system. In this case, a Hello World-like application, we want to model the message as variable. Then, create in a working directory, the file Project.xml:

<Project>
<Message>Hello World, by AjGenesis</Message>
</Project>

This is the first step, in a long journey. We didn’t use a predefined model. It’s simpler: we just write the model, in a well-formed XML file. No schemas, no DTDs, or weird things. Only our idea.

Second step: choose the target technology (programming language, platform, frameworks to use, databases….), to use in our example. Then, write (or reuse) templates. Now, we’ll use a VB.NET example, a simple console app. The template to write resides in the file HelloVb.tpl


‘ Hello World demo
‘ generated by AjGenesis
http://www.ajlopez.com/ajgenesis

Module HelloWorld
 Public Sub Main()
  System.Console.WriteLine(“${Project.Message}”)
 End Sub
End Module

Here, a feature from the templates: in the code, you can access and use in the output, the model data. If you write Project.Message between ${ and }, the AjGenesis processor will replace that text by the value of that branch of the model. You don’t use the XML syntax or something like XPath to access the model. The initial model was serialized in an XML file, but during processing, it’s brought to memory, as an object model, accesible via the familiar property syntax.

We would write the model as

<Project Message=”Hello World, by AjGenesis”/>

The memory model would be the same. Altough now Message is an attribute, for our template it’s still a Message property in the Project object.

Well, now we have the model, and the template. We must download and expand AjGenesis-0.4.3.zip (version currently under development, other versions are under the source code directory at the SourceForge project). In this version, there is a bin directory containing libraries and executables. The program AjGenesis.Console.exe can be invoked to load the model and to read the template, then, it generates a source code file. We enter at command line and run:

AjGenesis.Console Project.xml HelloWorldVb.tpl HelloWorld.vb

The paramaters can be:

An .xml file: when AjGenesis process a parameter that refers to an XML file, the represented model is loaded in its variable environment. The name of the root node is used as the name of the variable that contains the model. In our example, the variable is Project.

A .tpl file: it’s used as a template, is processed, generating a file with name equals to the next parameter.

The bin directory of AjGenesis distribution must be included in the path environment variable of your system.

The parameters are processed in order. We could have more than a model, using two or more XML files as input. For example, a second XML file could be used to describe the database technology to use, or the enterprise name and information to put in the generated source code, or anything else you want to model. In this case, the second XML file should have a different root node (not a Project one), so it will be loaded in a different global variable. We could put many template files with its corresponding generate files, in the same invocation, to generate more than one text artifact in one run.

After running the above command (we need a .NET framework installed in our system, remember that AjGenesis is written in VB.NET)), the file HelloWorld.vb is generated, with content:


‘ Hello World demo
‘ generated by AjGenesis
http://www.ajlopez.com/ajgenesis

Module HelloWorld
 Public Sub Main()
  System.Console.WriteLine(“Hello World, by AjGenesis”)
 End Sub
End Module

Well, it’s not a “Wow, what an application!!”, :-) , but it’s a first success.

Move forward. Now, with the same model, we want to generate our big system in Java. The market pressures, our customer needs, all point to use Java for the next version of our killer application. AjGenesis is here to help us! Lets go, create a file HelloWorldJava.tpl with

/**
* Hello World demo
* generated by AjGenesis
*
http://www.ajlopez.com/ajgenesis
*/

public class HelloWorld {
 public static void main(String [] args) {
  System.out.println(“${Project.Message}”);
 }
}

and run at the command line

AjGenesis.Console Project.xml HelloWorldJava.tpl elloWorld.java

Voilá! The file HelloWorld.java is generated:

/**
* Hello World demo
* generated by AjGenesis
*
http://www.ajlopez.com/ajgenesis
*/

public class HelloWorld {
 public static void main(String [] args) {
  System.out.println(“Hello World, by AjGenesis”);
 }
}

We’re in the road. Go for a more flexible example: we want to create the VB.NET program, and the Java file. We make the class and file name a variable (in the preceding templates, the name was fixed to HelloWorld).

The files for this second example can be download from HelloWorld2.zip.

To do that, in other working directory, create a file Project.xml with content:

<Project>
 <Name>HelloWorld</Name>
 <Description>Hello World Demostration</Description>
 <Message>Hello World, by AjGenesis</Message>
</Project>

Then, write the templates ModuleVb.tpl


‘ ${Project.Description}
‘ generated by AjGenesis
http://www.ajlopez.com/ajgenesis

Module ${Project.Name}
 Public Sub Main()
  System.Console.WriteLine(“${Project.Message}”)
 End Sub
End Module

and ClassJava.tpl

/**
* ${Project.Description}
* generated by AjGenesis
*
http://www.ajlopez.com/ajgenesis
*/

public class ${Project.Name} {
 public static void main(String [] args) {
  System.out.println(“${Project.Message}”);
 }
}

We’ll use another feature of AjGenesis: the capability to execute an script, in an interpreted language informally named AjBasic. I think that this a powerful feature, that open a new horizon, beyond the command line. With that feature, we can programmaticaly manipulate the model, and the tasks to execute. In the available examples, this capability is used at any point, producing complete solutions, with dozens of auto generated files. But, back to our example

The program is written in the file Build.ajg

PrintLine “Generating ${Project.Name}”

TransformerManager.Transform(“ModuleVb.tpl”, “${Project.Name}.vb”, Environment)
TransformerManager.Transform(“ClassJava.tpl”,”${Project.Name}.java”, Environment)

The AjBasic language has some predefined verbs, like the autodescriptive PrintLine. You must take note that, as in other scripting language, this one has expression expasion inside the strings. That is, when a text is between double quotes (a string constant), an expression inside ${ and } is located, and replaced by the corresponding value in the model. You can recognize her a behaviour similar to others languages, like Unix scripting languages, PHP, or JSP Expression Language.

The variable TransformerManager is one of a few predefined ones. I didn’t define a lot, and you can add new variables, if needed. The TransformerManager object is used to programmaticaly invoke what we used to run from the command line. Then, the first parameter of its Transform method is the template file name, the second is the file name to generate, and the third and last is the variable collection, known as the AjGenesis environment (Environment is a predefined variable that points to the current environment).

We run the above file with the command line

AjGenesis.Console Project.xml Build.ajg

The console program is prepared to execute each parameter that refers to an .ajg file, as an AjBasic program.

Lets go forward. During 2005 (AjGenesis project has years in development), I added NAnt support. That is, I wrote AjGenesis tasks that can be invoked from that great tool. Additionally, I use the NAnt-GUI utility to execute the .build files from a graphic interface.

Write a default.build file with the content (update the ajgenesis.dir property to point to your AjGenesis installation directory):

<?xml version=”1.0″?>
<project name=”Example 1″ default=”build”>
<property name=”ajgenesis.dir” value=”c:/ajlopez/dev/AjGenesis-0.4.3″/>
<property name=”nanttasks.dir” value=”${ajgenesis.dir}/bin”/>

<target name=”clean” description=”cleans build directory”>
   <delete dir=”${build.dir}” verbose=”true” if=”${directory::exists(build.dir)}” />
</target>
<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”>
   <loadmodel model=”Project.xml”/>
</target>

<target name=”build” depends=”init”>
   <executetask task=”Build.ajg”/>
</target>
</project>

Then, invoke from the command line:

nant

If we configured the NAnt tool, this utility process the default target from the build.xml file. You can use the NAnt-GUI utility, that shows a window like this:

I hope this article helps you to a quick start up in AjGenesis development. In a future post, I’ll explain more examples, model manipulation in memory, intensive use of NAnt, and complete solution generation, in different platforms and technologies.

If you find this utility useful, you can collaborate spreading the word, writting some comment or post about your AjGenesis experience.

Suggestions, and ideas, welcome!

Thanks for all!

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

Java on the Client side, and Swing Look and Feel

Filed under: Java — ajlopez @ 1:35 pm

I’ve just discovered a blog, with tons of information about using Java on the client side:

http://www.clientjava.com

You must use the search box, apparently, the normal navigation isn’t working now. I found that site, searching resources about changing the look and feel of a Swing application. Then, that blog has this old, but useful entry:

http://www.clientjava.com/blog/2004/07/07/1089221149000.html

For more information about Swing Look and Feel, you can visit:

http://java.sun.com/products/jfc/tsc/articles/lookandfeel_reference/index.html
http://www17.homepage.villanova.edu/william.pohlhaus/is/doc/Java%20Look%20and%20Feel.htm
http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-LAF.html
http://gtkswing.sourceforge.net/
http://javootoo.l2fprod.com/

Angel “Java” Lopez
http://www.ajlopez.com/
(yes!! it’s my sabbatical week!!!…. http://ajlopez.wordpress.com/2007/01/27/sabbatical-week/ )

January 28, 2007

Computer nightmare

Filed under: Uncategorized — ajlopez @ 9:38 pm

You MUST see this video (thanks to Juan Pablo García, great link Pablo!)

http://www.youtube.com/watch?v=5bPMwAHdJCg

January 27, 2007

Sabbatical Week

Filed under: Uncategorized — ajlopez @ 9:38 am

Today is the first day of my sabbatical week, a week dedicated to think, read, write, create and put order in my life. In my opinion, a “free” week is a must, twice a year: you can put all effort in one subject or you can explore new possibilities, without links to daily activities.

This time, during these days I’ll write down some ideas. I want to write some code that is in my mind, and rearrange some open source projects. I hope to publish any advance, here, my technical English blog, and at:

http://www.msmvps.com/lopez (technical Spanish blog)
http://ajlopez.zoomblog.com (personal Spanish blog)

The last month was very exciting for me, full of ideas and challenges, and now, it’s time to put order on all that stuff.

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

January 14, 2007

Source code examples: Java, ASP.NET, C Sharp, VB.Net, Spring, Hibernate…

Filed under: .NET, ASP.NET, Books, Java, Software Development — ajlopez @ 9:26 pm

I just discovered the site

http://www.java2s.com

It has lots of source code in Java, ASP.NET, C#, VB.Net. It has examples for Swing, Tomcat, Spring, Hibernate, JavaServer Faces. It includes examples for JavaScript, Cascading Style Sheets, Dynamic HTML. It has applications of Patterns, JavaServer Faces, JavaServer Pages, DataSets, and… The list is big.

And book examples, like:

Spring Live

and

Struts

A lot of resources.

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

January 4, 2007

Dreaming in code

Filed under: Books, Software Development — ajlopez @ 9:44 am

One of the mos interesting question on software development, is: Why is so hard? In my opinion, the creation of software is one of the most challenging human activities. One of the causes, is the different levels of abstractions that are needed. In a software project, you must master the big view, and pay attention to every detail.

A new book, Dreaming in code, try to explore the answers to that question

The author is Scott Rosenberg, one of the cofounder of Salon.com.  I don’t read the book yet, but it was comment by Joel Spolsky at his post Dreaming in code. According to Joel, Scott is an excellent writer, that knows how to understand the software development.

The book is about the story of one software project — Mitch Kapor’s Chandler, an ambitious, open-source effort to rethink the world of e-mail and scheduling, according to the book website.

Chandler, a PIM (Personal Information Manager), that Wired pointed years ago as “the Outlook killer”, is still under development.

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

January 3, 2007

Programming language for SaaS

Filed under: Software as a Service — ajlopez @ 7:45 pm

One of the problems to resolve in a Software as a Service, is customization. Another related problem, is extensibility and integration with enterprese in-house application.

Although the customization can be obtained via parametrization, and ad-hoc metadata configuration, your needs can easily scalate to an special level that requires more features.

A way to extend and implement such customizations, is using programming. But instead of using a traditional programming language, a SaaS application can use a controled, and specialized language, totally oriented to the domain or line of business of such application.

Notably, Salesforce.com adopted such approach, with the Apex programming language:

The language runs on the server. According to Salesforce page:

The key technology of Apex is a new programming language that allows developers to do something entirely new and powerful to run business logic on salesforce.com servers. With the release of this language, Apex developers will be able to use the same tools that salesforce.com’s own development team uses to build our own apps, including our flagship CRM products.

You can add code to events on buttons, links inside Salesforce’s web pages. This is an interesting solution, that deserves study and experimentation. I’d want to incorpore such feature in an extensible SaaS application. Don’t you?

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

One size cannot fit all

Filed under: Software as a Service — ajlopez @ 9:18 am

That’s the opinion from Gianpaolo Carraro, Microsoft’s evangelist on SaaS. He wrote an interesting post, making an analogy between SaaS and biology. It’s fun, too:

The key points are:

- There are many “species” of SaaS applications
- The habitat dictates which species survive

I’m still thinking about the relevance of such analogy, but it’s interesting. I don’t know how to describe an habitat, yet. 

You can read the complete post at:

Saas and Biology

Angel “Java” Lopez

http://www.ajlopez.com/en

Theme: Shocking Blue Green. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 28 other followers