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