001/*-
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.repository;
021
022import ca.uhn.fhir.context.FhirContext;
023import com.google.common.annotations.Beta;
024import jakarta.annotation.Nonnull;
025
026import java.util.Optional;
027
028/**
029 * Service provider interface for loading repositories based on a URL.
030 * Unstable API. Subject to change in future releases.
031 * <p>
032 * Implementors will receive the url parsed into IRepositoryRequest,
033 * and dispatch of the <code>subScheme</code> property.
034 * E.g. The InMemoryFhirRepositoryLoader will handle URLs
035 * that start with <code>fhir-repository:memory:</code>.
036 */
037@Beta()
038public interface IRepositoryLoader {
039        /**
040         * Impelmentors should return true if they can handle the given URL.
041         * @param theRepositoryRequest containing the URL to check
042         * @return true if supported
043         */
044        boolean canLoad(@Nonnull IRepositoryRequest theRepositoryRequest);
045
046        /**
047         * Construct a version of {@link IRepository} based on the given URL.
048         * Implementors can assume that the request passed the canLoad() check.
049         *
050         * @param theRepositoryRequest the details of the repository to load.
051         * @return a repository instance
052         */
053        @Nonnull
054        IRepository loadRepository(@Nonnull IRepositoryRequest theRepositoryRequest);
055
056        interface IRepositoryRequest {
057                /**
058                 * Get the full URL of the repository provided by the user.
059                 * @return the URL
060                 */
061                String getUrl();
062
063                /**
064                 * Get the sub-scheme of the URL, e.g. "memory" for "fhir-repository:memory:details".
065                 * @return the sub-scheme
066                 */
067                String getSubScheme();
068
069                /**
070                 * Get any additional details provided by the user in the URL.
071                 * This may be a url,  a unique identifier for the repository, or configuration details.
072                 * @return the details
073                 */
074                String getDetails();
075
076                Optional<FhirContext> getFhirContext();
077        }
078}