extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/ValueValidator.java

Code
Comments
Other
Rev Date Author Line
6200 08 Apr 21 nicklas 1 package net.sf.basedb.reggie.plugins.cmd;
6200 08 Apr 21 nicklas 2
6201 09 Apr 21 nicklas 3 import net.sf.basedb.core.DbControl;
6200 08 Apr 21 nicklas 4
6200 08 Apr 21 nicklas 5 /**
6200 08 Apr 21 nicklas 6   Validation and convertion of values.
6200 08 Apr 21 nicklas 7   @since 4.32
6200 08 Apr 21 nicklas 8 */
6200 08 Apr 21 nicklas 9 public interface ValueValidator<F, T>
6200 08 Apr 21 nicklas 10 {
6200 08 Apr 21 nicklas 11
6200 08 Apr 21 nicklas 12   /**
6200 08 Apr 21 nicklas 13     The expected class of the value when extracted from
6200 08 Apr 21 nicklas 14     the JSON file. Typically this can be String, Long or 
6200 08 Apr 21 nicklas 15     Double. Some validator may find it more useful to use
6200 08 Apr 21 nicklas 16     Number or Object.
6200 08 Apr 21 nicklas 17   */
6200 08 Apr 21 nicklas 18   public  Class<F> getExpectedClass();
6200 08 Apr 21 nicklas 19   
6200 08 Apr 21 nicklas 20   /**
6200 08 Apr 21 nicklas 21     Check if the value is valid. Errors should be reported
6200 08 Apr 21 nicklas 22     to the JsonSection. The entryKey is provided to specify
6200 08 Apr 21 nicklas 23     the entry where the value is taken from. The value
6200 08 Apr 21 nicklas 24     is never null when this method is called.
6200 08 Apr 21 nicklas 25   */
6201 09 Apr 21 nicklas 26   public T isValid(DbControl dc, F value, JsonSection section, String entryKey);
6200 08 Apr 21 nicklas 27   
6955 12 Dec 22 nicklas 28   /**
6955 12 Dec 22 nicklas 29     Pre-process the value from the JSON file. This method is called before validation
6955 12 Dec 22 nicklas 30     even if the value is null or of a different class than the exepected class.
6955 12 Dec 22 nicklas 31     The default implementation return the value unmodified.
6955 12 Dec 22 nicklas 32     @since 4.41.2
6955 12 Dec 22 nicklas 33   */
6955 12 Dec 22 nicklas 34   public default Object preProcess(DbControl dc, Object value, JsonSection section, String entryKey)
6955 12 Dec 22 nicklas 35   {
6955 12 Dec 22 nicklas 36     return value;
6955 12 Dec 22 nicklas 37   }
6955 12 Dec 22 nicklas 38
6200 08 Apr 21 nicklas 39 }