1
2
3
4
5
6 package gov.nist.secauto.metaschema.databind.model.impl;
7
8 import gov.nist.secauto.metaschema.core.model.IModule;
9 import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
10 import gov.nist.secauto.metaschema.core.model.XmlGroupAsBehavior;
11 import gov.nist.secauto.metaschema.databind.model.IGroupAs;
12 import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
13 import gov.nist.secauto.metaschema.databind.model.annotations.ModelUtil;
14
15 import javax.xml.namespace.QName;
16
17 import edu.umd.cs.findbugs.annotations.NonNull;
18 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19
20 public class DefaultGroupAs implements IGroupAs {
21 @NonNull
22 private final QName qname;
23 @NonNull
24 private final GroupAs annotation;
25
26 @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields")
27 public DefaultGroupAs(
28 @NonNull GroupAs annotation,
29 @NonNull IModule module) {
30 this.annotation = annotation;
31 String value = ModelUtil.resolveNoneOrDefault(annotation.name(), null);
32 if (value == null) {
33 throw new IllegalStateException(
34 String.format("The %s#groupName value '%s' resulted in an invalid null value",
35 GroupAs.class.getName(),
36 annotation.name()));
37 }
38 this.qname = module.toModelQName(value);
39 }
40
41 @Override
42 public QName getGroupAsQName() {
43 return qname;
44 }
45
46 @Override
47 public JsonGroupAsBehavior getJsonGroupAsBehavior() {
48 return annotation.inJson();
49 }
50
51 @Override
52 public XmlGroupAsBehavior getXmlGroupAsBehavior() {
53 return annotation.inXml();
54 }
55 }