Here is an example of my question:
1) I have an XML files where Rules for my Invoice are definded
<rules>
..
<price>
<Required>True</Required>
<MinValue>0.1</MinValue>
<price>
..
</rules>
2) I have an Invoice Object in java (important: this should stay so (plain). No annotations or anything should be included.)
public class Invoice implements Serializable {
private String details;
private String tax;
private String recipient;
private double price;
//getter and setter
}
3) And at least I have a Validator Object
public class Validator(){
public boolean validate(String xmlfile, Invoice i) {
//todo: Invoice i should be validated with xmlfile
}
}
What I need:
The Validator should take the XML File with the rules inside
e.g.
<price>
<Required>True</Required>
<MinValue>0.1</MinValue>
<price>
and use that rule to validate the Invoice java object.
Are there any good frameworks I could use for that? Or tutorials? Approaches?
Any help is really appreciated.
Thank you.
You can use Hibernate Validator which is implementation of JSR 303. You can write constrains in XML as below
A complete and nice tutorial can be found here