1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.core.model;
7   
8   import gov.nist.secauto.metaschema.core.util.ObjectUtils;
9   
10  import edu.umd.cs.findbugs.annotations.NonNull;
11  import edu.umd.cs.findbugs.annotations.Nullable;
12  
13  /**
14   * Represents a named model instance with absolute positioning and JSON
15   * serialization support.
16   * <p>
17   * Provides JSON name resolution based on cardinality and grouping behavior,
18   * with support for JSON key configuration.
19   */
20  public interface INamedModelInstanceAbsolute extends INamedModelInstance, IModelInstanceAbsolute, IJsonInstance {
21    @Override
22    default String getJsonName() {
23      @NonNull
24      String retval;
25      if (getMaxOccurs() == -1 || getMaxOccurs() > 1) {
26        @NonNull
27        String groupAsName = ObjectUtils.requireNonNull(getGroupAsName(),
28            ObjectUtils.notNull(String.format("null group-as name in instance '%s' on definition '%s' in '%s'",
29                this.getName(),
30                this.getContainingDefinition().getName(),
31                this.getContainingModule().getLocation())));
32        retval = groupAsName;
33      } else {
34        retval = getEffectiveName();
35      }
36      return retval;
37    }
38  
39    @Override
40    @Nullable
41    default IFlagInstance getEffectiveJsonKey() {
42      return getJsonGroupAsBehavior() == JsonGroupAsBehavior.KEYED
43          ? getJsonKey()
44          : null;
45    }
46  
47    @Override
48    @Nullable
49    default IFlagInstance getJsonKey() {
50      return getDefinition().getJsonKey();
51    }
52  }