Class DefaultEncodingRegistry
- All Implemented Interfaces:
EncodingRegistry
EncodingRegistry.
Instances automatically register all of Permazen's built-in Encodings (see below).
Array Types
Because this class is a subclass of SimpleEncodingRegistry, encodings for array types
(other than primitive arrays) are created on demand, so they don't need to be explicitly registered.
Enum Types
Encodings for Enum types are not registered in an EncodingRegistry. Instead, Enum
values are represented as EnumValue instances, and Enum fields are specially
defined in the schema with an explicit identifier list. In turn, EnumValue's are
encoded by EnumValueEncoding.
Custom Encodings
During construction, instances scan the class path for custom EncodingRegistry implementations
and will delegate to them when an encoding is not found. Custom EncodingRegistry implementations are specified via
META-INF/services/io.permazen.encoding.EncodingRegistry files or by module exports; see ServiceLoader.
Custom implementations are only queried for non-array types.
If multiple custom EncodingRegistry implementations advertise the same encoding, one will be
chosen arbitrarily.
Built-in Encodings
Permazen provides built-in Encodings covering the following Java types:
- Primitive types (
boolean,int, etc.) - Primitive array types (
boolean[],int[], etc.) - Primitive wrapper types (
Boolean,Integer, etc.) StringBigDecimalBigIntegerBitSetDateUUIDIntSummaryStatisticsLongSummaryStatisticsDoubleSummaryStatisticsURIFileInetAddressInet4AddressInet6AddressPatternjava.time.*InternetAddress(if present on the classpath)
-
Field Summary
FieldsFields inherited from class io.permazen.encoding.SimpleEncodingRegistry
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidRegister Permazen's built-in encodings.protected voidaddOptionalBuiltinEncoding(String name, Function<EncodingId, ? extends Encoding<?>> builder) Register a built-in encoding, but only if its target class is found on the classpath.protected voidRegister Permazen's optional built-in encodings.protected voidRegister Permazen's standard built-in encodings.aliasForId(EncodingId encodingId) Get the alias (or "nickname") for the given encoding ID in this registry, if any.protected voidScan the class path (viaServiceLoaderand the current thread's context class loader) for customEncodingRegistryimplementationsEncoding<?>getEncoding(EncodingId encodingId) Get theEncodingwith the given encoding ID in this registry.getEncodings(TypeToken<T> typeToken) Get all of theEncodings in this registry that supports values of the given Java type.idForAlias(String alias) Get the encoding ID corresponding to the given alias (or "nickname"), if any.protected voidInitialize this instance.Methods inherited from class io.permazen.encoding.SimpleEncodingRegistry
add, addNullSafe, buildArrayEncoding, registerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.permazen.encoding.EncodingRegistry
getEncoding, getEncoding
-
Field Details
-
customEncodingRegistries
-
-
Constructor Details
-
DefaultEncodingRegistry
public DefaultEncodingRegistry()Constructor.This constructor invokes
initialize().
-
-
Method Details
-
idForAlias
Description copied from interface:EncodingRegistryGet the encoding ID corresponding to the given alias (or "nickname"), if any.See
aliasForId()for details on aliases.If
aliasis a valid alias, this method should return the correspondingEncodingId. Ifaliasis not a valid alias, but is a valid encoding ID in string form, this method should return the correspondingEncodingIdas if bynew EncodingId(alias). Otherwise, this method should throwIllegalArgumentException.Note: the
EncodingIdcorresponding to an alias does not need to be actually registered with this instance in order for the alias to be valid.The implementation in
EncodingRegistryjust invokesnew EncodingId(alias).- Parameters:
alias- encoding ID alias- Returns:
- corresponding encoding ID, never null
-
aliasForId
Description copied from interface:EncodingRegistryGet the alias (or "nickname") for the given encoding ID in this registry, if any.An
EncodingRegistrymay support aliases for some of its encoding ID's. Aliases are simply more friendly names forEncodingIdstrings, which are formatted as Uniform Resource Names (URNs).Whereas
EncodingId's are globally unique, aliases are only meaningful to the particularEncodingRegistryinstance being queried. When a schema is recorded in a database, actualEncodingId's are always used.In Permazen's
DefaultEncodingRegistry, the built-in encodings all have aliases; for example,"int"is an alias for"urn:fdc:permazen.io:2020:int". Permazen's built-in encoding aliases are available viaEncodingIds.aliasForId()andEncodingIds.idForAlias().If no alias is known for
encodingId, this method should returnEncodingId.getId().Note: an
EncodingIddoes not need to be actually registered with this instance in order for it to have an alias.The implementation in
EncodingRegistryalways returnsEncodingId.getId().- Parameters:
encodingId- encoding ID- Returns:
- corresponding alias, if any, otherwise
EncodingId.getId() - See Also:
-
getEncoding
Description copied from interface:EncodingRegistryGet theEncodingwith the given encoding ID in this registry.- Specified by:
getEncodingin interfaceEncodingRegistry- Overrides:
getEncodingin classSimpleEncodingRegistry- Parameters:
encodingId- encoding ID- Returns:
- corresponding
Encoding, if any, otherwise null
-
getEncodings
Description copied from interface:EncodingRegistryGet all of theEncodings in this registry that supports values of the given Java type.The Java type must exactly match the
Encoding's supported Java type.- Specified by:
getEncodingsin interfaceEncodingRegistry- Overrides:
getEncodingsin classSimpleEncodingRegistry- Type Parameters:
T- encoding value type- Parameters:
typeToken- encoding value type- Returns:
- unmodifiable list of
Encodings supporting Java values of typetypeToken, possibly empty
-
initialize
protected void initialize()Initialize this instance.This method is invoked by the default constructor. The implementation in
DefaultEncodingRegistryinvokesaddBuiltinEncodings()and thenfindCustomEncodingRegistries(). -
addBuiltinEncodings
protected void addBuiltinEncodings()Register Permazen's built-in encodings.The implementation in
DefaultEncodingRegistryinvokesaddStandardBuiltinEncodings()and thenaddOptionalBuiltinEncodings(). -
addStandardBuiltinEncodings
protected void addStandardBuiltinEncodings()Register Permazen's standard built-in encodings. -
addOptionalBuiltinEncodings
protected void addOptionalBuiltinEncodings()Register Permazen's optional built-in encodings.The optional built-in encodings are ones that depend on optional dependencies. An example is
InternetAddressEncodingwhich depends on the Jakarta Mail API. -
addOptionalBuiltinEncoding
protected void addOptionalBuiltinEncoding(String name, Function<EncodingId, ? extends Encoding<?>> builder) Register a built-in encoding, but only if its target class is found on the classpath.The implementation in
DefaultEncodingRegistryinvokes the givenbuilderbut will catch and ignore anyNoClassDefFoundErrorthrown. Otherwise, the encoding is registered.No attempt to initialize the encoding class should have occurred prior to invoking this method.
- Parameters:
name- builtin encoding ID suffixbuilder- builder for encoding
-
findCustomEncodingRegistries
protected void findCustomEncodingRegistries()Scan the class path (viaServiceLoaderand the current thread's context class loader) for customEncodingRegistryimplementations
-