1
2
3
4
5
6 package gov.nist.secauto.metaschema.databind.codegen;
7
8 import gov.nist.secauto.metaschema.core.model.IModule;
9 import gov.nist.secauto.metaschema.databind.codegen.config.IBindingConfiguration;
10 import gov.nist.secauto.metaschema.databind.codegen.typeinfo.IMetaschemaClassFactory;
11 import gov.nist.secauto.metaschema.databind.codegen.typeinfo.ITypeResolver;
12
13 import java.io.IOException;
14 import java.nio.file.Path;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.stream.Stream;
19
20 import edu.umd.cs.findbugs.annotations.NonNull;
21 import edu.umd.cs.findbugs.annotations.Nullable;
22
23
24
25
26 public interface IProduction {
27
28
29
30
31
32
33
34 @NonNull
35 Collection<IGeneratedModuleClass> getModuleProductions();
36
37
38
39
40
41
42
43
44
45
46 @Nullable
47 IGeneratedModuleClass getModuleProduction(@NonNull IModule module);
48
49
50
51
52
53
54
55
56
57
58 @NonNull
59 Collection<IGeneratedDefinitionClass> getGlobalDefinitionClasses();
60
61
62
63
64
65
66
67 @NonNull
68 Stream<? extends IGeneratedClass> getGeneratedClasses();
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84 @NonNull
85 static IProduction of(
86 @NonNull Collection<? extends IModule> modules,
87 @NonNull IBindingConfiguration bindingConfiguration,
88 @NonNull Path classDir) throws IOException {
89
90 ITypeResolver typeResolver = ITypeResolver.newTypeResolver(bindingConfiguration);
91
92 IMetaschemaClassFactory classFactory = IMetaschemaClassFactory.newInstance(typeResolver);
93
94 ProductionImpl retval = new ProductionImpl();
95 for (IModule module : modules) {
96 assert module != null;
97 retval.addModule(module, classFactory, classDir);
98 }
99
100 Map<String, PackageMetadata> packageNameToPackageMetadataMap = new HashMap<>();
101 for (IGeneratedModuleClass moduleProduction : retval.getModuleProductions()) {
102 String packageName = moduleProduction.getPackageName();
103
104 PackageMetadata metadata = packageNameToPackageMetadataMap.get(packageName);
105 if (metadata == null) {
106 metadata = new PackageMetadata(moduleProduction);
107 packageNameToPackageMetadataMap.put(metadata.getPackageName(), metadata);
108 } else {
109 metadata.addModule(moduleProduction);
110 }
111 }
112
113 for (PackageMetadata metadata : packageNameToPackageMetadataMap.values()) {
114 assert metadata != null;
115 retval.addPackage(
116 metadata,
117 classFactory,
118 classDir);
119 }
120 return retval;
121 }
122 }