001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*-
002 *
003 * Copyright © 2023–2025 microBean™.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
006 * the License. You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
011 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
012 * specific language governing permissions and limitations under the License.
013 */
014package org.microbean.bean;
015
016import java.util.function.BiFunction;
017
018/**
019 * An interface whose implementations install <dfn>around-invoke</dfn> interceptions.
020 *
021 * @param <I> the type of contextual instance
022 *
023 * <p>{@link InterceptionsApplicator} implementations are typically used to implement the {@link
024 * Factory#create(Request)} method, together with {@link PostInitializer}s, {@link Initializer}s and {@link Producer}s.</p>
025 *
026 * @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
027 *
028 * @see #apply(Object, Request)
029 *
030 * @see PostInitializer
031 *
032 * @see Initializer
033 *
034 * @see Producer
035 */
036// Subordinate to Factory<I>. Normally applied to PostInitializer<I> output.
037// An applicator of business method interceptions. This is used during assembly of a Factory implementation and should
038// be used probably only when "around-invoke" interceptions are in effect.
039@FunctionalInterface
040public interface InterceptionsApplicator<I> extends BiFunction<I, Request<I>, I> {
041
042  /**
043   * Installs <dfn>around-invoke</dfn> method interceptions on the supplied contextual instance, which is presumed to
044   * have been {@linkplain PostInitializer fully initialized}, and returns the result.
045   *
046   * @param uninterceptedInstance a fully initialized contextual instance that needs to have certain of its methods
047   * intercepted; must not be {@code null}
048   *
049   * @param r a {@link Request} which may be used to acquire supporting contextual references; must not be {@code null}
050   *
051   * @return the supplied contextual instance, a copy of it, or a proxy wrapping it; never {@code null}
052   *
053   * @exception NullPointerException if any argument is {@code null}
054   */
055  @Override // BiFunction<I, Request<I>, I>
056  public I apply(final I uninterceptedInstance, final Request<I> r);
057
058}