W4W - Wizard for Web (J2EE) application

W4W stands for Wizard for Web application. After working for about 3 years in software industries as a J2EE based web application developer I came up with this W4W concept. W4W is a Java based code generator engine which generated web application code compliance with spring, Hibernate and Web Work.

Now a day’s internet is a robust medium of sharing data between groups of people, organization and even between two applications (SOA, where services are exposed and other application uses them). Many bigger software organizations are involved in development of software applications for different domains. Companies needs skilled developers, time, in-depth knowledge of various framework used for development and a set of process to complete the project in estimated time. Most of the time which we spend on is “doing ground work” before starting the project; we do this just to make sure that we should not fall in to a dead lock situation in further stages of development. When I say ground work it can be co-related in different ways for different teams (management, architecting, development, testing):

1) For Management - >Planning of resources and funds
2) For Architecting -> Designing Project based on domain knowledge and requirements.
3) For Developers - > Designing initial working model code, proof of concepts & components which can be extended further in to a rea
l application, this generally takes 15 to 25 % of total project time. Think on this and imagine what if it can be done in 15 minutes no matter how big the application/project is???
4) For Testing team -> Testing team prepares different environments, plans, test cases, automations etc.

Being a developer I will only stress on point 3 and will not get in to the complex side of other topics. Consider you are a developer and you have been asked to develop an application which looks very similar some already existing application, what you’ll be doing? I am sure first of all you would like to see that existing application. A good developer will do following things after having a demo of existing application and before starting his own work:

1) He will read the try take and overview of framework and technologies used for developed of application.

2) He will try to separate out some part of application which can be re-used to speed up the development work. I personally treat Copy-Paste and Re-Use differently, a good developer always give an opportunity to copy his code as it is and that too multiple times.

3) Re-Using the components which already exists he will start working and will try to come with a sample working model of application/project, and if it is accepted then he will extend/enhance the same model further to a complete application.

For sure this practice saves much time and gives a start point for any development work. In this case we have to be little careful about what to use and what not? What fits in to our requirement and what’s not? This approach is only possible when you already have something and you are supposed to develop something similar to it, what if you don’t have anything to refer, off course we have to do all ground work by putting our own efforts.

1) A web based (JSP) UI for each table with add, update, delete and search screens.
2) A Struts 2 based action controller classes.
3) Struts 2 based mapping and tiles configuration file.
4) Set of Hibernate POJO.
5) Spring DAO, DAO Implementation, Service & Service classes.

Once the code is generated you can directly copy it to you server and access you database as a web base application. I’ll walk you through the different components, frameworks and technology used developing W4W application. Also at the end of this document I’ll take a small application to explain how you can use W4W in you project.

Who can use it?

When you will analyze and application it basically does following things apart from doing some other complex things:

1) It provides a way of sharing data with user or other application.
2) It provides some sort of screens where user can browse the data in more readable and user friendly form.
3) Few screens where user can search, add, update and delete data.
4) Reports generation etc.


Being a code generator, W4W also generated the code for performing all these operation on an existing database, so in short it can be used for laying down the initial ground work for all web based applications. I can enlist few practical uses of W4W here but it is not limited these enlisted items:

1) Let’s say you have a database and you want to provide its access to set other users via web based interface, you can generate the code using W4W and can deploy it on web server. W4W will generate screens which can be used to read, search, update, add and delete information from database.

2) A team which is working on a project and wants to have basic infrastructure ready so that they can speed up the project in initial phases.

Idea and Concept of W4W

Software’s are all about automation, sharing information and manipulation of data. Its being almost 3 years I am working in a company called as GlobalLogic as senior software engineer. During these 3 years I have worked on many projects and almost each project had a similarity and that was:

1) Each application had a web based front end.
2) Each application had a supporting back end UI controller framework like Servlet, Spring MVC, Struts 1 or Struts 2 with web work.
3) A database layer which in some cases was plain JDBC and in other cases it was Hibernate with Spring DAO etc.
4) Most of the screens which we have been designing in all these applications/projects were related to searching of data, its editing, deletion and updating etc.
5) Report generation.
6) A scheduler framework to perform server side tasks on schedule basis.
7) A messaging layer to send out alerts and notifications.
8) A supporting SOAP based services to expose the features/functionalities of application as web service so that other application can access it via web service proxy.

Does this sound similar to the project/application you are working on? If not 100% at least some part of you project might be coinciding with the above listed functionalities/features. While working on these projects I noticed that I am doing the same task again and again, so I thought why we can’t have something generic and re-usable. This was the first thought which came in my mind and I decided that I’ll will extend this thought in to a reality and I named it as W4W (wizard for web application).

Before actually starting any work on W4W I did some home work on following things:

1) What technique should I use

2) What framework should I use?

3) How much should W4W bother end user to use it

4)Is there anything which I can refer or re-use to start working?


After doing some analysis I and found answers for above questions:

1) I should use the code generation technique which will generate the complete application code automatically once user provides database connection information. Code generation engine will use velocity templates for generating UI as well as backend code.

