changeset 537:f44c9e59f08c

Added validator for probe objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 24 Feb 2015 10:56:47 +0100
parents bf387959b75e
children fd927b584c54
files src/main/java/de/intevation/lada/validation/ProbeValidator.java
diffstat 1 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/ProbeValidator.java	Tue Feb 24 10:56:47 2015 +0100
@@ -0,0 +1,35 @@
+package de.intevation.lada.validation;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.annotation.ValidationConfig;
+import de.intevation.lada.validation.rules.Rule;
+
+@ValidationConfig(type="Probe")
+@ApplicationScoped
+public class ProbeValidator implements Validator {
+
+    @Inject
+    @ValidationRule("Probe")
+    private Instance<Rule> rules;
+
+    @Override
+    public Violation validate(Object object) {
+        Violation violations = new Violation();
+        for(Rule rule: rules) {
+            Violation result = rule.execute(object);
+            if (result != null) {
+                if (result.hasWarnings()) {
+                    violations.addWarnings(result.getWarnings());
+                }
+                if (result.hasErrors()) {
+                    violations.addErrors(result.getErrors());
+                }
+            }
+        }
+        return violations;
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)