Saturday, August 26, 2006

Spring Framework...

Why a new Framework comes to our mind. The solution to this lies in the need to have a light weight, 3rd party pluggable resource and configurable ( xml based ) kind of framework to help write business logic. And Spring helps in this by means of IOC(Inversion of Control) and AOP(Aspect oriented Programming) concepts.
I dont want to get into the IOC and AOP as thats not the point here to cover in this blog.

Basically if some one wants to understand spring then the crux is that one should think about writing a modularized utilities which will read the resources and make it available to the application at the time of integration -- on the same time, application being not dependent on the resource selection. Take the case of datasource which was provided by weblogic and though configurable to any database. Apart from this the framework abstracts the exception thrown from varius modules in the form of checked exception.

The basic coding lies in writing bean.xml files to inject the resources via constructor, methods, or settermethod (or any of the combination ) and utilise them in writing env independent code. Spring has been divided into parts like core, DAO, MVC web, etc. ApplicaitonContext and BeanProperty takes care of parsing xml file into beans and instantiating the beans as per the creational specification ( Design patters -- singelton, prototype, factory ) though keeping the threadsafe objects.


MVC Framework wrt Struts...

MVC ( Model View Controller ) is framework which is used in web application design. It had been used for years to get the structure in place. Apache struts has been popular in this regards.

In any web based application, the flow is very simple, User puts in request and the request goes to back end ( over HTTP port 80), Where the flow of the applicaiton is controlled by controller ( ActionServlet in case of struts to map the Action to be taken with the input request ( jsp page )) and being redirected to vie view ( jsp ( this assembles the data populated POJO objects from the back end to show thre results ). View are jsp pages which has been redirected by the controller on having done the action ( Action are the classes in struts written by the user to do back end code processing ).

Model are the action class which talks to the back end ( esp distributed transactionally controlled modules like EJB, HiberNate, or legacy applications )

In a way Struts used many a tag libraries to help write view code. Tag Libraries are precompiled java classes to generate HTML Form elements. Struts also comes with pluggable validation ( esp javascript in the form of xml file )and plugin configuration facility.

Silent features of struts...
1) ActionServlet reads the struts-config.xml to load and map the workflow by means of action tags.
2) ActionForm are the inputs taken from the page and sent in the form of POJO to the back end Action classes. These forms have reset and validation methods to modify data.
3) Action classes created use command pattern to use request ( with Forms, Mapping, etc ) to process request and send response.


What is XML

As I see XML ... Its a human readable file which has elements and attributes to transfer data in a objectified way. Elements can be considered as objects and attributes as object's variables. It is easy to read. eg.
<element1 attribute="123">
<!-- comments follows -->
<element2 attribute1="1234" attribute2="234"> Text to be put up</element2>

XML has many more kind of data which it takes esp text. As compared to RDBMS ( which has columns and rows as in excel sheet to store data. ) XML is more powerfull. XML helps developer to define his own rules ( DTD, XSD ) to generate apply datastructure as per the need of the system.

XML has validation rules in form of file ( DTD or XSD ). DTD has loose validation rules and the XSD has strict typed rules ( including regular expressions )

XML are mostly used in data transfer accross the modules, applications, and in the configuration of the application. Its extensively used in building scripts esp apache-ant.

I will add more to it as I read on.