Package org.linkki.core.ui.converters
Class LinkkiConverterRegistry
- java.lang.Object
-
- org.linkki.core.ui.converters.LinkkiConverterRegistry
-
- All Implemented Interfaces:
Serializable
public class LinkkiConverterRegistry extends Object implements Serializable
A converter registry that holds a set of standard converters. The registry could be instantiated with additional converters which would be set before the default converters. That means if the registry is initiated with a custom converter which has the same types as an existing one, the custom converter is used with higher priority.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static LinkkiConverterRegistryDEFAULT
-
Constructor Summary
Constructors Constructor Description LinkkiConverterRegistry(com.vaadin.flow.data.converter.Converter<?,?>... customConverters)Creates a newLinkkiConverterRegistrywith all default converters.LinkkiConverterRegistry(Collection<com.vaadin.flow.data.converter.Converter<?,?>> customConverters)Creates a newLinkkiConverterRegistrywith additional converters which are registered with higher priority before the default converters.LinkkiConverterRegistry(org.linkki.util.Sequence<com.vaadin.flow.data.converter.Converter<?,?>> customConverters)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <P,M>
com.vaadin.flow.data.converter.Converter<P,M>findConverter(Type presentationType, Type modelType)Finds a converter that does match the two types for the presentation an the model type.protected org.linkki.util.Sequence<com.vaadin.flow.data.converter.Converter<?,?>>getAllConverters()static LinkkiConverterRegistrygetCurrent()Returns theLinkkiConverterRegistrythat is configured in the currentVaadinSession.LinkkiConverterRegistrywith(com.vaadin.flow.data.converter.Converter<?,?> converter)
-
-
-
Field Detail
-
DEFAULT
public static final LinkkiConverterRegistry DEFAULT
-
-
Constructor Detail
-
LinkkiConverterRegistry
@SafeVarargs public LinkkiConverterRegistry(com.vaadin.flow.data.converter.Converter<?,?>... customConverters)
Creates a newLinkkiConverterRegistrywith all default converters.- Parameters:
customConverters- custom converters that are registered within thisLinkkiConverterRegistry
-
LinkkiConverterRegistry
public LinkkiConverterRegistry(Collection<com.vaadin.flow.data.converter.Converter<?,?>> customConverters)
Creates a newLinkkiConverterRegistrywith additional converters which are registered with higher priority before the default converters.- Parameters:
customConverters- custom converters that are registered within thisLinkkiConverterRegistry
-
LinkkiConverterRegistry
public LinkkiConverterRegistry(org.linkki.util.Sequence<com.vaadin.flow.data.converter.Converter<?,?>> customConverters)
-
-
Method Detail
-
findConverter
public <P,M> com.vaadin.flow.data.converter.Converter<P,M> findConverter(Type presentationType, Type modelType)
Finds a converter that does match the two types for the presentation an the model type.If the types are
classesthey have to match exactly the type of a converter. We do not check assignable types because the covariance and contravariance depends on the direction of conversion.If both types are equal or we cannot determine the correct type for any reason, the
identity converteris returned.If the correct type could be determined but there is no matching converter, an
IllegalArgumentExceptionis thrown.- Parameters:
presentationType- The type of the presentation, that means the value type of the UI componentmodelType- The type of the model, that means the value type of the model property- Returns:
- the converter that best match the two types
- Throws:
IllegalArgumentException- if the types could be considered to be correct but no matching converter could be found.
-
getAllConverters
protected org.linkki.util.Sequence<com.vaadin.flow.data.converter.Converter<?,?>> getAllConverters()
-
with
public LinkkiConverterRegistry with(com.vaadin.flow.data.converter.Converter<?,?> converter)
-
getCurrent
public static LinkkiConverterRegistry getCurrent()
Returns theLinkkiConverterRegistrythat is configured in the currentVaadinSession. Another instance ofLinkkiConverterRegistrycould be configured usingVaadinSession.getCurrent().setAttribute(LinkkiConverterRegistry.class, converterRegistry);
If there is either no currentVaadinSessionor noLinkkiConverterRegistryis configured this method returnsDEFAULT.- Returns:
- the current configured
LinkkiConverterRegistry
-
-