Package org.eweb4j.mvc.config.creator

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

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.ValidatorConstant;
import org.eweb4j.mvc.validator.annotation.SizeVal;


public class SizeImpl implements ValidatorCreator {

  private SizeVal ann;

  public SizeImpl(SizeVal ann) {
    this.ann = ann;
  }

  public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
      return null;
    if (val == null || !ValidatorConstant.INT_SIZE_VAL.equals(val.getName())) {
      val = new ValidatorConfigBean();
      val.setName(ValidatorConstant.INT_SIZE_VAL);
    }

    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(ann.mess());
   
    ParamConfigBean pcb = new ParamConfigBean();
    pcb.setName(ValidatorConstant.MIN_SIZE_PARAM);
    pcb.setValue(String.valueOf(ann.min()));
   
    fcb.getParam().add(pcb);
   
    ParamConfigBean pcb2 = new ParamConfigBean();
    pcb2.setName(ValidatorConstant.MAX_SIZE_PARAM);
    pcb2.setValue(String.valueOf(ann.max()));
   
    fcb.getParam().add(pcb2);

    val.getField().add(fcb);

    return val;
  }

}
TOP

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

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.