1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.oscal.lib.profile.resolver.policy;
7   
8   import dev.metaschema.oscal.lib.profile.resolver.ProfileResolutionEvaluationException;
9   import edu.umd.cs.findbugs.annotations.NonNull;
10  import edu.umd.cs.findbugs.annotations.Nullable;
11  
12  public interface IIdentifierParser {
13    @NonNull
14    IIdentifierParser FRAGMENT_PARSER = new PatternIdentifierParser("^#([^#]+)(?:#.*)?$", 1);
15    @NonNull
16    IIdentifierParser IDENTITY_PARSER = new IIdentifierParser() {
17  
18      @Override
19      public String parse(@NonNull String reference) {
20        return reference;
21      }
22  
23      @Override
24      public String update(@NonNull String reference, @NonNull String newIdentifier) {
25        return newIdentifier;
26      }
27    };
28  
29    /**
30     * Parse the {@code referenceText} for the identifier.
31     *
32     * @param referenceText
33     *          the reference text containing the identifier
34     * @return the identifier, or {@code null} if the identifier could not be parsed
35     */
36    @Nullable
37    String parse(@NonNull String referenceText);
38  
39    /**
40     * Substitute the provided {@code newIdentifier} with the identifier in the
41     * {@code referenceText}.
42     *
43     * @param referenceText
44     *          the reference text containing the original identifier
45     * @param newIdentifier
46     *          the new identifier to replace the existing identifier
47     * @return the updated reference text with the identifier replaced
48     * @throws ProfileResolutionEvaluationException
49     *           if the identifier could not be updated
50     */
51    @NonNull
52    String update(@NonNull String referenceText, @NonNull String newIdentifier);
53  }