1
2
3
4
5 package org.company.thesandbox.domain.businessrules;
6
7 import org.company.thesandbox.domain.Customer;
8 import org.springframework.validation.Errors;
9
10
11
12
13
14
15
16 public class OneEarDiscount extends OneEarDiscountImplBase {
17
18
19
20
21 public void validate(Object target, Errors errors) {
22
23 Customer cust = (Customer) target;
24 if (cust.getNumberOfEars() == 1 && cust.getDiscountPercentage() != 50) {
25 errors.rejectValue("discountPercentage", "businessrule.OneEarDiscount.not.valid", new Integer[] {
26 new Integer(50), new Integer(cust.getDiscountPercentage()) }, "discountPercentage"
27 + " for Customers with one ear should be " + 50 + ", but was " + cust.getDiscountPercentage());
28 }
29
30 }
31
32 }