001// Copyright 2026 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007// http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.ioc.services;
016
017import java.util.ArrayList;
018import java.util.Collections;
019import java.util.List;
020
021import org.apache.tapestry5.ioc.internal.services.PipelineDescriber;
022
023/**
024 * A record of a pipeline assembled by {@link PipelineBuilder}: the service and filter interfaces it bridges,
025 * the filters in the order they are invoked, and the terminator at the end of the chain.
026 *
027 * The filters and the terminator are recorded as descriptions, taken when the pipeline was assembled,
028 * rather than as objects, so that a pipeline no longer in use is not kept alive by this record.
029 *
030 * @since 5.9.2
031 */
032public final class AssembledPipeline
033{
034    private final Class<?> serviceInterface;
035
036    private final Class<?> filterInterface;
037
038    private final List<String> filters;
039
040    private final String terminator;
041
042    public AssembledPipeline(Class<?> serviceInterface, Class<?> filterInterface, List<String> filters,
043                             String terminator)
044    {
045        this.serviceInterface = serviceInterface;
046        this.filterInterface = filterInterface;
047        this.filters = Collections.unmodifiableList(new ArrayList<>(filters));
048        this.terminator = terminator;
049    }
050
051    /**
052     * The interface the pipeline implements.
053     */
054    public Class<?> getServiceInterface()
055    {
056        return serviceInterface;
057    }
058
059    /**
060     * The interface implemented by each filter of the pipeline.
061     */
062    public Class<?> getFilterInterface()
063    {
064        return filterInterface;
065    }
066
067    /**
068     * The filters, in the order they are invoked. Empty when the pipeline is just its terminator.
069     */
070    public List<String> getFilters()
071    {
072        return filters;
073    }
074
075    /**
076     * What the last filter delegates to.
077     */
078    public String getTerminator()
079    {
080        return terminator;
081    }
082
083    @Override
084    public String toString()
085    {
086        List<String> steps = new ArrayList<>(filters);
087
088        steps.add(terminator);
089
090        return PipelineDescriber.describe(PipelineDescriber.header(serviceInterface, filterInterface), steps);
091    }
092}