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
013public interface IReferencePolicy<T> {
014  @NonNull
015  IReferencePolicy<Object> IGNORE_POLICY = new IReferencePolicy<>() {
016
017    @Override
018    public boolean handleReference(
019        @NonNull IModelNodeItem<?, ?> contextItem,
020        @NonNull Object reference,
021        @NonNull ReferenceCountingVisitor.Context referenceVisitorContext) {
022      return true;
023    }
024  };
025
026  /**
027   * Get a reference policy that will ignore processing the reference.
028   *
029   * @param <T>
030   *          the type of the reference object
031   * @return the policy
032   */
033  @SuppressWarnings("unchecked")
034  @NonNull
035  static <T> IReferencePolicy<T> ignore() {
036    return (IReferencePolicy<T>) IGNORE_POLICY;
037  }
038
039  /**
040   * Handle the provided {@code reference}.
041   *
042   * @param contextItem
043   *          the nodes containing the reference
044   * @param reference
045   *          the reference object to process
046   * @param referenceVisitorContext
047   *          used to lookup and resolve items
048   * @return {@code true} if the reference was handled, or {@code false} otherwise
049   * @throws ProfileResolutionEvaluationException
050   *           if there was an error handing the reference
051   */
052  boolean handleReference(
053      @NonNull IModelNodeItem<?, ?> contextItem,
054      @NonNull T reference,
055      @NonNull ReferenceCountingVisitor.Context referenceVisitorContext);
056}