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

internal.sdmxdl.web.spi.AuthenticatorLoader Maven / Gradle / Ivy

The newest version!
package internal.sdmxdl.web.spi;

import java.lang.Iterable;
import java.util.Collections;
import java.util.List;
import java.util.ServiceLoader;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import sdmxdl.web.spi.Authenticator;

/**
 * Custom service loader for {@link sdmxdl.web.spi.Authenticator}.
 * 
This class is thread-safe. *

Properties: *

    *
  • Quantifier: MULTIPLE
  • *
  • Fallback: null
  • *
  • Preprocessing: wrapper: none filters:[isAuthenticatorAvailable] sorters:[]
  • *
  • Mutability: NONE
  • *
  • Singleton: false
  • *
  • Name: internal.{{canonicalName}}Loader
  • *
  • Backend: null
  • *
  • Cleaner: null
  • *
  • Batch: false
  • *
  • Batch name: null
  • *
*/ public final class AuthenticatorLoader { public static final Pattern ID_PATTERN = Pattern.compile("^[A-Z0-9]+(?:_[A-Z0-9]+)*$"); private final Iterable source = ServiceLoader.load(Authenticator.class); private final Predicate filter = ((Predicate)o -> ID_PATTERN.matcher(o.getAuthenticatorId()).matches()).and(Authenticator::isAuthenticatorAvailable); private final List resource = doLoad(); private List doLoad() { return StreamSupport.stream(source.spliterator(), false) .filter(filter) .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); } /** * Gets a list of {@link sdmxdl.web.spi.Authenticator} instances. *
This method is thread-safe. * @return the current non-null value */ public List get() { return resource; } /** * Gets a list of {@link sdmxdl.web.spi.Authenticator} instances. *
This is equivalent to the following code: new AuthenticatorLoader().get() *
Therefore, the returned value might be different at each call. *
This method is thread-safe. * @return a non-null value */ public static List load() { return new AuthenticatorLoader().get(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy