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