Author: michiel
Date: 2010-02-09 15:38:27 +0100 (Tue, 09 Feb 2010)
New Revision: 40936

Added:
   
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/MustBeTrueDataType.java
Log:
  MMB-1929

Added: 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/MustBeTrueDataType.java
===================================================================
--- 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/MustBeTrueDataType.java
                          (rev 0)
+++ 
mmbase/branches/MMBase-1_9/core/src/main/java/org/mmbase/datatypes/MustBeTrueDataType.java
  2010-02-09 14:38:27 UTC (rev 40936)
@@ -0,0 +1,69 @@
+/*
+
+This software is OSI Certified Open Source Software.
+OSI Certified is a certification mark of the Open Source Initiative.
+
+The license (Mozilla version 1.0) can be read at the MMBase site.
+See http://www.MMBase.org/license
+
+*/
+package org.mmbase.datatypes;
+import org.mmbase.bridge.*;
+import org.mmbase.util.*;
+import java.util.*;
+import org.mmbase.util.logging.*;
+/**
+ * A boolean datatype of which the value must be true. The
+ * default value can be false though. This makes it possible to make
+ * an input checkbox that the user must check. ("I agree").
+ *
+ * @author Michiel Meeuwissen
+ * @version $Id: BooleanDataType.java 35587 2009-06-02 21:57:49Z michiel $
+ * @since MMBase-1.9.3
+ */
+public class MustBeTrueDataType extends BooleanDataType {
+
+    private static final Logger LOG = 
Logging.getLoggerInstance(MustBeTrueDataType.class);
+
+    private static final long serialVersionUID = 1L;
+
+    protected ValueRestriction  valueRestriction =  new 
ValueRestriction(Boolean.TRUE);
+
+    /**
+     * Constructor for a boolean datatype (either a primitive boolean type or 
the Boolean class).
+     *
+     * @param name the name of the data type
+     */
+    public MustBeTrueDataType(String name) {
+        super(name, false);
+    }
+
+    @Override
+    protected Collection<LocalizedString> 
validateCastValue(Collection<LocalizedString> errors, Object castValue, Object 
value, Node node, Field field) {
+        LOG.debug("Validating " + castValue);
+        errors = super.validateCastValue(errors, castValue, value,  node, 
field);
+        errors = valueRestriction.validate(errors, castValue, node, field);
+        return errors;
+    }
+
+
+    protected class ValueRestriction extends AbstractRestriction<Boolean> {
+        private static final long serialVersionUID = 0L;
+        ValueRestriction(ValueRestriction source) {
+            super(source);
+        }
+        ValueRestriction(Boolean b) {
+            super("value", b);
+            setEnforceStrength(DataType.ENFORCE_ALWAYS);
+        }
+
+        @Override
+        protected boolean simpleValid(final Object v, final Node node, final 
Field field) {
+            return Boolean.valueOf(Casting.toBoolean(v)).equals(getValue());
+        }
+    }
+
+
+
+
+}

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to