wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes how to avoid many if else [Pojo Validation] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "how to avoid many if else [Pojo Validation]" Watch "how to avoid many if else [Pojo Validation]" New topic
Author

how to avoid many if else [Pojo Validation]

saqib sarwar
Ranch Hand

Joined: Mar 30, 2007
Posts: 77
I have written a validation class for eight types of messages(POJO classes) which first identifies the message class and than validate its properties.

now a pojo message class has about 46 properties, and validating these properties with if-else and then logging every validation error basicallly made the code too long and hard to read and maintain.

i want to improve my code and looking for a way to avoid many if-else statement or good way to validate pojo objects.

can any one suggest a way to move forward ?


SCJP5 95%, SCWCD 85%<br />Knowledge is the Life of Mind
Jilesh Lakhani
Ranch Hand

Joined: Jul 26, 2006
Posts: 49

can i have a sample code


-Jilesh
Universe and Knowledge has no bounderies
saqib sarwar
Ranch Hand

Joined: Mar 30, 2007
Posts: 77
actually the sample is tooooo big that it will confuse you guys ...

today i found solution about this, and now i will use JaValid

i walked through commons commons validators, i-screen and Spring validation as we are using Spring 2.0.

but i want to keep code away from xml and I cannot use Spring 2.5 annotation based validation because our project is bound to spring 2.0.

so i decided to use JaValid..

hope i would have good experience with this .. it looks like a simple annotation based framework for validation.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to avoid many if else [Pojo Validation]