1
2
3
4 package org.company.thesandbox.domain;
5
6 import org.mod4j.runtime.validation.BusinessRuleValidationSupport;
7
8 import java.util.Collections;
9 import java.util.Set;
10 import java.util.HashSet;
11 import org.mod4j.runtime.validation.MinValueValidator;
12 import org.mod4j.runtime.validation.MaxValueValidator;
13 import org.mod4j.runtime.validation.MinLengthValidator;
14 import org.mod4j.runtime.validation.MaxLengthValidator;
15 import org.mod4j.runtime.validation.RegExpValidator;
16
17
18
19
20
21
22
23 @SuppressWarnings("serial")
24 public abstract class PersonImplBase implements java.io.Serializable {
25
26
27
28
29
30 protected BusinessRuleValidationSupport validation = new BusinessRuleValidationSupport(this);
31
32
33
34
35 private long id;
36
37 @SuppressWarnings("unused")
38 private int version = -1;
39
40
41
42
43
44 public Long getId() {
45 return this.id;
46 }
47
48
49
50
51 private String firstName;
52
53
54
55
56 private String lastName;
57
58
59
60
61 private Integer age;
62
63
64
65
66 private int numberOfEars = 0;
67
68 public static final int NUMBEROFEARS_MINVALUE = 0;
69
70 public static final int NUMBEROFEARS_MAXVALUE = 4;
71
72
73
74
75 private Sexe sexe;
76
77
78
79
80 protected PersonImplBase() {
81
82 }
83
84
85
86
87
88
89
90
91
92 public PersonImplBase(String firstName, String lastName) {
93
94 this.firstName = firstName;
95 this.lastName = lastName;
96
97 validation.addValidator(new MinValueValidator(Person.class, "numberOfEars", NUMBEROFEARS_MINVALUE));
98
99 validation.addValidator(new MaxValueValidator(Person.class, "numberOfEars", NUMBEROFEARS_MAXVALUE));
100
101 validation.validate();
102 }
103
104
105
106
107
108 public String getFirstName() {
109 return this.firstName;
110 }
111
112
113
114
115
116 public String getLastName() {
117 return this.lastName;
118 }
119
120
121
122
123
124 public Integer getAge() {
125 return this.age;
126 }
127
128
129
130
131
132 public int getNumberOfEars() {
133 return this.numberOfEars;
134 }
135
136
137
138
139
140 public Sexe getSexe() {
141 return this.sexe;
142 }
143
144
145
146
147
148 public void setFirstName(final String firstName) {
149 this.firstName = firstName;
150 validation.validate();
151 }
152
153
154
155
156
157 public void setLastName(final String lastName) {
158 this.lastName = lastName;
159 validation.validate();
160 }
161
162
163
164
165
166 public void setAge(final Integer age) {
167 this.age = age;
168 validation.validate();
169 }
170
171
172
173
174
175 public void setNumberOfEars(final int numberOfEars) {
176 this.numberOfEars = numberOfEars;
177 validation.validate();
178 }
179
180
181
182
183
184 public void setSexe(final Sexe sexe) {
185 this.sexe = sexe;
186 validation.validate();
187 }
188
189
190
191
192
193
194
195
196 public void activateValidation(boolean value) {
197
198 this.validation.setActive(value);
199 if (value) {
200 validation.validate();
201 }
202 }
203
204 }