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

    Constructors
    Constructor
    Description
    Creates a new instance that throws a ConversionException if an error occurs and uses default instance of IdentityConverter for identity conversions.
    IdentityBeanConverter(@Nullable IdentityBean defaultValue)
    Creates a new instance that returns a default value if an error occurs and uses default instance of IdentityConverter for identity conversions.
    Creates a new instance that throws a ConversionException if an error occurs and uses default instance of IdentityConverter for identity conversions.
    IdentityBeanConverter(Class<? extends WritableIdentityBean> defaultType, org.apache.commons.beanutils.Converter identityConverter)
    Creates a new instance that throws a ConversionException if an error occurs.
    IdentityBeanConverter(Class<T> defaultType, @Nullable T defaultValue)
    Creates a new instance that returns a default value if an error occurs and uses default instance of IdentityConverter for identity conversions.
    IdentityBeanConverter(Class<T> defaultType, org.apache.commons.beanutils.Converter identityConverter, @Nullable T defaultValue)
    Creates a new instance that returns a default value if an error occurs.
    IdentityBeanConverter(org.apache.commons.beanutils.Converter identityConverter)
    Creates a new instance that throws a ConversionException if an error occurs.
    IdentityBeanConverter(org.apache.commons.beanutils.Converter identityConverter, @Nullable WritableIdentityBean defaultValue)
    Creates a new instance that returns a default value if an error occurs.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Identity
    Converts the value to a Identity instance.
    protected String
    protected <T> T
    convertToType(Class<T> type, Object value)
    protected <T> T
    createInstance(Class<T> type, Object value)
    Tries to create a new instance of the target type.
    protected 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • IdentityBeanConverter

      public IdentityBeanConverter()
      Creates a new instance that throws a ConversionException if an error occurs and uses default instance of IdentityConverter for identity conversions.
    • IdentityBeanConverter

      public IdentityBeanConverter(@Nullable IdentityBean defaultValue)
      Creates a new instance that returns a default value if an error occurs and uses default instance of IdentityConverter 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(org.apache.commons.beanutils.Converter identityConverter)
      Creates a new instance that throws a ConversionException if an error occurs.
      Parameters:
      identityConverter - The converter to use for identity conversions
    • IdentityBeanConverter

      public IdentityBeanConverter(org.apache.commons.beanutils.Converter identityConverter, @Nullable WritableIdentityBean defaultValue)
      Creates a new instance that returns a default value if an error occurs.
      Parameters:
      identityConverter - The converter to use for identity conversions
      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(Class<? extends WritableIdentityBean> defaultType)
      Creates a new instance that throws a ConversionException if an error occurs and uses default instance of IdentityConverter for identity conversions.
      Parameters:
      defaultType - The default type this Converter handles.
    • IdentityBeanConverter

      public IdentityBeanConverter(Class<T> defaultType, @Nullable T defaultValue)
      Creates a new instance that returns a default value if an error occurs and uses default instance of IdentityConverter for identity conversions.
      Type Parameters:
      T - The default type this Converter handles.
      Parameters:
      defaultType - The default type this Converter 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(Class<? extends WritableIdentityBean> defaultType, org.apache.commons.beanutils.Converter identityConverter)
      Creates a new instance that throws a ConversionException if an error occurs.
      Parameters:
      defaultType - The default type this Converter handles.
      identityConverter - The converter to use for identity conversions
    • IdentityBeanConverter

      public IdentityBeanConverter(Class<T> defaultType, org.apache.commons.beanutils.Converter identityConverter, @Nullable T defaultValue)
      Creates a new instance that returns a default value if an error occurs.
      Type Parameters:
      T - The default type this Converter handles.
      Parameters:
      defaultType - The default type this Converter handles.
      identityConverter - The converter to use for identity conversions
      defaultValue - 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

      protected Class<?> getDefaultType()
      Specified by:
      getDefaultType in class org.apache.commons.beanutils.converters.AbstractConverter
    • convertToType

      protected <T> T convertToType(Class<T> type, Object value)
      Specified by:
      convertToType in class org.apache.commons.beanutils.converters.AbstractConverter
    • createInstance

      protected <T> T createInstance(Class<T> type, Object value)
      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 create
      value - 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

      protected Identity convertIdentity(Object value)
      Converts the value to a Identity 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

      protected String convertToString(Object value)
      Overrides:
      convertToString in class org.apache.commons.beanutils.converters.AbstractConverter