001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package dev.metaschema.core.model; 007 008import java.net.URI; 009 010import edu.umd.cs.findbugs.annotations.NonNull; 011import edu.umd.cs.findbugs.annotations.Nullable; 012 013/** 014 * A common interface for implementation classes that load data resources. 015 */ 016public interface IResourceResolver { 017 /** 018 * Get the entity resolver associated with this loader. 019 * 020 * @return the entity resolver 021 */ 022 @Nullable 023 default IUriResolver getUriResolver() { 024 // by default, do not support external URI resolution. Subclasses can override 025 // this behavior 026 return null; 027 } 028 029 /** 030 * Resolve the provided URI, producing a resolved URI, which may point to a 031 * different resource than the provided URI. 032 * 033 * @param uri 034 * the URI to resolve 035 * @return the resulting URI 036 */ 037 @NonNull 038 default URI resolve(@NonNull URI uri) { 039 IUriResolver resolver = getUriResolver(); 040 return resolver == null ? uri : resolver.resolve(uri); 041 } 042}