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.INamedModelInstanceAbsolute;
009import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
010
011import java.util.Collection;
012
013import javax.xml.namespace.QName;
014
015import edu.umd.cs.findbugs.annotations.NonNull;
016import edu.umd.cs.findbugs.annotations.Nullable;
017
018public interface IBoundInstanceModelNamed<ITEM>
019    extends IBoundInstanceModel<ITEM>, INamedModelInstanceAbsolute {
020
021  @Override
022  @NonNull
023  IBoundDefinitionModel<ITEM> getDefinition();
024
025  @Override
026  default String getName() {
027    // delegate to the definition
028    return getDefinition().getName();
029  }
030
031  @Override
032  default Integer getIndex() {
033    // delegate to the definition
034    return getDefinition().getIndex();
035  }
036
037  @Override
038  @Nullable
039  default IBoundInstanceFlag getEffectiveJsonKey() {
040    return JsonGroupAsBehavior.KEYED.equals(getJsonGroupAsBehavior())
041        ? getJsonKey()
042        : null;
043  }
044
045  @Override
046  default IBoundInstanceFlag getJsonKey() {
047    return getDefinition().getJsonKey();
048  }
049
050  @Override
051  default IBoundInstanceFlag getItemJsonKey(Object item) {
052    return getEffectiveJsonKey();
053  }
054
055  @Override
056  default Collection<? extends Object> getItemValues(Object value) {
057    return getCollectionInfo().getItemsFromValue(value);
058  }
059
060  @Override
061  default boolean canHandleXmlQName(QName qname) {
062    return qname.equals(getXmlQName());
063  }
064}