⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validationdelegatecomboimpl.java

📁 欢迎使用 FastJsp 开发框架! 编译说明: * 若要生成Api Javadoc文档
💻 JAVA
字号:
package com.onetsoft.fastjsp;

import com.onetsoft.fastjsp.util.StringUtils;
import com.onetsoft.fastjsp.valid.ValidationDelegate;
import com.onetsoft.fastjsp.valid.ValidationException;
import org.apache.commons.lang.ArrayUtils;

/* 
 * 组合验证代理
 * 用以为用户提供一致的验证代理界面
 * 此类的目的在于支持 {@link AbstractComponent#initialize()}中的{@link com.onetsoft.fastjsp.valid.ValidationException}
 * 不同于页面/组件确保全部执行初始化,方法{@link ActionsManager#execute(AbstractPageService)}在遇到验证错误即抛出
 */

 class ValidationDelegateComboImpl implements ValidationDelegate {
    private ValidationDelegate[] delegates = new ValidationDelegate[0];
    private int count = 0;

    public void addDelegate(ValidationDelegate delegate) {
        ensureConpacity();
        delegates[count++] = delegate;
    }

    private void ensureConpacity() {
        if (count == delegates.length) {
            ValidationDelegate[] b = new ValidationDelegate[count + 2];
            System.arraycopy(delegates, 0, b, 0, count);
            this.delegates = b;
        }
    }

    public boolean containsDelegate() {
        return count > 0;
    }

    public boolean isError() {
        for (int i = 0; i < count; i++) {
            if (delegates[i].isError()) return true;
        }
        return false;
    }

    public boolean isError(String field) {
        for (int i = 0; i < count; i++) {
            if (delegates[i].isError(field)) return true;
        }
        return false;
    }

    public String getMessage(String field) {
        for (int i = 0; i < count; i++) {
            String err = delegates[i].getMessage(field);
            if (err.length() != 0) return err;                  
        }
        return StringUtils.EMPTY;
    }

    public String[] getMessages() {
        String[] a = ArrayUtils.EMPTY_STRING_ARRAY;
        for (int i = 0; i < count; i++) {
            String[]  e = delegates[i].getMessages();
            if (e.length != 0) {
                if (a.length == 0) a = e;
                else {
                    String[] tmp = new String[a.length + e.length];
                    System.arraycopy(a, 0, tmp, 0, a.length);
                    System.arraycopy(e, 0, tmp, a.length, e.length);
                }
            }
        }
        return a;
    }


    public void validate() throws ValidationException {
        throw new UnsupportedOperationException();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -