001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.kernel.api.models; 007 008import java.util.stream.Stream; 009 010import org.fcrepo.kernel.api.Transaction; 011import org.fcrepo.kernel.api.exception.PathNotFoundException; 012import org.fcrepo.kernel.api.identifiers.FedoraId; 013 014/** 015 * Interface to a factory to instantiate FedoraResources 016 * 017 * @author whikloj 018 * @since 2019-09-23 019 */ 020public interface ResourceFactory { 021 022 /** 023 * Get a FedoraResource for existing resource 024 * 025 * @param transaction The transaction associated with this request or null if not in a transaction. 026 * @param fedoraID The identifier for the resource. 027 * @return The resource. 028 * @throws PathNotFoundException If the identifier cannot be found. 029 */ 030 public FedoraResource getResource(final Transaction transaction, final FedoraId fedoraID) 031 throws PathNotFoundException; 032 033 /** 034 * Get a resource as a particular type 035 * 036 * @param <T> type for the resource 037 * @param transaction The transaction associated with this request or null 038 * @param fedoraID The identifier for the resource. 039 * @param clazz class the resource will be cast to 040 * @return The resource. 041 * @throws PathNotFoundException If the identifier cannot be found. 042 */ 043 public <T extends FedoraResource> T getResource(final Transaction transaction, final FedoraId fedoraID, 044 final Class<T> clazz) throws PathNotFoundException; 045 046 /** 047 * Get the containing resource (if exists). 048 * @param transaction The current transaction 049 * @param resourceId The internal identifier 050 * @return The containing resource or null if none. 051 */ 052 public FedoraResource getContainer(final Transaction transaction, final FedoraId resourceId); 053 054 /** 055 * Get immediate children of the resource 056 * @param transaction The transaction 057 * @param resourceId Identifier of the resource 058 * @return Stream of child resources 059 */ 060 public Stream<FedoraResource> getChildren(final Transaction transaction, final FedoraId resourceId); 061}