Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 1997-2013, www.tinygroup.org ([email protected]).
*
* Licensed under the GPL, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.tinygroup.validate.impl;
import org.tinygroup.beancontainer.BeanContainerFactory;
import org.tinygroup.i18n.I18nMessageFactory;
import org.tinygroup.i18n.I18nMessages;
import org.tinygroup.validate.ValidateResult;
import org.tinygroup.validate.Validator;
import org.tinygroup.validate.ValidatorManager;
import java.lang.reflect.Field;
import java.util.*;
import java.util.Map.Entry;
/**
* 字段与对应的校验器映射类
*
* @author renhui
*
*/
public class FieldValidatorMap {
private ValidatorManagerWrapper validatorManagerWrapper;
private I18nMessages i18nMessages = I18nMessageFactory.getI18nMessages();
public static final String TINY_DEFAULT_SCENE = "tiny_default";
public FieldValidatorMap() {
validatorManagerWrapper = BeanContainerFactory.getBeanContainer(
this.getClass().getClassLoader()).getBean(
ValidatorManagerWrapper.class);
}
private Map>> fieldSceneValidatorsMap = new HashMap>>();
void addValidator(FieldWrapper field, String scene, Validator validator) {
if (scene == null || "".equals(scene)) {
scene = TINY_DEFAULT_SCENE;
}
Map> sceneMap = fieldSceneValidatorsMap
.get(field);
if (sceneMap == null) {
sceneMap = new HashMap>();
fieldSceneValidatorsMap.put(field, sceneMap);
}
List validators = sceneMap.get(scene);
if (validators == null) {
validators = new ArrayList();
sceneMap.put(scene, validators);
}
if (validator != null) {// 20130605
// 为了支持对象嵌套而允许validator为空,使得可以添加对象的FieldWapper来占位,用于后面的嵌套调用
validators.add(validator);
}
}
void validator(String className, String scene, Object value,
ValidateResult result, List