All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.engine.form.Validation Maven / Gradle / Ivy

package com.xlrit.gears.engine.form;

import java.util.ArrayList;
import java.util.List;

import com.xlrit.gears.base.execution.Execution;
import com.xlrit.gears.engine.error.InputError;
import com.xlrit.gears.engine.error.InputErrorType;
import com.xlrit.gears.engine.error.InputException;

public class Validation {
	private final List errors = new ArrayList<>();

	public void addError(FormField field, Execution execution, Object value, InputErrorType type) {
		String rpath = field.getPath().toString(execution);
		this.errors.add(new InputError(field, rpath, value, type));
	}

	public void addError(FormField field, Execution execution, Object value, InputErrorType type, Throwable cause) {
		String rpath = field.getPath().toString(execution);
		this.errors.add(new InputError(field, rpath, value, type, cause));
	}

	public boolean isSuccess() {
		return errors.isEmpty();
	}

	public boolean isFailure() {
		return !errors.isEmpty();
	}

	public InputException toInputException() {
		if (errors.isEmpty()) return null;
		return new InputException(errors);
	}

	@Override
	public String toString() {
		return "Validation[" + errors.size() + " errors]";
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy