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
ConstructorDescriptionCreates a new instance that throws aConversionException
if an error occurs and uses default instance ofIdentityConverter
for identity conversions.IdentityBeanConverter
(@NotNull Class<? extends WritableIdentityBean> defaultType) Creates a new instance that throws aConversionException
if an error occurs and uses default instance ofIdentityConverter
for identity conversions.IdentityBeanConverter
(@NotNull Class<? extends WritableIdentityBean> defaultType, @NotNull org.apache.commons.beanutils.Converter identityConverter) Creates a new instance that throws aConversionException
if 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 ofIdentityConverter
for identity conversions.IdentityBeanConverter
(@NotNull org.apache.commons.beanutils.Converter identityConverter) Creates a new instance that throws aConversionException
if 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 ofIdentityConverter
for identity conversions. -
Method Summary
Modifier and TypeMethodDescriptionprotected Identity
convertIdentity
(Object value) Converts the value to aIdentity
instance.protected String
convertToString
(Object value) protected <T> T
convertToType
(@NotNull Class<T> type, Object value) protected <T> T
createInstance
(@NotNull Class<T> type, Object value) Tries to create a new instance of the target type.protected @NotNull Class<?>
protected org.apache.commons.beanutils.Converter
Returns 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 aConversionException
if an error occurs and uses default instance ofIdentityConverter
for identity conversions. -
IdentityBeanConverter
Creates a new instance that returns a default value if an error occurs and uses default instance ofIdentityConverter
for 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 aConversionException
if 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 aConversionException
if an error occurs and uses default instance ofIdentityConverter
for identity conversions.- Parameters:
defaultType
- The default type thisConverter
handles.
-
IdentityBeanConverter
Creates a new instance that returns a default value if an error occurs and uses default instance ofIdentityConverter
for identity conversions.- Type Parameters:
T
- The default type thisConverter
handles.- Parameters:
defaultType
- The default type thisConverter
handles.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 aConversionException
if an error occurs.- Parameters:
defaultType
- The default type thisConverter
handles.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 thisConverter
handles.- Parameters:
defaultType
- The default type thisConverter
handles.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:
getDefaultType
in classorg.apache.commons.beanutils.converters.AbstractConverter
-
convertToType
- Specified by:
convertToType
in 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 aIdentity
instance.- 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:
convertToString
in classorg.apache.commons.beanutils.converters.AbstractConverter
- Throws:
Throwable
-