Package org.eweb4j.mvc.config.creator

Source Code of org.eweb4j.mvc.config.creator.MyValidatorImpl

package org.eweb4j.mvc.config.creator;

import org.eweb4j.mvc.config.bean.FieldConfigBean;
import org.eweb4j.mvc.config.bean.ParamConfigBean;
import org.eweb4j.mvc.config.bean.ValidatorConfigBean;
import org.eweb4j.mvc.validator.annotation.MyValidator;


public class MyValidatorImpl implements ValidatorCreator {

  private MyValidator ann;

  public MyValidatorImpl(MyValidator ann) {
    this.ann = ann;
  }

  public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
      return null;
    Class<?> clazz = this.ann.clazz();
    String valName = clazz.getSimpleName();
    if (val == null || !valName.equals(val.getName())) {
      val = new ValidatorConfigBean();
      val.setName(valName);
      val.setClazz(clazz.getName());
    }

    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(ann.mess());
    String[] params = ann.params();
    String[] values = ann.values();
    if (params.length > 0 && values.length > 0 && params.length == values.length){
      for (int i = 0; i < params.length; i++){
        ParamConfigBean pcb = new ParamConfigBean();
        pcb.setName(params[i]);
        pcb.setValue(values[i]);
        fcb.getParam().add(pcb);
      }
    }
   

    val.getField().add(fcb);

    return val;
  }

}
TOP

Related Classes of org.eweb4j.mvc.config.creator.MyValidatorImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.