Package com.isomorphic.datasource

# Class Validator

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap
com.isomorphic.datasource.Validator

All Implemented Interfaces:
  `com.isomorphic.util.IDoNotAdapt`, `Serializable`, `Cloneable`, `Map`

public class Validator extends HashMap implements com.isomorphic.util.IDoNotAdapt
Server-side representation of a Validator.

Contains accessors for all documented Validator properties and a general getProperty() API for retrieving your own properties for custom DataSource implementations.

See Also:
  - Serialized Form

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addErrorMessageVariable(String name, String value)`
  Adds a variable to the context used when building error messages for this Validator.
  `ErrorMessage`
  `evaluateErrorMessage(ErrorMessage error)`
  Returns the evaluated form of the passed in error message, applying any error message variables that have been assigned to this validator.
  `String`
  `getErrorMessage()`
  Returns the error message
  `Map`
  `getErrorMessageVariables()`
  Retrieves the current map of error message variables for this Validator
  `String`
  `getLanguage()`
  Returns language property, which is script language of serverCondition expression that will be executed by the server.
  `List`
  `getListProperty(String property)`
  Returns the value of the specified attribute as a List.
  `Map`
  `getMapProperty(String property)`
  Returns the value of the specified attribute as a Map.
  `Object`
  `getObjectProperty(String property)`
  Returns the value of the specified element(s) as an Object.
  `String`
  `getProperty(String property)`
  Returns the value of the specified attribute as a string.
  `Object`
  `getScriptImports()`
  Returns script imports, which are used by script defined in serverCondition expression that will be executed by the server.
  `String`
  `getServerCondition()`
  Returns the server condition, which is an expression that will be executed by the server.
  `String`
  `getType()`
  Returns the Validator type
  `boolean`
  `isClientOnly()`
  Returns whether this Validator is intended to run only on the client
  `boolean`
  `isServerOnly()`
  Returns whether this Validator is intended to run only on the server
  `boolean`
  `isStopIfFalse()`
  Returns true if validation should stop if this Validator fails.

- ## Method Details

  - ### getProperty

    public String getProperty(String property)
    Returns the value of the specified attribute as a string.
    Parameters:
      `property` - the name of the attribute
    Returns:
      the value of the specified attribute as a string
    See Also:
      - `getObjectProperty(java.lang.String)`
      - `getListProperty(java.lang.String)`
      - `getMapProperty(java.lang.String)`

  - ### getObjectProperty

    public Object getObjectProperty(String property)
    Returns the value of the specified element(s) as an Object.

    Custom XML is transformed to Strings or Java collections by the following rules:

    - Elements with just text (no child elements or attributes) become Strings
    - Elements with child elements or attributes become Maps containing data derived from their subelements
    - Repeating elements (more than one of the same name at the same level) become Lists

    Sample XML:

    - Map

      `<validator>
      <mapCustomProperty key1="value1" key2="value2" />
      </validator>`

    - List of String

      `<validator>
      <listCustomProperty>ListElement1</listCustomProperty>
      <listCustomProperty>ListElement2</listCustomProperty> </validator>`

    - List of Map

      `<validator>
      <mapCustomProperty key1="value1" key2="value2" />
      <mapCustomProperty key1="value1" key2="value2" />
      </validator>`

    Parameters:
      `property` - the name of the element(s)
    Returns:
      the value of the specified element(s) as an Object
    See Also:
      - `getProperty(java.lang.String)`
      - `getListProperty(java.lang.String)`
      - `getMapProperty(java.lang.String)`

  - ### getListProperty

    public List getListProperty(String property)
    Returns the value of the specified attribute as a List.
    Parameters:
      `property` - the name of the attribute
    Returns:
      the value of the specified attribute as a List
    Throws:
      `ClassCastException` - if requested property is not instanceof List
    See Also:
      - `getProperty(java.lang.String)`
      - `getObjectProperty(java.lang.String)`
      - `getMapProperty(java.lang.String)`

  - ### getMapProperty

    public Map getMapProperty(String property)
    Returns the value of the specified attribute as a Map.
    Parameters:
      `property` - the name of the attribute
    Returns:
      the value of the specified attribute as a Map
    Throws:
      `ClassCastException` - if requested property is not instanceof Map
    See Also:
      - `getProperty(java.lang.String)`
      - `getObjectProperty(java.lang.String)`
      - `getListProperty(java.lang.String)`

  - ### isClientOnly

    public boolean isClientOnly()
    Returns whether this Validator is intended to run only on the client
    Returns:
      whether this Validator is intended to run only on the client

  - ### isServerOnly

    public boolean isServerOnly()
    Returns whether this Validator is intended to run only on the server
    Returns:
      whether this Validator is intended to run only on the server

  - ### isStopIfFalse

    public boolean isStopIfFalse()
    Returns true if validation should stop if this Validator fails. Ordinarily, all Validators for a given field run, even if one has already failed.
    Returns:
      true if validation should stop if this Validator fails

  - ### getErrorMessage

    public String getErrorMessage()
    Returns the error message
    Returns:
      the error message

  - ### getServerCondition

    public String getServerCondition()
    Returns the server condition, which is an expression that will be executed by the server. Script language can be defined via language property, otherwise system-wide script.validator.defaultLanguage setting will be used.
    Returns:
      the server condition

  - ### getScriptImports

    public Object getScriptImports()
    Returns script imports, which are used by script defined in serverCondition expression that will be executed by the server.
    Returns:
      the server condition

  - ### getLanguage

    public String getLanguage()
    Returns language property, which is script language of serverCondition expression that will be executed by the server.
    Returns:
      the server condition

  - ### getType

    public String getType()
    Returns the Validator type
    Returns:
      the validator type

  - ### addErrorMessageVariable

    public void addErrorMessageVariable(String name, String value)
    Adds a variable to the context used when building error messages for this Validator.
    Parameters:
      `name` - the name to give the variable in the context
      `value` - the value to associate with the variable

  - ### getErrorMessageVariables

    public Map getErrorMessageVariables()
    Retrieves the current map of error message variables for this Validator
    Returns:
      The Map of error message variables

  - ### evaluateErrorMessage

    public ErrorMessage evaluateErrorMessage(ErrorMessage error) throws Exception
    Returns the evaluated form of the passed in error message, applying any error message variables that have been assigned to this validator.
    Parameters:
      `error` - The message text to evaluate
    Returns:
      The evaluated error message (it is the same object as was passed in)
    Throws:
      `Exception`