All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.avaje.validation.core.ExtensionLoader Maven / Gradle / Ivy

Go to download

validator for annotated pojos using constraint annotations and source code generation

There is a newer version: 2.4
Show newest version
package io.avaje.validation.core;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;

import io.avaje.validation.spi.AdapterFactory;
import io.avaje.validation.spi.AnnotationFactory;
import io.avaje.validation.spi.GeneratedComponent;
import io.avaje.validation.spi.MessageInterpolator;
import io.avaje.validation.spi.ValidatorCustomizer;
import io.avaje.validation.spi.ValidationExtension;

/** Load all the services using the common service interface. */
final class ExtensionLoader {

  private final List generatedComponents = new ArrayList<>();
  private final List customizers = new ArrayList<>();
  private final List adapterFactories = new ArrayList<>();
  private final List annotationFactories = new ArrayList<>();
  private Optional interpolator = Optional.empty();

  ExtensionLoader() {
    for (var spi : ServiceLoader.load(ValidationExtension.class)) {
      if (spi instanceof GeneratedComponent gc) {
        generatedComponents.add(gc);
      } else if (spi instanceof ValidatorCustomizer c) {
        customizers.add(c);
      } else if (spi instanceof MessageInterpolator m) {
        interpolator = Optional.of(m);
      } else if (spi instanceof AdapterFactory af) {
        adapterFactories.add(af);
      } else if (spi instanceof AnnotationFactory af) {
        annotationFactories.add(af);
      }
    }
  }

  Optional interpolator() {
    return interpolator;
  }

  List generatedComponents() {
    return generatedComponents;
  }

  List customizers() {
    return customizers;
  }

  List adapterFactories() {
    return adapterFactories;
  }

  List annotationFactories() {
    return annotationFactories;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy