001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package dev.metaschema.core.model; 007 008import java.io.File; 009import java.io.IOException; 010import java.net.URI; 011import java.net.URL; 012import java.nio.file.Path; 013import java.util.Collection; 014 015import dev.metaschema.core.util.ObjectUtils; 016import edu.umd.cs.findbugs.annotations.NonNull; 017 018/** 019 * Provides loading capabilities for resources of type {@code T}. 020 * <p> 021 * Supports loading from various sources including URIs, paths, files, and URLs. 022 * 023 * @param <T> 024 * the type of resource loaded by this loader 025 */ 026public interface ILoader<T> { 027 /** 028 * Retrieve the set of loaded resources. 029 * 030 * @return the set of loaded resources 031 */ 032 @NonNull 033 Collection<T> getLoadedResources(); 034 035 /** 036 * Load a resource from the specified URI. 037 * 038 * @param resource 039 * the resource to load 040 * @return the loaded instance for the specified resource 041 * @throws MetaschemaException 042 * if an error occurred while processing the resource 043 * @throws IOException 044 * if an error occurred parsing the resource 045 */ 046 @NonNull 047 T load(@NonNull URI resource) throws MetaschemaException, IOException; 048 049 /** 050 * Load a resource from the specified path. 051 * 052 * @param path 053 * the resource to load 054 * @return the loaded instance for the specified resource 055 * @throws MetaschemaException 056 * if an error occurred while processing the resource 057 * @throws IOException 058 * if an error occurred parsing the resource 059 */ 060 @NonNull 061 T load(@NonNull Path path) throws MetaschemaException, IOException; 062 063 /** 064 * Load a resource from the specified file. 065 * 066 * @param file 067 * the resource to load 068 * @return the loaded instance for the specified resource 069 * @throws MetaschemaException 070 * if an error occurred while processing the resource 071 * @throws IOException 072 * if an error occurred parsing the resource 073 */ 074 @NonNull 075 default T load(@NonNull File file) throws MetaschemaException, IOException { 076 return load(ObjectUtils.notNull(file.toPath())); 077 } 078 079 /** 080 * Loads a resource from the specified URL. 081 * 082 * @param url 083 * the URL to load the resource from 084 * @return the loaded instance for the specified resource 085 * @throws MetaschemaException 086 * if an error occurred while processing the resource 087 * @throws IOException 088 * if an error occurred parsing the resource 089 */ 090 @NonNull 091 T load(@NonNull URL url) throws MetaschemaException, IOException; 092}