1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.databind.codegen;
7   
8   import java.io.IOException;
9   import java.net.URI;
10  import java.nio.file.Path;
11  
12  import dev.metaschema.databind.codegen.typeinfo.IMetaschemaClassFactory;
13  import edu.umd.cs.findbugs.annotations.NonNull;
14  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15  
16  /**
17   * Default implementation of {@link IPackageProduction} representing a generated
18   * package-info.java class.
19   */
20  class PackageProductionImpl implements IPackageProduction {
21    @NonNull
22    private final URI xmlNamespace;
23    @NonNull
24    private final IGeneratedClass packageInfoClass;
25  
26    /**
27     * Construct a new package production.
28     *
29     * @param metadata
30     *          the package metadata
31     * @param classFactory
32     *          the class factory to use for generating the package-info class
33     * @param targetDirectory
34     *          the directory to generate the class in
35     * @throws IOException
36     *           if an error occurs during class generation
37     */
38    @SuppressFBWarnings(value = "CT_CONSTRUCTOR_THROW", justification = "Use of final fields")
39    public PackageProductionImpl(
40        @NonNull PackageMetadata metadata,
41        @NonNull IMetaschemaClassFactory classFactory,
42        @NonNull Path targetDirectory)
43        throws IOException {
44      this.xmlNamespace = metadata.getXmlNamespace();
45      this.packageInfoClass = classFactory.generatePackageInfoClass(
46          metadata.getPackageName(),
47          this.xmlNamespace,
48          metadata.getModuleProductions(),
49          targetDirectory);
50    }
51  
52    @Override
53    public URI getXmlNamespace() {
54      return xmlNamespace;
55    }
56  
57    /**
58     * Get the generated package-info class associated with this package.
59     *
60     * @return the package-info class
61     */
62    @Override
63    public IGeneratedClass getGeneratedClass() {
64      return packageInfoClass;
65    }
66  }