2) Since I have worked on J2EE technologies there fore it was little easer for me to bend towards J2EE frameworks, that’s why I considered spring, Hibernate and Struts 2(with web work) as the base frameworks. Generated code will be based on these technologies.

3) User will only provide database connection information like host machine, drivers, user name and password. W4W will take this information and will generate code which is ready to deploy on serve with out any modification. So isn’t it cool? You don’t have to do anything and like a fast food everything is ready for you in 2 minutes!!!

4) While working on different project I have came across few eclipse plug-INS, net bean features which generates CURD code automatically for a given database. If you want you can explore them as well for comparing and knowledge purposes.

Once I had answers for all my questions I looked back again to the projects on which I have worked in past to prepare a ground work. Few years back I have developed a blog site for one of my friend and fortunately I have built it on those technologies which I have selected for W4W. I took that blog site as my reference and did my ground work by creating a small database, created a project directory structure, created a work flow and architecture on paper for W4W. Once I had ground work I started actual implementation of W4W.

Technologies Used

W4W automatically generates web application code by just taking database connection as input information. The generated code can be deployed to web server without a single line change, so there are no complex steps to deploy the generated code. There are four types of code generation and almost each of them uses some different framework for code generation:

1) Database Hibernate POJO and XML mapping files: I have use a very cool framework called as salt-db which can generate Hibernate style POJP and mapping files by reading the underlying database schema.

Salt – db Hibernate POJP generator

2) XML Descriptors: these are the descriptors which act as guide for code generator engine and tell code generator what to and how to generate.

For generating XML descriptors I have used DOM and SAX parser

3) UI Classes: W4W uses the XML descriptors and merges it with velocity template to generate UI code.

Velocity engine for generating JSP based UI and Java Script code.

4) Action, DAO and Service classes: Again velocity engine used for generating action classes, DAO and service.

Action classes are based on Struts2, DAO and Service classes are based in spring.

So the generated code is combination of JSP, Struts2, Hibernate and spring and it can be deployed on web servers which have been developed with sun’s JSP and Servlet specification.

So this is how W4W’s thought came in my mind and I completed a demo release of it, yet there are many more features which I am planning to include in to this ti make it more robust and accurate, I have completed W4W in number of steps, I’ll explain them while explain them while explaining the W4W framework later in this document.

W4W Framework & How Does it work?

Generally we should have the framework detail and “how does it work?” kind of things separately but I always feel comfortable having the step by step exploration of framework along with having details of how does it work, it helps us to co-relate the framework component and their use. I apologies if I am creating some extra confusion here, I thought it’ll be a good experiment that’s why I am clubbing up these two sections here.

W4W framework is a framework which reads the metadata from underlying given database and generates J2EE application ready to deploy / use code. This framework is actually combination of other popular frameworks available for J2EE development. W4W generates code is based on struts, spring, hibernate etc. There are four main components of W4W framework:

1) POJO generator

2) XML Descriptor generator

3) Action, DAO and Service class generator

4)SP and Java Script generator

Here is component diagram of W4W


In following section I’ll explain each one of above in little detail to give you a brief idea about what does each component do and how other components interact with each other, this concept can be extended further to have more sophisticated applications and I am working in this direction, if anyone is interested in working on this with me they are welcome. You can mail me at sun.engineer@yahoo.com, or see contacts section for full contact detail.

Now I’ll explain different steps which W4W performs while generating the code. Please see the diagram below which shows the different steps performed by W4W while its execution.


1) Very first step is to provide information about the database for which we want to generate the code, so we have to provide the database information in an xml file which is basically ant (link apache ant site) script file. Here is an example




Once we have entered the database information, we just need to execute this ant file and it will go through step 2 to 4 and will generate the required code. That’s was easy right? Just a database configuration and everything is generated for you on fly!!

2) Once W4W have the database information it executes “generate (Salto-DB ANT Generator - Salto Consulting)” ant task as shown in above example. This task reads the underlying database and generated the hibenrnate POJOs and corresponding mapping file, generated POJOs and mapping files will be copied to package (<property name="packageName" value="com.sur.model"/>) defined in above example file.

3) After generating POJOs and mapping files, W4W reads these mapping files and POJOs to generate the XML descriptor file. I have defined a XML file structure/format in which I can collect the information about the different components which W4W needs to generate. XML Descriptor file is a simple XML file which contains information about different components (action classes, JSP, DAO, spring service classes etc). to collect information form POJOs and mapping file I have written few Java classes which reads the hibernate POJOs and (.hbm) mapping files (generated in step 2 above), these classes reads the XML file and POJOs with the help of Java class loader. These classes collects necessary information for generating DAO, action, sprint service classes etc. and dumps this information in a XML descriptor file, this file is called as “source_classes.xml”. here is an example of “source_classes.xml” file:




4) Now we have all information ready with us in XML descriptor file to generate the different components. Using the information in XML descriptor file W4W will generate following components:

A) Action classes –

B) DAO Classes –

C) Implementation classes –

D) Spring Service classe –

E) Spring Service Implementation class -

F) Spring applicationContext.xml file with hibernate database configurations, transaction manager definition and other service class beans.

G) A Sturts.xml file which contain the action mapping

