1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.databind.model;
7   
8   import gov.nist.secauto.metaschema.core.model.IBoundObject;
9   import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped;
10  import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
11  import gov.nist.secauto.metaschema.core.util.ObjectUtils;
12  import gov.nist.secauto.metaschema.databind.io.BindingException;
13  import gov.nist.secauto.metaschema.databind.model.info.IFeatureComplexItemValueHandler;
14  
15  import edu.umd.cs.findbugs.annotations.Nullable;
16  
17  /**
18   * Represents a model instance that is a member of a choice group instance.
19   */
20  public interface IBoundInstanceModelGroupedNamed
21      extends INamedModelInstanceGrouped, IFeatureComplexItemValueHandler {
22    @Override
23    IBoundInstanceModelChoiceGroup getParentContainer();
24  
25    @Override
26    IBoundDefinitionModelComplex getDefinition();
27  
28    @Override
29    @Nullable
30    default IBoundInstanceFlag getEffectiveJsonKey() {
31      return JsonGroupAsBehavior.KEYED.equals(getParentContainer().getJsonGroupAsBehavior())
32          ? getJsonKey()
33          : null;
34    }
35  
36    @Override
37    default IBoundInstanceFlag getJsonKey() {
38      String name = getParentContainer().getJsonKeyFlagInstanceName();
39      return name == null
40          ? null
41          : ObjectUtils.requireNonNull(getDefinition().getFlagInstanceByName(getContainingModule().toFlagQName(name)));
42    }
43  
44    @Override
45    default IBoundDefinitionModelAssembly getContainingDefinition() {
46      return getParentContainer().getContainingDefinition();
47    }
48  
49    @Override
50    default String getName() {
51      return getDefinition().getName();
52    }
53  
54    @Override
55    default IBoundObject deepCopyItem(IBoundObject item, IBoundObject parentInstance) throws BindingException {
56      return getDefinition().deepCopyItem(item, parentInstance);
57    }
58  
59    @Override
60    default void callBeforeDeserialize(IBoundObject targetObject, IBoundObject parentObject) throws BindingException {
61      getDefinition().callBeforeDeserialize(targetObject, parentObject);
62    }
63  
64    @Override
65    default void callAfterDeserialize(IBoundObject targetObject, IBoundObject parentObject) throws BindingException {
66      getDefinition().callAfterDeserialize(targetObject, parentObject);
67    }
68  }