|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+package se.citerus.dddsample.web.command;
|
|
|
2
|
+
|
|
|
3
|
+import org.apache.commons.lang.StringUtils;
|
|
|
4
|
+import org.apache.commons.logging.Log;
|
|
|
5
|
+import org.apache.commons.logging.LogFactory;
|
|
|
6
|
+import org.springframework.validation.Errors;
|
|
|
7
|
+import org.springframework.validation.Validator;
|
|
|
8
|
+
|
|
|
9
|
+/**
|
|
|
10
|
+ * Validator for {@link se.citerus.dddsample.web.command.TrackCommand}s.
|
|
|
11
|
+ */
|
|
|
12
|
+public class TrackCommandValidator implements Validator {
|
|
|
13
|
+
|
|
|
14
|
+ /**
|
|
|
15
|
+ * Logger for this class and subclasses
|
|
|
16
|
+ */
|
|
|
17
|
+ private final Log logger = LogFactory.getLog(getClass());
|
|
|
18
|
+
|
|
|
19
|
+ public boolean supports(Class clazz) {
|
|
|
20
|
+ return TrackCommand.class.isAssignableFrom(clazz);
|
|
|
21
|
+ }
|
|
|
22
|
+
|
|
|
23
|
+ public void validate(Object object, Errors errors) {
|
|
|
24
|
+ final TrackCommand command = (TrackCommand) object;
|
|
|
25
|
+
|
|
|
26
|
+ if (StringUtils.isEmpty(command.getTrackingId())) {
|
|
|
27
|
+ final String msg = "Illegal id!";
|
|
|
28
|
+ logger.warn(msg);
|
|
|
29
|
+ errors.rejectValue("trackingId", "track.illegal-id", msg);
|
|
|
30
|
+ }
|
|
|
31
|
+ }
|
|
|
32
|
+
|
|
|
33
|
+}
|
|
|
34
|
+
|