Search in sources :

Example 1 with IActionFieldsCheckUtils

use of com.netsteadfast.greenstep.base.model.IActionFieldsCheckUtils in project bamboobsc by billchen198318.

the class BaseSupportAction method checkFields.

@Deprecated
protected void checkFields(String[] fieldsName, String[] msg, Class<IActionFieldsCheckUtils>[] checkUtilsClass, String[] methodsName, List<String> fieldsId) throws ControllerException, InstantiationException, IllegalAccessException {
    if (fieldsName == null || msg == null || checkUtilsClass == null || (fieldsName.length != msg.length) || (fieldsName.length != checkUtilsClass.length)) {
        throw new java.lang.IllegalArgumentException("check filed args error!");
    }
    StringBuilder exceptionMsg = new StringBuilder();
    for (int i = 0; i < fieldsName.length; i++) {
        String value = this.getFields().get(fieldsName[i]);
        IActionFieldsCheckUtils checkUtils = checkUtilsClass[i].newInstance();
        if (methodsName != null && methodsName.length == checkUtilsClass.length) {
            Method[] methods = checkUtils.getClass().getMethods();
            for (Method method : methods) {
                if (method.getName().equals(methodsName[i])) {
                    try {
                        if (!(Boolean) method.invoke(null, value)) {
                            if (fieldsId != null) {
                                fieldsId.add(fieldsName[i]);
                            }
                            exceptionMsg.append(msg[i]);
                        }
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            }
        } else {
            if (!checkUtils.check(value)) {
                if (fieldsId != null) {
                    fieldsId.add(fieldsName[i]);
                }
                exceptionMsg.append(msg[i]);
            }
        }
    }
    if (exceptionMsg.length() > 0) {
        throw new ControllerException(exceptionMsg.toString());
    }
}
Also used : ControllerException(com.netsteadfast.greenstep.base.exception.ControllerException) Method(java.lang.reflect.Method) IActionFieldsCheckUtils(com.netsteadfast.greenstep.base.model.IActionFieldsCheckUtils) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ControllerException (com.netsteadfast.greenstep.base.exception.ControllerException)1 IActionFieldsCheckUtils (com.netsteadfast.greenstep.base.model.IActionFieldsCheckUtils)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1