
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 ca.uhn.fhir.repository.impl.UrlRepositoryFactory; 024import jakarta.annotation.Nonnull; 025 026/** 027 * Static factory methods for creating instances of {@link IRepository}. 028 */ 029public class Repositories { 030 /** 031 * Private constructor to prevent instantiation. 032 */ 033 Repositories() {} 034 035 public static boolean isRepositoryUrl(String theBaseUrl) { 036 return UrlRepositoryFactory.isRepositoryUrl(theBaseUrl); 037 } 038 039 /** 040 * Constructs a version of {@link IRepository} based on the given URL. 041 * These URLs are expected to be in the form of fhir-repository:subscheme:details. 042 * Currently supported subschemes include: 043 * <ul> 044 * <li>memory - e.g. fhir-repository:memory:my-repo - the last piece (my-repo) identifies the repository</li> 045 * </ul> 046 * <p> 047 * The subscheme is used to find a matching {@link IRepositoryLoader} implementation. 048 * 049 * @param theFhirContext the FHIR context to use for the repository. 050 * @param theRepositoryUrl a url of the form fhir-repository:subscheme:details 051 * @return a repository instance 052 * @throws IllegalArgumentException if the URL is not a valid repository URL, or no loader can be found for the URL. 053 */ 054 @Nonnull 055 public static IRepository repositoryForUrl(@Nonnull FhirContext theFhirContext, @Nonnull String theRepositoryUrl) { 056 return UrlRepositoryFactory.buildRepository(theFhirContext, theRepositoryUrl); 057 } 058}