XML base data validation rule in java -
XML base data validation rule in java -
hi new in xml in java.in recent project need create validation rules in xml,but the problem different user grouping may have different rule example
<root> <user-group type="sale"> <parameter-name ="loginname"> <max-length>10</max-length> <min-length>4</min-length> </parameter-name> <parameter-name ="password"> <max-length>10</max-length> <min-length>4</min-length> </parameter-name> </user-group> <user-group type="clerk"> <parameter-name ="loginname"> <max-length>16</max-length> <min-length>4</min-length> </parameter-name> <parameter-name ="password"> <max-length>12</max-length> <min-length>8</min-length> </parameter-name> </user-group>` </root>
so how write java stuff implements above rule. in advance.
read xml using 1 of known xml parsers. refer xml parsing java
as read through xml, can create info construction store rules. explained below. loop through each of "user-group" xml nodes in java program, create map implementation, can utilize hashmap, key - "clerk" value pojo bean defining "rule"
for illustration here "rules" class -
public class rules { private string rulename; private int maxlength; private int minlength; public string getrulename() { homecoming rulename; } public void setrulename(string rulename) { this.rulename = rulename; } public int getminlength() { homecoming minlength; } public void setminlength(int minlength) { this.minlength = minlength; } public void setmaxlength(int maxlength) { this.maxlength = maxlength; } public int getmaxlength() { homecoming maxlength; } }
now can utilize hashmap anywhere in program, implement rules. seems need implement rules on ui. in case, recommend using established frameworks struts, spring or equivalent framework.
hope gives headstart ;)
java
Comments
Post a Comment