Class StrutsTypeConverterHolder

java.lang.Object
org.apache.struts2.conversion.StrutsTypeConverterHolder
All Implemented Interfaces:
TypeConverterHolder

public class StrutsTypeConverterHolder extends Object implements TypeConverterHolder
Default implementation of TypeConverterHolder
  • Field Details

    • unknownMappings

      @Deprecated(since="7.3.0", forRemoval=true) protected HashSet<String> unknownMappings
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 7.3.0, unused - superseded by internal concurrent storage. Retained only for binary compatibility with subclasses compiled against earlier versions, and will be removed in a future release.
      Record classes that doesn't have conversion mapping defined.
       - String -> classname as String
       
  • Constructor Details

    • StrutsTypeConverterHolder

      public StrutsTypeConverterHolder()
  • Method Details

    • addDefaultMapping

      public void addDefaultMapping(String className, TypeConverter typeConverter)
      Description copied from interface: TypeConverterHolder
      Adds mapping for default type converters - application scoped
      Specified by:
      addDefaultMapping in interface TypeConverterHolder
      Parameters:
      className - name of the class with associated converter
      typeConverter - TypeConverter instance for associated class
    • containsDefaultMapping

      public boolean containsDefaultMapping(String className)
      Description copied from interface: TypeConverterHolder
      Checks if converter was already defined for given class
      Specified by:
      containsDefaultMapping in interface TypeConverterHolder
      Parameters:
      className - name of the class to check for
      Returns:
      true if default mapping was already specified
    • getDefaultMapping

      public TypeConverter getDefaultMapping(String className)
      Description copied from interface: TypeConverterHolder
      Returns instance of TypeConverter associated with given class
      Specified by:
      getDefaultMapping in interface TypeConverterHolder
      Parameters:
      className - name of the class to return converter for
      Returns:
      instance of TypeConverter to be used to convert class
    • getMapping

      @Deprecated(since="7.3.0", forRemoval=true) public Map<String,Object> getMapping(Class clazz)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 7.3.0, use computeMappingIfAbsent(Class, Function) instead.
      Returns null if clazz has been flagged as having no mapping via addNoMapping(Class), even if a real mapping was previously stored for it.
      Specified by:
      getMapping in interface TypeConverterHolder
      Parameters:
      clazz - class to convert to/from
      Returns:
      the property-converter mapping for the given class, or null if none
    • addMapping

      @Deprecated(since="7.3.0", forRemoval=true) public void addMapping(Class clazz, Map<String,Object> mapping)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 7.3.0, use computeMappingIfAbsent(Class, Function) instead.
      Description copied from interface: TypeConverterHolder
      Assign mapping of converters for given class
      Specified by:
      addMapping in interface TypeConverterHolder
      Parameters:
      clazz - class to convert to/from
      mapping - property converters
    • containsNoMapping

      @Deprecated(since="7.3.0", forRemoval=true) public boolean containsNoMapping(Class clazz)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 7.3.0, use computeMappingIfAbsent(Class, Function) instead.
      Description copied from interface: TypeConverterHolder
      Check if there is no mapping for given class to convert
      Specified by:
      containsNoMapping in interface TypeConverterHolder
      Parameters:
      clazz - class to convert to/from
      Returns:
      true if mapping couldn't be found
    • addNoMapping

      public void addNoMapping(Class clazz)
      Stores the NO_MAPPING sentinel for the given class, replacing any mapping previously cached for it. This matches the pre-7.3.0 effective behaviour, back when a separate no-mapping collection was consulted independently of the mappings map: the only in-tree caller, XWorkConverter.getConverter, checked the no-mapping flag first and short-circuited before the cached mapping was ever read, so flagging a class as no-mapping made it behave as though it had no mapping, real cached mapping or not. Map.putIfAbsent(K, V) is deliberately not used here: it would leave a stale mapping being served for a class whose conversion build subsequently failed, which is a genuine behaviour change rather than a faithful port.
      Specified by:
      addNoMapping in interface TypeConverterHolder
      Parameters:
      clazz - class to register missing converter
    • computeMappingIfAbsent

      public Map<String,Object> computeMappingIfAbsent(Class clazz, Function<Class,Map<String,Object>> builder)
      Description copied from interface: TypeConverterHolder
      Returns the property-converter mapping for the given class, building and caching it on first use. Never returns null: a class known to have no mapping yields an empty map.

      If the builder returns null or an empty map, the class is recorded in the negative cache so the builder is not invoked for it again.

      Implementations only guarantee that all callers converge on the same cached mapping instance for a given class - not that the builder runs at most once. Under concurrent first access, the builder may be invoked more than once (each on a different thread, for the same class); only one of the resulting mappings is retained and returned to every caller. The builder must therefore be idempotent and free of side effects on the holder itself. The default implementation is a non-atomic check-then-act using the deprecated primitives, preserving pre-7.3.0 behaviour for third-party holders that do not override it.

      Specified by:
      computeMappingIfAbsent in interface TypeConverterHolder
      Parameters:
      clazz - class to convert to/from
      builder - builds the property-converter mapping for the class when it is not yet cached
      Returns:
      the mapping for the class, or an empty map if it has none
    • containsUnknownMapping

      public boolean containsUnknownMapping(String className)
      Description copied from interface: TypeConverterHolder
      Checks if no mapping was defined for given class name FIXME lukaszlenart: maybe it should be merged with NoMapping
      Specified by:
      containsUnknownMapping in interface TypeConverterHolder
      Parameters:
      className - name of the class to check for
      Returns:
      true if converter was defined for given class name
    • addUnknownMapping

      public void addUnknownMapping(String className)
      Description copied from interface: TypeConverterHolder
      Adds no converter flag for given class name FIXME lukaszlenart: maybe it should be merged with NoMapping
      Specified by:
      addUnknownMapping in interface TypeConverterHolder
      Parameters:
      className - name of the class to mark there is no converter for it