Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* 
  * Copyright (C) 2012 FoxLabs
  * 
  * 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 org.foxlabs.validation.converter;
The root interface in the converter hierarchy. A converter provides ability to convert values of certain data type into and from string representation. Converter instances should be registered and obtained from ConverterFactory.

Parameters:
<V> The type of value to be converted
Author(s):
Fox Mulder
See also:
ConverterFactory
public interface Converter<V> extends Validation<V> {
    
    
Returns the type of value to be converted.

Returns:
The type of value to be converted.
    Class<V> getType();
    
    
Returns localized error message template.

This method may return null if converter never generates MalformedValueException.

Parameters:
context Validation context.
Returns:
Localized error message template.
    String getMessageTemplate(ValidationContext<?> context);
    
    
Appends arguments to be substituted into the error message template.

Parameters:
context Validation context.
arguments Arguments to be substituted into the error message template.
    boolean appendMessageArguments(ValidationContext<?> contextMap<StringObjectarguments);
    
    
Converts string representation of value into object.

The method org.foxlabs.validation.ValidationContext.isLocalizedConvert() determines if converter should take locale into account. Locale can be obtained through the method org.foxlabs.validation.ValidationContext.getMessageLocale().

Parameters:
value String representation of value.
context Validation context.
Returns:
Decoded value.
Throws:
MalformedValueException if conversion fails.
    <T> V decode(String valueValidationContext<T> context);
    
    
Converts value into string representation.

The method org.foxlabs.validation.ValidationContext.isLocalizedConvert() determines if converter should take locale into account. Locale can be obtained through the method org.foxlabs.validation.ValidationContext.getMessageLocale().

Parameters:
value Value to be encoded.
context Validation context.
Returns:
String representation of value.
    <T> String encode(V valueValidationContext<T> context);
    
New to GrepCode? Check out our FAQ X