1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.databind;
7   
8   import gov.nist.secauto.metaschema.core.model.IBoundObject;
9   import gov.nist.secauto.metaschema.databind.IBindingContext.IBindingMatcher;
10  import gov.nist.secauto.metaschema.databind.model.IBoundDefinitionModelAssembly;
11  
12  import javax.xml.namespace.QName;
13  
14  import edu.umd.cs.findbugs.annotations.NonNull;
15  
16  class RootAssemblyBindingMatcher implements IBindingMatcher {
17    @NonNull
18    private final IBoundDefinitionModelAssembly definition;
19  
20    public RootAssemblyBindingMatcher(
21        @NonNull IBoundDefinitionModelAssembly definition) {
22      this.definition = definition;
23    }
24  
25    protected IBoundDefinitionModelAssembly getDefinition() {
26      return definition;
27    }
28  
29    protected Class<? extends IBoundObject> getClazz() {
30      return getDefinition().getBoundClass();
31    }
32  
33    @SuppressWarnings("null")
34    @NonNull
35    protected QName getRootQName() {
36      return getDefinition().getRootXmlQName();
37    }
38  
39    @SuppressWarnings("null")
40    @NonNull
41    protected String getRootJsonName() {
42      return getDefinition().getRootJsonName();
43    }
44  
45    @Override
46    public Class<? extends IBoundObject> getBoundClassForXmlQName(QName rootQName) {
47      return getRootQName().equals(rootQName) ? getClazz() : null;
48    }
49  
50    @Override
51    public Class<? extends IBoundObject> getBoundClassForJsonName(String rootName) {
52      return getRootJsonName().equals(rootName) ? getClazz() : null;
53    }
54  }