Eliminate warnings in .validation package

Issue: SPR-8062

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4103 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Chris Beams 2011-03-18 06:47:12 +00:00
parent ea5f28a8fd
commit d1c5bb0160
18 changed files with 52 additions and 41 deletions

View File

@ -39,7 +39,7 @@ public interface PropertyEditorRegistry {
* @param requiredType the type of the property * @param requiredType the type of the property
* @param propertyEditor the editor to register * @param propertyEditor the editor to register
*/ */
void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor); void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor);
/** /**
* Register the given custom property editor for the given type and * Register the given custom property editor for the given type and
@ -64,7 +64,7 @@ public interface PropertyEditorRegistry {
* <code>null</code> if registering an editor for all properties of the given type * <code>null</code> if registering an editor for all properties of the given type
* @param propertyEditor editor to register * @param propertyEditor editor to register
*/ */
void registerCustomEditor(Class requiredType, String propertyPath, PropertyEditor propertyEditor); void registerCustomEditor(Class<?> requiredType, String propertyPath, PropertyEditor propertyEditor);
/** /**
* Find a custom property editor for the given type and property. * Find a custom property editor for the given type and property.
@ -74,6 +74,6 @@ public interface PropertyEditorRegistry {
* <code>null</code> if looking for an editor for all properties of the given type * <code>null</code> if looking for an editor for all properties of the given type
* @return the registered editor, or <code>null</code> if none * @return the registered editor, or <code>null</code> if none
*/ */
PropertyEditor findCustomEditor(Class requiredType, String propertyPath); PropertyEditor findCustomEditor(Class<?> requiredType, String propertyPath);
} }

View File

@ -41,6 +41,7 @@ import org.springframework.util.StringUtils;
* @since 2.0 * @since 2.0
* @see Errors * @see Errors
*/ */
@SuppressWarnings("serial")
public abstract class AbstractBindingResult extends AbstractErrors implements BindingResult, Serializable { public abstract class AbstractBindingResult extends AbstractErrors implements BindingResult, Serializable {
private final String objectName; private final String objectName;
@ -131,7 +132,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
} }
public String[] resolveMessageCodes(String errorCode, String field) { public String[] resolveMessageCodes(String errorCode, String field) {
Class fieldType = getFieldType(field); Class<?> fieldType = getFieldType(field);
return getMessageCodesResolver().resolveMessageCodes( return getMessageCodesResolver().resolveMessageCodes(
errorCode, getObjectName(), fixedField(field), fieldType); errorCode, getObjectName(), fixedField(field), fieldType);
} }
@ -237,7 +238,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
* @see #getActualFieldValue * @see #getActualFieldValue
*/ */
@Override @Override
public Class getFieldType(String field) { public Class<?> getFieldType(String field) {
Object value = getActualFieldValue(fixedField(field)); Object value = getActualFieldValue(fixedField(field));
if (value != null) { if (value != null) {
return value.getClass(); return value.getClass();
@ -286,10 +287,10 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
* {@link #getPropertyEditorRegistry() PropertyEditorRegistry}'s * {@link #getPropertyEditorRegistry() PropertyEditorRegistry}'s
* editor lookup facility, if available. * editor lookup facility, if available.
*/ */
public PropertyEditor findEditor(String field, Class valueType) { public PropertyEditor findEditor(String field, Class<?> valueType) {
PropertyEditorRegistry editorRegistry = getPropertyEditorRegistry(); PropertyEditorRegistry editorRegistry = getPropertyEditorRegistry();
if (editorRegistry != null) { if (editorRegistry != null) {
Class valueTypeToUse = valueType; Class<?> valueTypeToUse = valueType;
if (valueTypeToUse == null) { if (valueTypeToUse == null) {
valueTypeToUse = getFieldType(field); valueTypeToUse = getFieldType(field);
} }

View File

@ -33,6 +33,7 @@ import org.springframework.util.StringUtils;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 2.5.3 * @since 2.5.3
*/ */
@SuppressWarnings("serial")
public abstract class AbstractErrors implements Errors, Serializable { public abstract class AbstractErrors implements Errors, Serializable {
private String nestedPath = ""; private String nestedPath = "";
@ -146,8 +147,8 @@ public abstract class AbstractErrors implements Errors, Serializable {
} }
public ObjectError getGlobalError() { public ObjectError getGlobalError() {
List globalErrors = getGlobalErrors(); List<ObjectError> globalErrors = getGlobalErrors();
return (!globalErrors.isEmpty() ? (ObjectError) globalErrors.get(0) : null); return (!globalErrors.isEmpty() ? globalErrors.get(0) : null);
} }
public boolean hasFieldErrors() { public boolean hasFieldErrors() {
@ -159,8 +160,8 @@ public abstract class AbstractErrors implements Errors, Serializable {
} }
public FieldError getFieldError() { public FieldError getFieldError() {
List fieldErrors = getFieldErrors(); List<FieldError> fieldErrors = getFieldErrors();
return (!fieldErrors.isEmpty() ? (FieldError) fieldErrors.get(0) : null); return (!fieldErrors.isEmpty() ? fieldErrors.get(0) : null);
} }
public boolean hasFieldErrors(String field) { public boolean hasFieldErrors(String field) {
@ -184,12 +185,12 @@ public abstract class AbstractErrors implements Errors, Serializable {
} }
public FieldError getFieldError(String field) { public FieldError getFieldError(String field) {
List fieldErrors = getFieldErrors(field); List<FieldError> fieldErrors = getFieldErrors(field);
return (!fieldErrors.isEmpty() ? (FieldError) fieldErrors.get(0) : null); return (!fieldErrors.isEmpty() ? (FieldError) fieldErrors.get(0) : null);
} }
public Class getFieldType(String field) { public Class<?> getFieldType(String field) {
Object value = getFieldValue(field); Object value = getFieldValue(field);
if (value != null) { if (value != null) {
return value.getClass(); return value.getClass();

View File

@ -39,6 +39,7 @@ import org.springframework.util.Assert;
* @see org.springframework.beans.PropertyAccessor * @see org.springframework.beans.PropertyAccessor
* @see org.springframework.beans.ConfigurablePropertyAccessor * @see org.springframework.beans.ConfigurablePropertyAccessor
*/ */
@SuppressWarnings("serial")
public abstract class AbstractPropertyBindingResult extends AbstractBindingResult { public abstract class AbstractPropertyBindingResult extends AbstractBindingResult {
private ConversionService conversionService; private ConversionService conversionService;
@ -85,7 +86,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul
* @see #getPropertyAccessor() * @see #getPropertyAccessor()
*/ */
@Override @Override
public Class getFieldType(String field) { public Class<?> getFieldType(String field) {
return getPropertyAccessor().getPropertyType(fixedField(field)); return getPropertyAccessor().getPropertyType(fixedField(field));
} }
@ -133,7 +134,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul
* @return the custom PropertyEditor, or <code>null</code> * @return the custom PropertyEditor, or <code>null</code>
*/ */
protected PropertyEditor getCustomEditor(String fixedField) { protected PropertyEditor getCustomEditor(String fixedField) {
Class targetType = getPropertyAccessor().getPropertyType(fixedField); Class<?> targetType = getPropertyAccessor().getPropertyType(fixedField);
PropertyEditor editor = getPropertyAccessor().findCustomEditor(targetType, fixedField); PropertyEditor editor = getPropertyAccessor().findCustomEditor(targetType, fixedField);
if (editor == null) { if (editor == null) {
editor = BeanUtils.findEditorByConvention(targetType); editor = BeanUtils.findEditorByConvention(targetType);
@ -146,8 +147,8 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul
* if applicable. * if applicable.
*/ */
@Override @Override
public PropertyEditor findEditor(String field, Class valueType) { public PropertyEditor findEditor(String field, Class<?> valueType) {
Class valueTypeForLookup = valueType; Class<?> valueTypeForLookup = valueType;
if (valueTypeForLookup == null) { if (valueTypeForLookup == null) {
valueTypeForLookup = getFieldType(field); valueTypeForLookup = getFieldType(field);
} }

View File

@ -40,6 +40,7 @@ import org.springframework.util.Assert;
* @see DataBinder#initBeanPropertyAccess() * @see DataBinder#initBeanPropertyAccess()
* @see DirectFieldBindingResult * @see DirectFieldBindingResult
*/ */
@SuppressWarnings("serial")
public class BeanPropertyBindingResult extends AbstractPropertyBindingResult implements Serializable { public class BeanPropertyBindingResult extends AbstractPropertyBindingResult implements Serializable {
private final Object target; private final Object target;

View File

@ -40,6 +40,7 @@ import org.springframework.util.Assert;
* @see DataBinder#getBindingResult() * @see DataBinder#getBindingResult()
* @see DataBinder#close() * @see DataBinder#close()
*/ */
@SuppressWarnings("serial")
public class BindException extends Exception implements BindingResult { public class BindException extends Exception implements BindingResult {
private final BindingResult bindingResult; private final BindingResult bindingResult;
@ -134,7 +135,7 @@ public class BindException extends Exception implements BindingResult {
return this.bindingResult.getErrorCount(); return this.bindingResult.getErrorCount();
} }
public List getAllErrors() { public List<ObjectError> getAllErrors() {
return this.bindingResult.getAllErrors(); return this.bindingResult.getAllErrors();
} }
@ -146,7 +147,7 @@ public class BindException extends Exception implements BindingResult {
return this.bindingResult.getGlobalErrorCount(); return this.bindingResult.getGlobalErrorCount();
} }
public List getGlobalErrors() { public List<ObjectError> getGlobalErrors() {
return this.bindingResult.getGlobalErrors(); return this.bindingResult.getGlobalErrors();
} }
@ -162,7 +163,7 @@ public class BindException extends Exception implements BindingResult {
return this.bindingResult.getFieldErrorCount(); return this.bindingResult.getFieldErrorCount();
} }
public List getFieldErrors() { public List<FieldError> getFieldErrors() {
return this.bindingResult.getFieldErrors(); return this.bindingResult.getFieldErrors();
} }
@ -178,7 +179,7 @@ public class BindException extends Exception implements BindingResult {
return this.bindingResult.getFieldErrorCount(field); return this.bindingResult.getFieldErrorCount(field);
} }
public List getFieldErrors(String field) { public List<FieldError> getFieldErrors(String field) {
return this.bindingResult.getFieldErrors(field); return this.bindingResult.getFieldErrors(field);
} }
@ -190,7 +191,7 @@ public class BindException extends Exception implements BindingResult {
return this.bindingResult.getFieldValue(field); return this.bindingResult.getFieldValue(field);
} }
public Class getFieldType(String field) { public Class<?> getFieldType(String field) {
return this.bindingResult.getFieldType(field); return this.bindingResult.getFieldType(field);
} }
@ -206,6 +207,7 @@ public class BindException extends Exception implements BindingResult {
return this.bindingResult.getRawFieldValue(field); return this.bindingResult.getRawFieldValue(field);
} }
@SuppressWarnings("rawtypes")
public PropertyEditor findEditor(String field, Class valueType) { public PropertyEditor findEditor(String field, Class valueType) {
return this.bindingResult.findEditor(field, valueType); return this.bindingResult.findEditor(field, valueType);
} }

View File

@ -94,7 +94,7 @@ public interface BindingResult extends Errors {
* is given but should be specified in any case for consistency checking) * is given but should be specified in any case for consistency checking)
* @return the registered editor, or <code>null</code> if none * @return the registered editor, or <code>null</code> if none
*/ */
PropertyEditor findEditor(String field, Class valueType); PropertyEditor findEditor(String field, Class<?> valueType);
/** /**
* Return the underlying PropertyEditorRegistry. * Return the underlying PropertyEditorRegistry.

View File

@ -36,7 +36,7 @@ public abstract class BindingResultUtils {
* @return the BindingResult, or <code>null</code> if none found * @return the BindingResult, or <code>null</code> if none found
* @throws IllegalStateException if the attribute found is not of type BindingResult * @throws IllegalStateException if the attribute found is not of type BindingResult
*/ */
public static BindingResult getBindingResult(Map model, String name) { public static BindingResult getBindingResult(Map<?, ?> model, String name) {
Assert.notNull(model, "Model map must not be null"); Assert.notNull(model, "Model map must not be null");
Assert.notNull(name, "Name must not be null"); Assert.notNull(name, "Name must not be null");
Object attr = model.get(BindingResult.MODEL_KEY_PREFIX + name); Object attr = model.get(BindingResult.MODEL_KEY_PREFIX + name);
@ -53,7 +53,7 @@ public abstract class BindingResultUtils {
* @return the BindingResult (never <code>null</code>) * @return the BindingResult (never <code>null</code>)
* @throws IllegalStateException if no BindingResult found * @throws IllegalStateException if no BindingResult found
*/ */
public static BindingResult getRequiredBindingResult(Map model, String name) { public static BindingResult getRequiredBindingResult(Map<?, ?> model, String name) {
BindingResult bindingResult = getBindingResult(model, name); BindingResult bindingResult = getBindingResult(model, name);
if (bindingResult == null) { if (bindingResult == null) {
throw new IllegalStateException("No BindingResult attribute found for name '" + name + throw new IllegalStateException("No BindingResult attribute found for name '" + name +

View File

@ -509,18 +509,15 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
return this.conversionService; return this.conversionService;
} }
@SuppressWarnings("unchecked") public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) {
public void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor) {
getPropertyEditorRegistry().registerCustomEditor(requiredType, propertyEditor); getPropertyEditorRegistry().registerCustomEditor(requiredType, propertyEditor);
} }
@SuppressWarnings("unchecked") public void registerCustomEditor(Class<?> requiredType, String field, PropertyEditor propertyEditor) {
public void registerCustomEditor(Class requiredType, String field, PropertyEditor propertyEditor) {
getPropertyEditorRegistry().registerCustomEditor(requiredType, field, propertyEditor); getPropertyEditorRegistry().registerCustomEditor(requiredType, field, propertyEditor);
} }
@SuppressWarnings("unchecked") public PropertyEditor findCustomEditor(Class<?> requiredType, String propertyPath) {
public PropertyEditor findCustomEditor(Class requiredType, String propertyPath) {
return getPropertyEditorRegistry().findCustomEditor(requiredType, propertyPath); return getPropertyEditorRegistry().findCustomEditor(requiredType, propertyPath);
} }
@ -700,8 +697,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
* @throws BindException if there were any errors in the bind operation * @throws BindException if there were any errors in the bind operation
* @see BindingResult#getModel() * @see BindingResult#getModel()
*/ */
@SuppressWarnings("unchecked") public Map<?, ?> close() throws BindException {
public Map close() throws BindException {
if (getBindingResult().hasErrors()) { if (getBindingResult().hasErrors()) {
throw new BindException(getBindingResult()); throw new BindException(getBindingResult());
} }

View File

@ -75,6 +75,7 @@ import org.springframework.util.StringUtils;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 1.0.1 * @since 1.0.1
*/ */
@SuppressWarnings("serial")
public class DefaultMessageCodesResolver implements MessageCodesResolver, Serializable { public class DefaultMessageCodesResolver implements MessageCodesResolver, Serializable {
/** /**
@ -119,7 +120,7 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
* details on the generated codes. * details on the generated codes.
* @return the list of codes * @return the list of codes
*/ */
public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class fieldType) { public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class<?> fieldType) {
List<String> codeList = new ArrayList<String>(); List<String> codeList = new ArrayList<String>();
List<String> fieldList = new ArrayList<String>(); List<String> fieldList = new ArrayList<String>();
buildFieldList(field, fieldList); buildFieldList(field, fieldList);

View File

@ -34,6 +34,7 @@ import org.springframework.util.Assert;
* @see DataBinder#initDirectFieldAccess() * @see DataBinder#initDirectFieldAccess()
* @see BeanPropertyBindingResult * @see BeanPropertyBindingResult
*/ */
@SuppressWarnings("serial")
public class DirectFieldBindingResult extends AbstractPropertyBindingResult { public class DirectFieldBindingResult extends AbstractPropertyBindingResult {
private final Object target; private final Object target;

View File

@ -296,6 +296,6 @@ public interface Errors {
* @param field the field name * @param field the field name
* @return the type of the field, or <code>null</code> if not determinable * @return the type of the field, or <code>null</code> if not determinable
*/ */
Class getFieldType(String field); Class<?> getFieldType(String field);
} }

View File

@ -31,6 +31,7 @@ import org.springframework.util.ObjectUtils;
* @since 10.03.2003 * @since 10.03.2003
* @see DefaultMessageCodesResolver * @see DefaultMessageCodesResolver
*/ */
@SuppressWarnings("serial")
public class FieldError extends ObjectError { public class FieldError extends ObjectError {
private final String field; private final String field;

View File

@ -33,9 +33,10 @@ import org.springframework.util.Assert;
* @since 2.0 * @since 2.0
* @see java.util.Map * @see java.util.Map
*/ */
@SuppressWarnings("serial")
public class MapBindingResult extends AbstractBindingResult implements Serializable { public class MapBindingResult extends AbstractBindingResult implements Serializable {
private final Map target; private final Map<?, ?> target;
/** /**
@ -43,14 +44,14 @@ public class MapBindingResult extends AbstractBindingResult implements Serializa
* @param target the target Map to bind onto * @param target the target Map to bind onto
* @param objectName the name of the target object * @param objectName the name of the target object
*/ */
public MapBindingResult(Map target, String objectName) { public MapBindingResult(Map<?, ?> target, String objectName) {
super(objectName); super(objectName);
Assert.notNull(target, "Target Map must not be null"); Assert.notNull(target, "Target Map must not be null");
this.target = target; this.target = target;
} }
public final Map getTargetMap() { public final Map<?, ?> getTargetMap() {
return this.target; return this.target;
} }

View File

@ -50,6 +50,6 @@ public interface MessageCodesResolver {
* @param fieldType the field type (may be <code>null</code> if not determinable) * @param fieldType the field type (may be <code>null</code> if not determinable)
* @return the message codes to use * @return the message codes to use
*/ */
String[] resolveMessageCodes(String errorCode, String objectName, String field, Class fieldType); String[] resolveMessageCodes(String errorCode, String objectName, String field, Class<?> fieldType);
} }

View File

@ -31,6 +31,7 @@ import org.springframework.util.Assert;
* @see DefaultMessageCodesResolver * @see DefaultMessageCodesResolver
* @since 10.03.2003 * @since 10.03.2003
*/ */
@SuppressWarnings("serial")
public class ObjectError extends DefaultMessageSourceResolvable { public class ObjectError extends DefaultMessageSourceResolvable {
private final String objectName; private final String objectName;

View File

@ -62,6 +62,7 @@ import org.springframework.util.CollectionUtils;
public class LocalValidatorFactoryBean extends SpringValidatorAdapter public class LocalValidatorFactoryBean extends SpringValidatorAdapter
implements ValidatorFactory, ApplicationContextAware, InitializingBean { implements ValidatorFactory, ApplicationContextAware, InitializingBean {
@SuppressWarnings("rawtypes")
private Class providerClass; private Class providerClass;
private MessageInterpolator messageInterpolator; private MessageInterpolator messageInterpolator;
@ -85,6 +86,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
* @see javax.validation.Validation#byProvider(Class) * @see javax.validation.Validation#byProvider(Class)
* @see javax.validation.Validation#byDefaultProvider() * @see javax.validation.Validation#byDefaultProvider()
*/ */
@SuppressWarnings("rawtypes")
public void setProviderClass(Class<? extends ValidationProvider> providerClass) { public void setProviderClass(Class<? extends ValidationProvider> providerClass) {
this.providerClass = providerClass; this.providerClass = providerClass;
} }
@ -177,6 +179,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void afterPropertiesSet() { public void afterPropertiesSet() {
@SuppressWarnings("rawtypes")
Configuration configuration = (this.providerClass != null ? Configuration configuration = (this.providerClass != null ?
Validation.byProvider(this.providerClass).configure() : Validation.byProvider(this.providerClass).configure() :
Validation.byDefaultProvider().configure()); Validation.byDefaultProvider().configure());

View File

@ -3,8 +3,9 @@
* (such as Hibernate Validator 4.0) into a Spring ApplicationContext * (such as Hibernate Validator 4.0) into a Spring ApplicationContext
* and in particular with Spring's data binding and validation APIs. * and in particular with Spring's data binding and validation APIs.
* *
* <p>The central class is {@link LocalValidatorFactoryBean} which * <p>The central class is {@link
* defines a shared ValidatorFactory/Validator setup for availability * org.springframework.validation.beanvalidation.LocalValidatorFactoryBean}
* which defines a shared ValidatorFactory/Validator setup for availability
* to other Spring components. * to other Spring components.
*/ */
package org.springframework.validation.beanvalidation; package org.springframework.validation.beanvalidation;