1
2
3
4
5
6 package gov.nist.secauto.metaschema.databind.codegen;
7
8 import java.net.URI;
9 import java.util.LinkedList;
10 import java.util.List;
11
12 import edu.umd.cs.findbugs.annotations.NonNull;
13
14 class PackageMetadata {
15 @NonNull
16 private final String packageName;
17 @NonNull
18 private final URI xmlNamespace;
19 @NonNull
20 private final List<IGeneratedModuleClass> moduleProductions = new LinkedList<>();
21
22 public PackageMetadata(@NonNull IGeneratedModuleClass moduleProduction) {
23 packageName = moduleProduction.getPackageName();
24 xmlNamespace = moduleProduction.getModule().getXmlNamespace();
25 moduleProductions.add(moduleProduction);
26 }
27
28 @NonNull
29 protected String getPackageName() {
30 return packageName;
31 }
32
33 @NonNull
34 protected URI getXmlNamespace() {
35 return xmlNamespace;
36 }
37
38 @NonNull
39 protected List<IGeneratedModuleClass> getModuleProductions() {
40 return moduleProductions;
41 }
42
43 public void addModule(@NonNull IGeneratedModuleClass moduleProduction) {
44 URI nextXmlNamespace = moduleProduction.getModule().getXmlNamespace();
45 if (!xmlNamespace.equals(nextXmlNamespace)) {
46 throw new IllegalStateException(String.format(
47 "The package %s is associated with the XML namespaces '%s' and '%s'."
48 + " A package must be associated with a single XML namespace.",
49 getPackageName(), getXmlNamespace().toASCIIString(), nextXmlNamespace.toASCIIString()));
50 }
51 moduleProductions.add(moduleProduction);
52 }
53 }