001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.oscal.lib.profile.resolver.policy;
007
008import gov.nist.secauto.metaschema.core.metapath.item.node.IModelNodeItem;
009import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolutionEvaluationException;
010
011import edu.umd.cs.findbugs.annotations.NonNull;
012
013@FunctionalInterface
014public interface IReferencePolicy<T> {
015  @NonNull
016  IReferencePolicy<Object> IGNORE_POLICY = new IReferencePolicy<>() {
017
018    @Override
019    public boolean handleReference(
020        @NonNull IModelNodeItem<?, ?> contextItem,
021        @NonNull Object reference,
022        @NonNull ReferenceCountingVisitor.Context referenceVisitorContext) {
023      return true;
024    }
025  };
026
027  /**
028   * Get a reference policy that will ignore processing the reference.
029   *
030   * @param <T>
031   *          the type of the reference object
032   * @return the policy
033   */
034  @SuppressWarnings("unchecked")
035  @NonNull
036  static <T> IReferencePolicy<T> ignore() {
037    return (IReferencePolicy<T>) IGNORE_POLICY;
038  }
039
040  /**
041   * Handle the provided {@code reference}.
042   *
043   * @param contextItem
044   *          the nodes containing the reference
045   * @param reference
046   *          the reference object to process
047   * @param referenceVisitorContext
048   *          used to lookup and resolve items
049   * @return {@code true} if the reference was handled, or {@code false} otherwise
050   * @throws ProfileResolutionEvaluationException
051   *           if there was an error handing the reference
052   */
053  boolean handleReference(
054      @NonNull IModelNodeItem<?, ?> contextItem,
055      @NonNull T reference,
056      @NonNull ReferenceCountingVisitor.Context referenceVisitorContext);
057}