H) A tiles configuration file, which contain the tiles definition for different pages

I) A Navigator JSP with the help of Velocity template

J) Set of JSP pages for CURD functionality.

5) Once W4W has completed step 4, we have complete web application ready with us which we can deploy (just copy and paste) as it is to web server and it is ready to use!!

Now you know what are the different steps which W4W performs while generating the code? So there are four main components as mentioned during start of this section. Each component is doing some piece of work which is either used by other component (like POJOs and xml descriptor file) or it is end result (actual java or JSP code)

Advantages and Disadvantages

Till now we have seen how easily W4W can generate code a full fleged web application code which can be deployed without any hassle. I would like to enlist few of the advantages and disadvantages of W4W here.

Advantages:

1) For a J2EE project which is about to start and needs a web based UI for underlying database W4W can do that in less than 2 minutes.
2) W4W generates JSP screens which allow addition, deletion, editing and updating of data in tables.
3) It can be used with all database supported by hibernate framework.
4) You don’t need to write any xml file, JSP or java code, everything will be generated for you.
5) No need to modify anything before deployment unless you have same copy of database elsewhere and you want to use that as backed database. If you want to use some other database then you can simply modify the applicationContext.xml file.
6) No ground work needs to be done for building Struts+hibernate+spring based web application.
7) Easy to use, it just needs database information from end user.

Disadvantages:

1) Since this is first release of W4W therefore it does not have validation on UI screen. In future releases of W4W I’ll address this as well, and will try to come with a generic validation framework.

2) If there is need for strict validations then users need to write their own JavaScript and plug it in to the generated JSP code.

3) At the moment the layout of screen is predefined, if a user wants to have some different look and feel they need to modify the tiles layout (in tiles.xml file) and CSS files according to their need.

4) At the moment I am using a library to generate hibernate POJOs and mapping file, and this framework needs a primary key column in each table and that column should name as “id” otherwise W4W can not generate the full functional work. This is not a show stopper, either I can write my own library or I have to hunt for a library which can address this.

5) Right the code which W4W generates, it display all the available column on UI even though if it not required, so user need to modify JSP code if they don’t want few of column on UI.

6) W4W is a script based tool that’s why at the moment it does not takes much of users opinion in to consideration while generating code, but I am already working on this front to have a full fledged UI similar to wizard screens so that at each level user can select what he wants, what he don’t want, how does UI should look like, what should be level of validation etc.

7) There is a configuration file which W4W uses to know where to dump the generated code, where to look for files needed for generating code etc. This file needs to be configured carefully because if it is configured incorrectly, W4W will not generate code. Ideally we should have some screen where user can browse and select path, so this will be available in next release.


Customization & Tips and Tricks for W4W

Right not there is not much which I can write in this section, because there is nothing tricky here, W4W is very simple and straightforward. But I would like to list few things which can help users to customize the generated code so that they can enhance it based on their need.

7) To change the look and feel just go through the existing CSS and modify it according to it change the color and texture.

2) If you don’t like the UI layout, not an issue, you can modify the tiles.xml file. A developer who has worked on struts can modify the tiles.xml file or if you are new then please refer to Strut’s site [link to struts or tiles tutorial]

3) f you don’t want to give access to all generated screens, modify the navigation.jsp file and remove the links for the pages which you want to restrict.

Future Enhancement & Bug fixes

I am planning to come up with couple of new features so that W4W can be used easily, and it should be more users friendly. Few of the things which I am planning to include are:

11) A wizard based UI which using which users can interact with W4W framework to provide their choices about what to generate, what not to generate, how should be look and feel, what should be the level of validation etc.

2) I am planning to provide different predefined templates in W4W so that use should have some choices for look and feel.

3) here will a configuration screen using which user can perform the configuration task easily.

4) In next release I’ll be adding a customizable generic JavaScript validation framework with a UI screen for selecting different level of validation for each individual field of database table. User can select the type of validation they want for a particular filed.

5) I'llalso add a JavaScript tool tip framework which I have used in some other projects as well, so that users/developer can add help and description for a particular field easily.

References

1) This is where you can find library which can be used for generating Hibernate POJOs and mapping files http://salto-db.sourceforge.net/salto-db-generator/index.html

2) Additional information and details about Struts2 and web work can be found at http://struts.apache.org/2.x/

3) Read more about Spring modules and components at http://www.springframework.org/

4) Want to know how to use velocity for generating code, then please visit at http://velocity.apache.org/ .

5) Learn and find more about hibernate at http://www.hibernate.org/

Contact

Feel free to share your ides, suggestion with me. If you want any help or want to work on this project you are welcome.

Suryakand Shinde (yes friends its “D” not “T”!!!)
Sr. Software engineer @ GlobalLogic India Pvt. Ltd.
e-mail:
suryakand.shinde@globallogic.com(O),suryakant34@rediffmail.com (P)
Yahoo IM: suryakant34, Gtalk:
suryakand@gmail.com


Comments

Popular posts from this blog

Sling Authentication

CQ Development - OSGi bundles and Components

Multiple log files using log4j appender

Create an AEM (CQ) project using Maven