1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.core.model;
7   
8   import java.net.URI;
9   
10  import edu.umd.cs.findbugs.annotations.NonNull;
11  import edu.umd.cs.findbugs.annotations.Nullable;
12  
13  /**
14   * A common interface for implementation classes that load data resources.
15   */
16  public interface IResourceResolver {
17    /**
18     * Get the entity resolver associated with this loader.
19     *
20     * @return the entity resolver
21     */
22    @Nullable
23    default IUriResolver getUriResolver() {
24      // by default, do not support external URI resolution. Subclasses can override
25      // this behavior
26      return null;
27    }
28  
29    /**
30     * Resolve the provided URI, producing a resolved URI, which may point to a
31     * different resource than the provided URI.
32     *
33     * @param uri
34     *          the URI to resolve
35     * @return the resulting URI
36     */
37    @NonNull
38    default URI resolve(@NonNull URI uri) {
39      IUriResolver resolver = getUriResolver();
40      return resolver == null ? uri : resolver.resolve(uri);
41    }
42  }