001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.databind.model;
007
008import gov.nist.secauto.metaschema.core.model.IBoundObject;
009import gov.nist.secauto.metaschema.core.model.INamedModelInstanceGrouped;
010import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
011import gov.nist.secauto.metaschema.core.model.util.ModuleUtils;
012import gov.nist.secauto.metaschema.core.util.ObjectUtils;
013import gov.nist.secauto.metaschema.databind.io.BindingException;
014import gov.nist.secauto.metaschema.databind.model.info.IFeatureComplexItemValueHandler;
015
016import edu.umd.cs.findbugs.annotations.Nullable;
017
018/**
019 * Represents a model instance that is a member of a choice group instance.
020 */
021public interface IBoundInstanceModelGroupedNamed
022    extends INamedModelInstanceGrouped, IFeatureComplexItemValueHandler {
023  @Override
024  IBoundInstanceModelChoiceGroup getParentContainer();
025
026  @Override
027  IBoundDefinitionModelComplex getDefinition();
028
029  @Override
030  @Nullable
031  default IBoundInstanceFlag getEffectiveJsonKey() {
032    return JsonGroupAsBehavior.KEYED.equals(getParentContainer().getJsonGroupAsBehavior())
033        ? getJsonKey()
034        : null;
035  }
036
037  @Override
038  default IBoundInstanceFlag getJsonKey() {
039    String name = getParentContainer().getJsonKeyFlagInstanceName();
040    return name == null
041        ? null
042        : ObjectUtils.requireNonNull(
043            getDefinition().getFlagInstanceByName(
044                ModuleUtils.parseFlagName(getContainingModule(), name).getIndexPosition()));
045  }
046
047  @Override
048  default IBoundDefinitionModelAssembly getContainingDefinition() {
049    return getParentContainer().getContainingDefinition();
050  }
051
052  @Override
053  default String getName() {
054    return getDefinition().getName();
055  }
056
057  @Override
058  default IBoundObject deepCopyItem(IBoundObject item, IBoundObject parentInstance) throws BindingException {
059    return getDefinition().deepCopyItem(item, parentInstance);
060  }
061
062  @Override
063  default void callBeforeDeserialize(IBoundObject targetObject, IBoundObject parentObject) throws BindingException {
064    getDefinition().callBeforeDeserialize(targetObject, parentObject);
065  }
066
067  @Override
068  default void callAfterDeserialize(IBoundObject targetObject, IBoundObject parentObject) throws BindingException {
069    getDefinition().callAfterDeserialize(targetObject, parentObject);
070  }
071}