* ["required",
* ["length min=10, max=100"]
*
*/
for (String validatorString : validatorsParts) {
ValidatorMetaData validatorMetaData = new ValidatorMetaData();
validatorMetaDataList.add(validatorMetaData);
/* Now we split one of the string (we will use length)
* as follows:
* parts=["length", "min=10", "max=100"]
* */
String[] parts = validatorString.trim().split("[ ,]");
/* The first part is the name of the validation,
* e.g., "length".
*
*/
validatorMetaData.setName(parts[0]);
/* If the string has more than one part, then there must
* be arguments as in: ["min=10", "max=100"]
*
* Parse the arguments and add them to the list as well.
*/
if (parts.length > 1) {
/* This line converts:
*
* ["length", "min=10", "max=100"]
*
* into:
*
* ["min=10", "max=100"]
*/
List<String> values =
Arrays.asList(parts).subList(1, parts.length);
/* For each value convert it into name value pairs. */
for (String value : values) {
if (value.indexOf("=") != -1) {
/* Split "min=10" into ["min", "10"] */
String[] valueParts = value.split("[=]");
/* Stick this value into validatorMetaData's
* list of properties.
*/
validatorMetaData.getProperties().put(
valueParts[0], valueParts[1]);
}
}
}
}