Package dev.orne.beans.converters
Class IdentityBeanConverter
java.lang.Object
org.apache.commons.beanutils.converters.AbstractConverter
dev.orne.beans.converters.IdentityBeanConverter
- All Implemented Interfaces:
org.apache.commons.beanutils.Converter
@API(status=STABLE,
since="0.3")
public class IdentityBeanConverter
extends org.apache.commons.beanutils.converters.AbstractConverter
Implementation of
Converter that converts IdentityBean
instances to String and WritableIdentityBean from
String using the identity token of the bean as String
representation.
Uses a nested Converter, of type IdentityConverter by
default, to convert bean identities.
When converting from String instances of TokenIdentity
are produced an populated on empty instances of the bean, producing valid
ValidBeanIdentity instances.
- Since:
- 0.3
- Version:
- 1.0, 2020-09
- Author:
- (w) Iker Hernaez
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance that throws aConversionExceptionif an error occurs and uses default instance ofIdentityConverterfor identity conversions.IdentityBeanConverter(@NotNull Class<? extends WritableIdentityBean> defaultType) Creates a new instance that throws aConversionExceptionif an error occurs and uses default instance ofIdentityConverterfor identity conversions.IdentityBeanConverter(@NotNull Class<? extends WritableIdentityBean> defaultType, @NotNull org.apache.commons.beanutils.Converter identityConverter) Creates a new instance that throws aConversionExceptionif an error occurs.IdentityBeanConverter(@NotNull Class<T> defaultType, @NotNull org.apache.commons.beanutils.Converter identityConverter, T defaultValue) Creates a new instance that returns a default value if an error occurs.IdentityBeanConverter(@NotNull Class<T> defaultType, T defaultValue) Creates a new instance that returns a default value if an error occurs and uses default instance ofIdentityConverterfor identity conversions.IdentityBeanConverter(@NotNull org.apache.commons.beanutils.Converter identityConverter) Creates a new instance that throws aConversionExceptionif an error occurs.IdentityBeanConverter(@NotNull org.apache.commons.beanutils.Converter identityConverter, WritableIdentityBean defaultValue) Creates a new instance that returns a default value if an error occurs.IdentityBeanConverter(IdentityBean defaultValue) Creates a new instance that returns a default value if an error occurs and uses default instance ofIdentityConverterfor identity conversions. -
Method Summary
Modifier and TypeMethodDescriptionprotected IdentityconvertIdentity(Object value) Converts the value to aIdentityinstance.protected StringconvertToString(Object value) protected <T> TconvertToType(@NotNull Class<T> type, Object value) protected <T> TcreateInstance(@NotNull Class<T> type, Object value) Tries to create a new instance of the target type.protected @NotNull Class<?>protected org.apache.commons.beanutils.ConverterReturns the converter for identities.Methods inherited from class org.apache.commons.beanutils.converters.AbstractConverter
conversionException, convert, convertArray, getDefault, handleError, handleMissing, isUseDefault, setDefaultValue, toString
-
Constructor Details
-
IdentityBeanConverter
public IdentityBeanConverter()Creates a new instance that throws aConversionExceptionif an error occurs and uses default instance ofIdentityConverterfor identity conversions. -
IdentityBeanConverter
Creates a new instance that returns a default value if an error occurs and uses default instance ofIdentityConverterfor identity conversions.- Parameters:
defaultValue- The default value to be returned if the value to be converted is missing or an error occurs converting the value
-
IdentityBeanConverter
public IdentityBeanConverter(@NotNull @NotNull org.apache.commons.beanutils.Converter identityConverter) Creates a new instance that throws aConversionExceptionif an error occurs.- Parameters:
identityConverter- The converter to use for identity conversions
-
IdentityBeanConverter
public IdentityBeanConverter(@NotNull @NotNull org.apache.commons.beanutils.Converter identityConverter, WritableIdentityBean defaultValue) Creates a new instance that returns a default value if an error occurs.- Parameters:
identityConverter- The converter to use for identity conversionsdefaultValue- The default value to be returned if the value to be converted is missing or an error occurs converting the value
-
IdentityBeanConverter
Creates a new instance that throws aConversionExceptionif an error occurs and uses default instance ofIdentityConverterfor identity conversions.- Parameters:
defaultType- The default type thisConverterhandles.
-
IdentityBeanConverter
Creates a new instance that returns a default value if an error occurs and uses default instance ofIdentityConverterfor identity conversions.- Type Parameters:
T- The default type thisConverterhandles.- Parameters:
defaultType- The default type thisConverterhandles.defaultValue- The default value to be returned if the value to be converted is missing or an error occurs converting the value
-
IdentityBeanConverter
public IdentityBeanConverter(@NotNull @NotNull Class<? extends WritableIdentityBean> defaultType, @NotNull @NotNull org.apache.commons.beanutils.Converter identityConverter) Creates a new instance that throws aConversionExceptionif an error occurs.- Parameters:
defaultType- The default type thisConverterhandles.identityConverter- The converter to use for identity conversions
-
IdentityBeanConverter
public IdentityBeanConverter(@NotNull @NotNull Class<T> defaultType, @NotNull @NotNull org.apache.commons.beanutils.Converter identityConverter, T defaultValue) Creates a new instance that returns a default value if an error occurs.- Type Parameters:
T- The default type thisConverterhandles.- Parameters:
defaultType- The default type thisConverterhandles.identityConverter- The converter to use for identity conversionsdefaultValue- The default value to be returned if the value to be converted is missing or an error occurs converting the value
-
-
Method Details
-
getIdentityConverter
protected org.apache.commons.beanutils.Converter getIdentityConverter()Returns the converter for identities.- Returns:
- The converter for identities
-
getDefaultType
- Specified by:
getDefaultTypein classorg.apache.commons.beanutils.converters.AbstractConverter
-
convertToType
- Specified by:
convertToTypein classorg.apache.commons.beanutils.converters.AbstractConverter
-
createInstance
Tries to create a new instance of the target type.- Type Parameters:
T- The type of bean to create- Parameters:
type- The type of bean to createvalue- The input value to be converted. Used only when an error occurs- Returns:
- The newly created instance
- Throws:
org.apache.commons.beanutils.ConversionException- If the new instance cannot be created
-
convertIdentity
Converts the value to aIdentityinstance.- Parameters:
value- The input value to be converted- Returns:
- The converted value
- Throws:
org.apache.commons.beanutils.ConversionException- If an error occurs converting the value
-
convertToString
- Overrides:
convertToStringin classorg.apache.commons.beanutils.converters.AbstractConverter- Throws:
Throwable
-