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
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T<T> TAttempts to convert any object to the desired target type.voidensureType(@Nullable String name) Makes sure the required type exists in the nice system.@Nullable Type<?> findBaseType(Class<?> representationClass) Finds theTypefor the given java class for one of its ancestors, if any.<T> @Nullable Type<T> getBaseType(Class<T> representationClass) Returns theTypefor 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).booleanTells 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.voidsetAdaptersConfig(List<AdapterContribution> contribs) This is where type adapters from contributions come in.voidsetBaseTypesConfig(List<BaseTypeContribution> contribs) The contributions are merged in, existing ones are kept.voidsetConversionsConfig(List<ConversionContribution> contribs) The contributions are merged in, existing ones are kept.voidsetTypeConfig(List<BaseTypeContribution> baseTypes, List<VirtualTypeContribution> virtualTypes, List<ConversionContribution> conversions, List<AdapterContribution> adapters) voidsetVirtualTypesConfig(List<VirtualTypeContribution> contribs) The contributions are merged in, existing ones are kept.@Nullable StringsuggestType(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:TypeManagerReturns all available types (including virtual ones).- Specified by:
getTypesin interfaceTypeManager
-
hasType
Description copied from interface:TypeManagerTells if such a type or virtual type exists.- Specified by:
hasTypein interfaceTypeManager- Parameters:
name- The type's name, eg 'string'.
-
getType
Description copied from interface:TypeManagerReturns the Type (base or virtual) for the name specified. See https://wiki.tocco.ch/wiki/index.php/Nice2-types- Specified by:
getTypein interfaceTypeManager- Parameters:
name- The type's name, eg 'string'.- Returns:
- Null if no such type.
- See Also:
-
getBaseTypes
Description copied from interface:TypeManagerReturns all available base types (the real ones, without virtual ones).- Specified by:
getBaseTypesin interfaceTypeManager
-
getBaseType
Description copied from interface:TypeManagerReturns theTypefor the given java class, if any. For the java to type mappings see https://wiki.tocco.ch/wiki/index.php/Nice2-types- Specified by:
getBaseTypein interfaceTypeManager- Parameters:
representationClass- The class.- Returns:
- The type. Null if none. Never a virtual type.
- See Also:
-
findBaseType
Description copied from interface:TypeManagerFinds theTypefor 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:
findBaseTypein interfaceTypeManager- Parameters:
representationClass- The class.- Returns:
- The type. Null if none. Never a virtual type.
-
requireType
Description copied from interface:TypeManagerSame asTypeManager.getType(java.lang.String)but throws if missing.- Specified by:
requireTypein interfaceTypeManager- Throws:
NoSuchTypeException- See Also:
-
requireBaseType
Description copied from interface:TypeManagerSame asTypeManager.getBaseType(java.lang.Class<T>)but throws if missing.- Specified by:
requireBaseTypein interfaceTypeManager- Throws:
NoSuchTypeException- See Also:
-
parse
public TypedValue<?> parse(String str, TypeManager.ParseFlags... flags) throws StringConversionException - Specified by:
parsein interfaceTypeManager- Throws:
StringConversionException
-
parse
public TypedValue<?> parse(String typeName, String value, TypeManager.ParseFlags... flags) throws StringConversionException - Specified by:
parsein interfaceTypeManager- Throws:
StringConversionException
-
convert
@Nullable public <T> T convert(@Nullable @Nullable Object o, Type<T> targetType) throws TypeConversionException Description copied from interface:TypeManagerAttempts to convert any object to the desired target type.- Specified by:
convertin 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:
convertin interfaceTypeManager- Throws:
TypeConversionException
-
parse
public TypedValue<?> parse(String typeName, String value, TypeManager.ParseFlags[] flags, String fullValue) throws StringConversionException - Throws:
StringConversionException
-
matchTypes
- Specified by:
matchTypesin interfaceTypeManager
-
getStringType
- Specified by:
getStringTypein interfaceTypeManager
-
getIntegerType
- Specified by:
getIntegerTypein interfaceTypeManager
-
getLongType
- Specified by:
getLongTypein interfaceTypeManager
-
getDoubleType
- Specified by:
getDoubleTypein interfaceTypeManager
-
getBooleanType
- Specified by:
getBooleanTypein interfaceTypeManager
-
getGlobType
- Specified by:
getGlobTypein interfaceTypeManager
-
getNullType
- Specified by:
getNullTypein interfaceTypeManager
-
suggestType
Description copied from interface:TypeManagerSuggests 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:
suggestTypein interfaceTypeManager- Returns:
- The correct type name, or null.
- See Also:
-
ensureType
Description copied from interface:TypeManagerMakes 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:
ensureTypein interfaceTypeManager- Parameters:
name- The type's name, eg 'string'.
-