Hi All, I have been working on reusable component called BeanGenerator, which as following functionality. Please advise if it is eligible to be posted as component in Commons.
Availability of DynaBean from BeanUtils has simplified the programmer lives to quite a bit extent but it lacks in certain functionality which is very much required to all programmers to name a few like CompileTime method semantics validation, generating the equals, hashCode for beans, type conversion from all Strings types to business specific type etc. So I had been wondering if there is a tool, which takes the beans information in the xml file and generates the corresponding beans automatically. Some of the visible advantages of this are, 1. From the same xml bean data, we can automatically generate two bean classes. For ex., if you specify bean information for com.test.User, tool can generate com/test/User.java file and also com/test/UserForm.java file, with corresponding access method. so by calling new User().getFormBean(), would return com.test.UserForm, which can be automatically used in the jsps as action forms. Also by calling new UserForm().getBusinessBean() may automatically return a new instance of com.test.User, with all fields automatically type converted and populated. 2. By just marking a set of attributes as primary key fields, tool can generate the equals, hashCode in a consistent manner 3. If user wish, tool can generate the containers for specific beans. For ex., if you have com.test.User and if you want container for this, tool can generate com.test.Users, with all access fields which returns the User instead of object, which avoids ugly typecast things all across 4. Also tool can add necessary comparator implementation for marked attributes, so that beans in a container can be automatically sorted. so by calling users.sort (User.FIELD_FIRSTNAME) or users.sort (User.LASTNAME) etc. 6. Generate appropriate reset, toString, validate methods, which are really a nightmare to maintain in enterprise applications (if you add a attribute or modify one) 5. Tool can automatically generate java files, compile them and create corresponding jar files and put it in a specified folder. So modifying the bean specification is as simple as just adding a task and executing it. As you clearly visible, by having the Bean information in xml once, we can programmatically can do many things, which would be very error prone or laborious otherwise. Also it is clear that, this is not to do with BeanUtils module what we have as of now. Please advise if this is of any use for other java developers or designers. and also if this can hosted as new module in commons may be like Commons BeanGenerator. Thanking you all, Santhosh.