Update of /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/validator
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1995/metadata/src/java/org/hibernate/validator
Modified Files:
ClassValidator.java
Log Message:
ANN-256
and warning suppression
Index: ClassValidator.java
===================================================================
RCS file: /cvsroot/hibernate/HibernateExt/metadata/src/java/org/hibernate/validator/ClassValidator.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ClassValidator.java 11 Feb 2006 01:04:02 -0000 1.19
+++ ClassValidator.java 17 Feb 2006 10:57:59 -0000 1.20
@@ -25,6 +25,7 @@
import java.util.ResourceBundle;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -86,12 +87,32 @@
private ResourceBundle getDefaultResourceBundle() {
ResourceBundle rb;
try {
- rb = ResourceBundle.getBundle( "ValidatorMessages" );
+ //use context class loader as a first citizen
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ if (contextClassLoader == null) {
+ throw new MissingResourceException("No context classloader", null, "ValidatorMessage");
+ }
+ rb = ResourceBundle.getBundle(
+ "ValidatorMessages",
+ Locale.getDefault(),
+ contextClassLoader
+ );
}
catch( MissingResourceException e) {
- //the user did not override the default ValidatorMessages
- log.debug( "ResourceBundle ValidatorMessages not found. Delegate to " + DEFAULT_VALIDATOR_MESSAGE);
- rb = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
+ log.trace( "ResourceBundle ValidatorMessages not found in thread context classloader");
+ //then use the Validator Framework classloader
+ try {
+ rb = ResourceBundle.getBundle(
+ "ValidatorMessages",
+ Locale.getDefault(),
+ this.getClass().getClassLoader()
+ );
+ }
+ catch( MissingResourceException ee) {
+ log.debug( "ResourceBundle ValidatorMessages not found in Validator classloader. Delegate to " + DEFAULT_VALIDATOR_MESSAGE);
+ //the user did not override the default ValidatorMessages
+ rb = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
+ }
}
defaultResourceBundle = true;
return rb;
@@ -148,6 +169,7 @@
}
}
+ @SuppressWarnings("unchecked")
private void createChildValidator(ResourceBundle resourceBundle, Member member, Class clazz) {
if ( ( (AnnotatedElement) member ).isAnnotationPresent( Valid.class ) ) {
setAccessible( member );
@@ -177,14 +199,7 @@
}
}
-// private static final Set<String> methodNames = new HashSet<String>();
-// static {
-// methodNames.add("toString");
-// methodNames.add("hashCode");
-// methodNames.add("equals");
-// methodNames.add("annotationType");
-// }
-
+ @SuppressWarnings("unchecked")
private Validator createValidator(Annotation annotation) {
try {
ValidatorClass validatorClass = annotation.annotationType().getAnnotation( ValidatorClass.class );
@@ -221,6 +236,7 @@
* apply constraints on a bean instance and return all the failures.
* if <code>bean</code> is null, an empty array is returned
*/
+ @SuppressWarnings("unchecked")
protected InvalidValue[] getInvalidValues(T bean, Set<Object> circularityState) {
if ( bean == null || circularityState.contains( bean ) ) {
return EMPTY_INVALID_VALUE_ARRAY; //Avoid circularity
@@ -273,6 +289,7 @@
return results.toArray( new InvalidValue[results.size()] );
}
+ @SuppressWarnings("unchecked")
private ClassValidator getClassValidator(Object value) {
Class clazz = value.getClass();
ClassValidator validator = childClassValidators.get( clazz );
@@ -418,15 +435,13 @@
*/
public void apply(PersistentClass persistentClass) {
- Iterator<Validator> validators = beanValidators.iterator();
- while ( validators.hasNext() ) {
- Validator validator = validators.next();
+ for ( Validator validator : beanValidators ) {
if ( validator instanceof PersistentClassConstraint ) {
( (PersistentClassConstraint) validator ).apply( persistentClass );
}
}
- validators = memberValidators.iterator();
+ Iterator<Validator> validators = memberValidators.iterator();
Iterator<Member> getters = memberGetters.iterator();
while ( validators.hasNext() ) {
Validator validator = validators.next();
|