// Path: src/main/java/org/myazure/weixin/domain/entity/MaUserEntity.java
// public class MaUserEntity {
// 
// 	@NotEmpty
//     private Long id;
// 	
//     @NotEmpty
//     private String userName = "";
// 
//     private String password = "";
// 
//     private String passwordRepeated = "";
// 
//     @NotNull
//     private MaRole role = MaRole.USER;
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public String getPasswordRepeated() {
//         return passwordRepeated;
//     }
// 
//     public void setPasswordRepeated(String passwordRepeated) {
//         this.passwordRepeated = passwordRepeated;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/service/MaUserService.java
// public interface MaUserService {
// 
//     MaUser getMaUserById(long id);
// 
//     MaUser getMaUserByName(String name);
// 
//     Collection<MaUser> getAllMaUsers();
// 
//     MaUser create(MaUserEntity form);
// }


import org.myazure.weixin.domain.entity.MaUserEntity;
import org.myazure.weixin.service.MaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
package org.myazure.weixin.domain.validator;


/**
 * @author WangZhen
 */
@Component
public class MaUserFormValidator implements Validator {

    private final MaUserService userService;

    @Autowired
    public MaUserFormValidator(MaUserService userService) {
        this.userService = userService;
    }

    @Override
    public boolean supports(Class<?> clazz) {
        return clazz.equals(MaUserEntity.class);
    }

    @Override
    public void validate(Object target, Errors errors) {
        MaUserEntity form = (MaUserEntity) target;
        validatePasswords(errors, form);
        validateName(errors, form);
    }

    private void validatePasswords(Errors errors, MaUserEntity form) {
        if (!form.getPassword().equals(form.getPasswordRepeated())) {
            errors.rejectValue("password", "password", "Passwords do not match");
        }
    }

// Path: src/main/java/org/myazure/weixin/domain/entity/MaUserEntity.java
// public class MaUserEntity {
// 
// 	@NotEmpty
//     private Long id;
// 	
//     @NotEmpty
//     private String userName = "";
// 
//     private String password = "";
// 
//     private String passwordRepeated = "";
// 
//     @NotNull
//     private MaRole role = MaRole.USER;
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public String getPasswordRepeated() {
//         return passwordRepeated;
//     }
// 
//     public void setPasswordRepeated(String passwordRepeated) {
//         this.passwordRepeated = passwordRepeated;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/service/MaUserService.java
// public interface MaUserService {
// 
//     MaUser getMaUserById(long id);
// 
//     MaUser getMaUserByName(String name);
// 
//     Collection<MaUser> getAllMaUsers();
// 
//     MaUser create(MaUserEntity form);
// }


// Path: src/main/java/org/myazure/weixin/domain/validator/MaUserFormValidator.java
import org.myazure.weixin.domain.entity.MaUserEntity;
import org.myazure.weixin.service.MaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

package org.myazure.weixin.domain.validator;


/**
 * @author WangZhen
 */
@Component
public class MaUserFormValidator implements Validator {

    private final MaUserService userService;

    @Autowired
    public MaUserFormValidator(MaUserService userService) {
        this.userService = userService;
    }

    @Override
    public boolean supports(Class<?> clazz) {
        return clazz.equals(MaUserEntity.class);
    }

    @Override
    public void validate(Object target, Errors errors) {
        MaUserEntity form = (MaUserEntity) target;
        validatePasswords(errors, form);
        validateName(errors, form);
    }

    private void validatePasswords(Errors errors, MaUserEntity form) {
        if (!form.getPassword().equals(form.getPasswordRepeated())) {
            errors.rejectValue("password", "password", "Passwords do not match");
        }
    }

    private void validateName(Errors errors, MaUserEntity form) {