001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.kernel.api.models;
019
020import java.util.stream.Stream;
021
022import org.fcrepo.kernel.api.Transaction;
023import org.fcrepo.kernel.api.exception.PathNotFoundException;
024import org.fcrepo.kernel.api.identifiers.FedoraId;
025
026/**
027 * Interface to a factory to instantiate FedoraResources
028 *
029 * @author whikloj
030 * @since 2019-09-23
031 */
032public interface ResourceFactory {
033
034    /**
035     * Get a FedoraResource for existing resource
036     *
037     * @param transaction The transaction associated with this request or null if not in a transaction.
038     * @param fedoraID The identifier for the resource.
039     * @return The resource.
040     * @throws PathNotFoundException If the identifier cannot be found.
041     */
042    public FedoraResource getResource(final Transaction transaction, final FedoraId fedoraID)
043            throws PathNotFoundException;
044
045    /**
046     * Get a resource as a particular type
047     *
048     * @param <T> type for the resource
049     * @param transaction The transaction associated with this request or null
050     * @param fedoraID The identifier for the resource.
051     * @param clazz class the resource will be cast to
052     * @return The resource.
053     * @throws PathNotFoundException If the identifier cannot be found.
054     */
055    public <T extends FedoraResource> T getResource(final Transaction transaction, final FedoraId fedoraID,
056                                                    final Class<T> clazz) throws PathNotFoundException;
057
058    /**
059     * Get the containing resource (if exists).
060     * @param transaction The current transaction
061     * @param resourceId The internal identifier
062     * @return The containing resource or null if none.
063     */
064    public FedoraResource getContainer(final Transaction transaction, final FedoraId resourceId);
065
066    /**
067     * Get immediate children of the resource
068     * @param transaction The transaction
069     * @param resourceId Identifier of the resource
070     * @return Stream of child resources
071     */
072    public Stream<FedoraResource> getChildren(final Transaction transaction, final FedoraId resourceId);
073}