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(@NotNull 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.
    IdentityBeanConverter(@NotNull Class<? extends WritableIdentityBean> defaultType, @NotNull org.apache.commons.beanutils.Converter identityConverter)
    Creates a new instance that throws a ConversionException 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 of IdentityConverter for identity conversions.
    IdentityBeanConverter(@NotNull org.apache.commons.beanutils.Converter identityConverter)
    Creates a new instance that throws a ConversionException 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.
    Creates a new instance that returns a default value if an error occurs and uses default instance of IdentityConverter for identity conversions.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Identity
    Converts the value to a Identity instance.
    protected String
    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

    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(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(@NotNull @NotNull 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(@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 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(@NotNull @NotNull 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(@NotNull @NotNull Class<T> defaultType, 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(@NotNull @NotNull Class<? extends WritableIdentityBean> defaultType, @NotNull @NotNull 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(@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 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

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

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

      protected <T> T createInstance(@NotNull @NotNull 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) throws Throwable
      Overrides:
      convertToString in class org.apache.commons.beanutils.converters.AbstractConverter
      Throws:
      Throwable