net.sf.morph.transform
Interface Converter
- All Superinterfaces:
- net.sf.composite.Component, Transformer
- All Known Subinterfaces:
- DecoratedConverter
- All Known Implementing Classes:
- ArbitraryObjectMappingConverter, ArbitraryTypeMappingConverter, ArrayCopier, AssemblerCopier, BasePropertyNameCopier, BaseToPrettyTextConverter, BeanToPrettyTextConverter, BeanUtilsConverter, BeanUtilsConverter, BooleanToTextConverter, ChainedTransformer, CombiningCopier, ConditionalCopier, ConstantConverter, ContainerCopier, ContainerOfBeansCopier, ContainerToPrettyTextConverter, ContainerToTraverserConverter, ConverterDecorator, CopierDecorator, CumulativeCopier, DefaultToBooleanConverter, DefaultToTextConverter, DisassemblerCopier, EvaluateExpressionConverter, IdentityConverter, ImmutableComponentArrayCopier, ImmutableTypesOnlyIdentityConverter, MapCopier, MultipleDestinationConverter, NOPCopier, NullConverter, NumberConverter, NumberToBooleanConverter, NumberToTextConverter, NumberToTimeConverter, ObjectToBooleanConverter, ObjectToClassConverter, ObjectToPrettyTextConverter, ObjectToTextConverter, PrimitiveWrapperConverter, PropertyExpressionMappingCopier, PropertyNameMappingCopier, PropertyNameMatchingCopier, SetExpressionCopier, SimpleDelegatingTransformer, TextConverter, TextToBooleanConverter, TextToClassConverter, TextToContainerCopier, TextToNumberConverter, TextToTimeConverter, TimeConverter, TimeToNumberConverter, TimeToTextConverter, TransformerToDecoratedConverterAdapter, TypeChangingGraphTransformer
public interface Converter
- extends Transformer
An object that can convert one type of object into another type of object.
Usually, the sourceClasses and destinationClasses attributes determine the
set of sources and destinations which the converter can convert. However,
if any of the sourceClasses is not convertible to a destinationClass, then
a converter may implement the ExplicitTransformer
to explicitly define which sources are convertible to which destinations.
Note that the Converter interface can be easily implemented by a Copier (see
net.sf.morph.transform.converters.CopierConverter
), so it is
recommended that Converters only be implemented for basic data types
(numbers, primitives) or immutable data types (e.g. Strings, but note Dates).
- Since:
- October 24, 2004
- Author:
- Matt Sgarlata
- See Also:
ExplicitTransformer
Method Summary |
java.lang.Object |
convert(java.lang.Class destinationClass,
java.lang.Object source,
java.util.Locale locale)
Converts the given source into an object of class
destinationClass . |
convert
java.lang.Object convert(java.lang.Class destinationClass,
java.lang.Object source,
java.util.Locale locale)
throws TransformationException
- Converts the given
source
into an object of class
destinationClass
. The returned object may be a reference
to source
itself. This isn't an issue for immutable
classes (String, Long, etc) but is an issue for Collection and Array
types.
- Parameters:
destinationClass
- the destination class to testsource
- the source object to testlocale
- the locale in which the conversion should take place, or
null
if the locale is not applicable
- Returns:
- the result of the conversion
- Throws:
TransformationException
- if destinationClass
is null
,
an error occurred while performing the conversion
Copyright © 2004-2008.