Interface Converter

All Superinterfaces:
net.sf.composite.Component, Transformer
All Known Subinterfaces:
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).

October 24, 2004
Matt Sgarlata
See Also:

Field Summary
Fields inherited from interface net.sf.morph.transform.Transformer
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.
Methods inherited from interface net.sf.morph.transform.Transformer
getDestinationClasses, getSourceClasses

Method Detail


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.

destinationClass - the destination class to test
source - the source object to test
locale - the locale in which the conversion should take place, or null if the locale is not applicable
the result of the conversion
TransformationException - if destinationClass is null, an error occurred while performing the conversion

Copyright © 2004-2008.