Store Business Rules in XML Document, Validate afterwards in Java, how?
        Posted  
        
            by JavaPete
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by JavaPete
        
        
        
        Published on 2010-05-10T10:31:40Z
        Indexed on 
            2010/05/10
            10:34 UTC
        
        
        Read the original article
        Hit count: 225
        
Example XML Rules document:
<user>
  <username>
     <not-null/>
     <capitals value="false"/>
     <max-length value="15"/>
  </username>
  <email>
     <not-null/>
     <isEmail/>
     <max-length value="40"/>
  </email>
</user>
How do I implement this? I'm starting from scratch, what I currently have is a User-class, and a UserController which saves the User object in de DB (through a Service-layer and Dao-layer), basic Spring MVC. I can't use Spring MVC Validation however in our Model-classes, I have to use an XML document so an Admin can change the rules
I think I need a pattern which dynamically builds an algorithm based on what is provided by the XML Rules document, but I can't seem to think of anything other than a massive amount of if-statements.
I also have nothing for the parsing yet and I'm not sure how I'm gonna (de)couple it from the actual implementation of the validation-process.
© Stack Overflow or respective owner