use of org.apache.ignite.internal.configuration.util.ConfigurationUtil in project ignite-3 by apache.
the class ConfigurationRegistry method polymorphicExtensionsWithCheck.
/**
* Get polymorphic extensions of configuration schemas with checks.
*
* @param allSchemas All configuration schemas.
* @param polymorphicSchemaExtensions Polymorphic extensions ({@link PolymorphicConfigInstance}) of configuration schemas.
* @return Mapping: polymorphic scheme -> extensions (instances) of polymorphic configuration.
* @throws IllegalArgumentException If the schema extension is invalid.
*/
private Map<Class<?>, Set<Class<?>>> polymorphicExtensionsWithCheck(Set<Class<?>> allSchemas, Collection<Class<?>> polymorphicSchemaExtensions) {
Map<Class<?>, Set<Class<?>>> polymorphicExtensionsByParent = polymorphicSchemaExtensions(polymorphicSchemaExtensions);
Set<Class<?>> notInAllSchemas = difference(polymorphicExtensionsByParent.keySet(), allSchemas);
if (!notInAllSchemas.isEmpty()) {
throw new IllegalArgumentException("Polymorphic extensions for which no polymorphic configuration schemas were found: " + notInAllSchemas);
}
Collection<Class<?>> noPolymorphicExtensionsSchemas = allSchemas.stream().filter(ConfigurationUtil::isPolymorphicConfig).filter(not(polymorphicExtensionsByParent::containsKey)).collect(toList());
if (!noPolymorphicExtensionsSchemas.isEmpty()) {
throw new IllegalArgumentException("Polymorphic configuration schemas for which no extensions were found: " + noPolymorphicExtensionsSchemas);
}
checkPolymorphicConfigIds(polymorphicExtensionsByParent);
for (Map.Entry<Class<?>, Set<Class<?>>> e : polymorphicExtensionsByParent.entrySet()) {
Class<?> schemaClass = e.getKey();
Field typeIdField = schemaFields(schemaClass).get(0);
if (!isPolymorphicId(typeIdField)) {
throw new IllegalArgumentException(String.format("First field in a polymorphic configuration schema must contain @%s: %s", PolymorphicId.class, schemaClass.getName()));
}
}
return polymorphicExtensionsByParent;
}
Aggregations