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