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.INamedModelInstanceAbsolute;
9   import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
10  
11  import java.util.Collection;
12  
13  import javax.xml.namespace.QName;
14  
15  import edu.umd.cs.findbugs.annotations.NonNull;
16  import edu.umd.cs.findbugs.annotations.Nullable;
17  
18  public interface IBoundInstanceModelNamed<ITEM>
19      extends IBoundInstanceModel<ITEM>, INamedModelInstanceAbsolute {
20  
21    @Override
22    @NonNull
23    IBoundDefinitionModel<ITEM> getDefinition();
24  
25    @Override
26    default String getName() {
27      // delegate to the definition
28      return getDefinition().getName();
29    }
30  
31    @Override
32    default Integer getIndex() {
33      // delegate to the definition
34      return getDefinition().getIndex();
35    }
36  
37    @Override
38    @Nullable
39    default IBoundInstanceFlag getEffectiveJsonKey() {
40      return JsonGroupAsBehavior.KEYED.equals(getJsonGroupAsBehavior())
41          ? getJsonKey()
42          : null;
43    }
44  
45    @Override
46    default IBoundInstanceFlag getJsonKey() {
47      return getDefinition().getJsonKey();
48    }
49  
50    @Override
51    default IBoundInstanceFlag getItemJsonKey(Object item) {
52      return getEffectiveJsonKey();
53    }
54  
55    @Override
56    default Collection<? extends Object> getItemValues(Object value) {
57      return getCollectionInfo().getItemsFromValue(value);
58    }
59  
60    @Override
61    default boolean canHandleXmlQName(QName qname) {
62      return qname.equals(getXmlQName());
63    }
64  }