br.com.anteros.bean.validation.ConstraintDefaults Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Anteros-Bean-Validation Show documentation
Show all versions of Anteros-Bean-Validation Show documentation
Anteros Bean Validation for Java.
/*******************************************************************************
* Copyright 2012 Anteros Tecnologia
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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 br.com.anteros.bean.validation;
import java.lang.annotation.Annotation;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import br.com.anteros.bean.validation.resource.messages.AnterosDefaultConstraints;
import br.com.anteros.core.log.LogLevel;
import br.com.anteros.core.log.Logger;
import br.com.anteros.core.log.LoggerProvider;
import br.com.anteros.validation.api.ConstraintValidator;
/**
* Description: Provides access to the default constraints/validator implementation classes built into the framework.
* These are configured in DefaultConstraints.properties.
*/
public class ConstraintDefaults {
private static final Logger log = LoggerProvider.getInstance().getLogger(ConstraintDefaults.class.getName());
/**
* The default constraint data stored herein.
*/
protected Map>[]> defaultConstraints;
/**
* Create a new ConstraintDefaults instance.
*/
public ConstraintDefaults() {
defaultConstraints = loadDefaultConstraints();
}
/**
* Get the default constraint data.
* @return String-keyed map
*/
public Map>[]> getDefaultConstraints() {
return defaultConstraints;
}
/**
* Get the default validator implementation types for the specified constraint annotation type.
* @param annotationType
* @return array of {@link ConstraintValidator} implementation classes
*/
@SuppressWarnings("unchecked")
public Class extends ConstraintValidator>[] getValidatorClasses(
Class annotationType) {
return (Class extends ConstraintValidator>[]) getDefaultConstraints().get(annotationType.getName());
}
@SuppressWarnings("unchecked")
private Map>[]> loadDefaultConstraints() {
Properties constraintProperties = AnterosDefaultConstraints.getConstraints();
final ClassLoader classloader = getClassLoader();
Map>[]> loadedConstraints
= new HashMap>[]>();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy