Class TypeManagerImpl
- All Implemented Interfaces:
TypeManager
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.tocco.nice2.types.api.TypeManager
TypeManager.ParseFlags
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> T
<T> T
Attempts to convert any object to the desired target type.void
ensureType
(@Nullable String name) Makes sure the required type exists in the nice system.@Nullable Type
<?> findBaseType
(Class<?> representationClass) Finds theType
for the given java class for one of its ancestors, if any.<T> @Nullable Type
<T> getBaseType
(Class<T> representationClass) Returns theType
for the given java class, if any.Collection
<Type<?>> Returns all available base types (the real ones, without virtual ones).@Nullable Type
<?> Returns the Type (base or virtual) for the name specified.Collection
<Type<?>> getTypes()
Returns all available types (including virtual ones).boolean
Tells if such a type or virtual type exists.Type
<?> matchTypes
(Type<?> one, Type<?> two) TypedValue
<?> parse
(String str, TypeManager.ParseFlags... flags) TypedValue
<?> parse
(String typeName, String value, TypeManager.ParseFlags... flags) TypedValue
<?> parse
(String typeName, String value, TypeManager.ParseFlags[] flags, String fullValue) <T> Type
<T> requireBaseType
(Class<T> representationClass) Same asTypeManager.getBaseType(java.lang.Class<T>)
but throws if missing.Type
<?> requireType
(String name) Same asTypeManager.getType(java.lang.String)
but throws if missing.void
setAdaptersConfig
(List<AdapterContribution> contribs) This is where type adapters from contributions come in.void
setBaseTypesConfig
(List<BaseTypeContribution> contribs) The contributions are merged in, existing ones are kept.void
setConversionsConfig
(List<ConversionContribution> contribs) The contributions are merged in, existing ones are kept.void
setTypeConfig
(List<BaseTypeContribution> baseTypes, List<VirtualTypeContribution> virtualTypes, List<ConversionContribution> conversions, List<AdapterContribution> adapters) void
setVirtualTypesConfig
(List<VirtualTypeContribution> contribs) The contributions are merged in, existing ones are kept.@Nullable String
suggestType
(String name) Suggests the correct type name when the one looked for does not exist.
-
Constructor Details
-
TypeManagerImpl
public TypeManagerImpl(org.slf4j.Logger log)
-
-
Method Details
-
setTypeConfig
@Autowired public void setTypeConfig(List<BaseTypeContribution> baseTypes, List<VirtualTypeContribution> virtualTypes, List<ConversionContribution> conversions, List<AdapterContribution> adapters) -
setBaseTypesConfig
The contributions are merged in, existing ones are kept. Exceptions are thrown on duplicates.
-
setVirtualTypesConfig
The contributions are merged in, existing ones are kept. Exceptions are thrown on duplicates.
-
setConversionsConfig
The contributions are merged in, existing ones are kept. Exceptions are thrown on duplicates.
-
setAdaptersConfig
This is where type adapters from contributions come in.The contributions are merged in, existing ones are kept. Exceptions are thrown on duplicates.
Type adapters may implement TypeReceivable (setType()) to receive a reference to their type. For example AbstractTypeAdapter does this.
- Parameters:
contribs
- The contributions.
-
getTypes
Description copied from interface:TypeManager
Returns all available types (including virtual ones).- Specified by:
getTypes
in interfaceTypeManager
-
hasType
Description copied from interface:TypeManager
Tells if such a type or virtual type exists.- Specified by:
hasType
in interfaceTypeManager
- Parameters:
name
- The type's name, eg 'string'.
-
getType
Description copied from interface:TypeManager
Returns the Type (base or virtual) for the name specified. See https://wiki.tocco.ch/wiki/index.php/Nice2-types- Specified by:
getType
in interfaceTypeManager
- Parameters:
name
- The type's name, eg 'string'.- Returns:
- Null if no such type.
- See Also:
-
getBaseTypes
Description copied from interface:TypeManager
Returns all available base types (the real ones, without virtual ones).- Specified by:
getBaseTypes
in interfaceTypeManager
-
getBaseType
Description copied from interface:TypeManager
Returns theType
for the given java class, if any. For the java to type mappings see https://wiki.tocco.ch/wiki/index.php/Nice2-types- Specified by:
getBaseType
in interfaceTypeManager
- Parameters:
representationClass
- The class.- Returns:
- The type. Null if none. Never a virtual type.
- See Also:
-
findBaseType
Description copied from interface:TypeManager
Finds theType
for the given java class for one of its ancestors, if any. For the java to type mappings see https://wiki.tocco.ch/wiki/index.php/Nice2-types- Specified by:
findBaseType
in interfaceTypeManager
- Parameters:
representationClass
- The class.- Returns:
- The type. Null if none. Never a virtual type.
-
requireType
Description copied from interface:TypeManager
Same asTypeManager.getType(java.lang.String)
but throws if missing.- Specified by:
requireType
in interfaceTypeManager
- Throws:
NoSuchTypeException
- See Also:
-
requireBaseType
Description copied from interface:TypeManager
Same asTypeManager.getBaseType(java.lang.Class<T>)
but throws if missing.- Specified by:
requireBaseType
in interfaceTypeManager
- Throws:
NoSuchTypeException
- See Also:
-
parse
public TypedValue<?> parse(String str, TypeManager.ParseFlags... flags) throws StringConversionException - Specified by:
parse
in interfaceTypeManager
- Throws:
StringConversionException
-
parse
public TypedValue<?> parse(String typeName, String value, TypeManager.ParseFlags... flags) throws StringConversionException - Specified by:
parse
in interfaceTypeManager
- Throws:
StringConversionException
-
convert
@Nullable public <T> T convert(@Nullable @Nullable Object o, Type<T> targetType) throws TypeConversionException Description copied from interface:TypeManager
Attempts to convert any object to the desired target type.- Specified by:
convert
in interfaceTypeManager
- Parameters:
o
- The object to convert.- Returns:
- Object as the converted type, null if input was null (null-in-null-out).
- Throws:
TypeConversionException
- If there is no such type converter, or the conversion fails.
-
convert
@Nullable public <T> T convert(@Nullable @Nullable Object o, Type<?> sourceType, Type<T> targetType) throws TypeConversionException - Specified by:
convert
in interfaceTypeManager
- Throws:
TypeConversionException
-
parse
public TypedValue<?> parse(String typeName, String value, TypeManager.ParseFlags[] flags, String fullValue) throws StringConversionException - Throws:
StringConversionException
-
matchTypes
- Specified by:
matchTypes
in interfaceTypeManager
-
getStringType
- Specified by:
getStringType
in interfaceTypeManager
-
getIntegerType
- Specified by:
getIntegerType
in interfaceTypeManager
-
getLongType
- Specified by:
getLongType
in interfaceTypeManager
-
getDoubleType
- Specified by:
getDoubleType
in interfaceTypeManager
-
getBooleanType
- Specified by:
getBooleanType
in interfaceTypeManager
-
getGlobType
- Specified by:
getGlobType
in interfaceTypeManager
-
getNullType
- Specified by:
getNullType
in interfaceTypeManager
-
suggestType
Description copied from interface:TypeManager
Suggests the correct type name when the one looked for does not exist.Examples are "String" → "string" and "int" → "integer".
If the requested type really exists then the same string is returned, though that's not what this method is meant for.
If the requested type does not look familiar in any way then null is returned.
This method is meant for checking (configuration) input, and telling the implementor quickly what the correct type name is.
- Specified by:
suggestType
in interfaceTypeManager
- Returns:
- The correct type name, or null.
- See Also:
-
ensureType
Description copied from interface:TypeManager
Makes sure the required type exists in the nice system.If missing then the desired exception is thrown, along with meaningful text info.
This is useful for config readers etc.
- Specified by:
ensureType
in interfaceTypeManager
- Parameters:
name
- The type's name, eg 'string'.
-