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

org.springmodules.validation.bean.rule.ValidationRule Maven / Gradle / Ivy

There is a newer version: 0.8a
Show newest version
/*
 * Copyright 2004-2005 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springmodules.validation.bean.rule;

import org.springmodules.validation.util.condition.Condition;

/**
 * Represents a validation rule. A validation rule binds an error to a condition.
 *
 * @author Uri Boness
 */
public interface ValidationRule {

    /**
     * Checks whether this validation is applicable on the given object. This can be used
     * to define applicability rules base on runtime factors.
     *
     * @param obj The object to be validated
     * @return True if this validation rule is applicable on the given obj, false otherwise.
     */
    boolean isApplicable(Object obj);

    /**
     * Returns the condition of this validation rule.
     *
     * @return The condition of this validation rule.
     */
    Condition getCondition();

    /**
     * Return the error code of this validation rule. This method cannot return null.
     *
     * @return The error code of this validation rule.
     */
    String getErrorCode();

    /**
     * Returns the arguments that apply to the error code of this validation rule. This
     * method should never return null. If there are no arguments, this method must return
     * an empty array. This method accepts the validated object, this enables runtime generation
     * of arguments based on that object.
     *
     * @param obj The validated object.
     * @return The arguments that apply to the error code of this validation rule.
     */
    Object[] getErrorArguments(Object obj);

    /**
     * Returns the default error message that can be used in case no error message is bound
     * to the error code of the rule. This method can return null to indicate that
     * no default message exists.
     *
     * @return The default error message of this validation rule.
     */
    String getDefaultErrorMessage();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy