/** * Determines if any {@code RepositoryResolver}s are able to handle a given URI Scheme. * <p> * The lookup method uses the standard JAVA SPI (Service Provider Interface) mechanism, by which * all the {@code META-INF/services/org.locationtech.geogig.repository.RepositoryResolver} files * in the classpath will be scanned for fully qualified names of implementing classes. * * @param scheme the URI scheme * @return {@code true} if any resolver could handle the scheme, {@code false} otherwise */ public static boolean resolverAvailableForURIScheme(String scheme) { Preconditions.checkNotNull(scheme, "URI scheme is null"); List<RepositoryResolver> resolvers = lookupResolvers(); for (RepositoryResolver resolverImpl : resolvers) { final String resolverClassName = resolverImpl.getClass().getName(); if (!DISABLED_RESOLVERS.contains(resolverClassName) && resolverImpl.canHandleURIScheme(scheme)) { return true; } } return false; }
/** * Finds a {@code RepositoryResolver} that {@link #canHandle(URI) can handle} the given URI, or * throws an {@code IllegalArgumentException} if no such initializer can be found. * <p> * The lookup method uses the standard JAVA SPI (Service Provider Interface) mechanism, by which * all the {@code META-INF/services/org.locationtech.geogig.repository.RepositoryResolver} files * in the classpath will be scanned for fully qualified names of implementing classes. * * @param repoURI Repository location URI * @return A RepositoryResolver that can handle the supplied URI. * @throws IllegalArgumentException if no repository resolver is found capable of handling the * given URI */ public static RepositoryResolver lookup(URI repoURI) throws IllegalArgumentException { Preconditions.checkNotNull(repoURI, "Repository URI is null"); List<RepositoryResolver> resolvers = lookupResolvers(); RepositoryResolver resolver = null; for (RepositoryResolver resolverImpl : resolvers) { final String resolverClassName = resolverImpl.getClass().getName(); if (!DISABLED_RESOLVERS.contains(resolverClassName) && resolverImpl.canHandle(repoURI)) { resolver = resolverImpl; break; } } Preconditions.checkArgument(resolver != null, "No repository initializer found capable of handling this kind of URI: %s", repoURI.getScheme()); return resolver; }