org.springmodules.validation.bean.converter
Class ModelAwareErrorCodeConverter

java.lang.Object
  extended by org.springmodules.validation.bean.converter.ModelAwareErrorCodeConverter
All Implemented Interfaces:
ErrorCodeConverter

public class ModelAwareErrorCodeConverter
extends Object
implements ErrorCodeConverter

Converts simple error codes to an error code that expresses the class and perhaps the property that are associated with the error code.

Author:
Uri Boness

Constructor Summary
ModelAwareErrorCodeConverter()
          Constructs a new ModelAwareErrorCodeConverter that uses class simple names.
ModelAwareErrorCodeConverter(boolean useFullyQualifiedClassName)
          Constructs a new ModelAwareErrorCodeConverter.
 
Method Summary
 String convertGlobalErrorCode(String errorCode, Class clazz)
          Converts the given error code to the following format:
short_class_name[errorCode]
where short_class_name is the name of the given class with its package stripped, and error_code is the given error code.
 String convertPropertyErrorCode(String errorCode, Class clazz, String propertyName)
          Converts the given error code to the following format:
short_class_name.property_name[errorCode]
where short_class_name is the name of the given class with its package stripped, property_name is the given property name, and error_code is the given error code.
 void setUseFullyQualifiedClassName(boolean useFullyQualifiedClassName)
          Determines whether the converted error codes will use the fully qualified class names of the validated class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelAwareErrorCodeConverter

public ModelAwareErrorCodeConverter()
Constructs a new ModelAwareErrorCodeConverter that uses class simple names. For example, the validation error code error_code for class org.springmodules.validation.sample.Person will be converted to Person[error_code].


ModelAwareErrorCodeConverter

public ModelAwareErrorCodeConverter(boolean useFullyQualifiedClassName)
Constructs a new ModelAwareErrorCodeConverter. The given argument idicateds whether a fully qualified name should be used for the converted error codes. For example, if the validation error code error_code for class org.springmodules.validation.sample.Person will be converted with fully qualified name set to true, the converted error code will be org.springmodules.validation.sample.Person[error_code].

Method Detail

convertGlobalErrorCode

public String convertGlobalErrorCode(String errorCode,
                                     Class clazz)
Converts the given error code to the following format:
short_class_name[errorCode]
where short_class_name is the name of the given class with its package stripped, and error_code is the given error code.

Specified by:
convertGlobalErrorCode in interface ErrorCodeConverter
Parameters:
errorCode - The given error code (the one to convert)
clazz - The given class
Returns:
The converted error code.

convertPropertyErrorCode

public String convertPropertyErrorCode(String errorCode,
                                       Class clazz,
                                       String propertyName)
Converts the given error code to the following format:
short_class_name.property_name[errorCode]
where short_class_name is the name of the given class with its package stripped, property_name is the given property name, and error_code is the given error code.

Specified by:
convertPropertyErrorCode in interface ErrorCodeConverter
Parameters:
errorCode - The given error code (the one to convert)
clazz - The given class
propertyName - The property name
Returns:
The converted error code.

setUseFullyQualifiedClassName

public void setUseFullyQualifiedClassName(boolean useFullyQualifiedClassName)
Determines whether the converted error codes will use the fully qualified class names of the validated class. If not, the simple class name will be used instead.

Parameters:
useFullyQualifiedClassName -


Copyright © 2009. All Rights Reserved.