org.hisrc.jsonix.compilation.jsonschema.JsonSchemaModulesGenerator Maven / Gradle / Ivy
package org.hisrc.jsonix.compilation.jsonschema;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObject;
import javax.json.spi.JsonProvider;
import org.apache.commons.lang3.Validate;
import org.hisrc.jsonix.definition.JsonSchema;
import org.hisrc.jsonix.definition.Module;
import org.hisrc.jsonix.definition.Modules;
import org.hisrc.jsonix.jsonschema.JsonSchemaBuilder;
public class JsonSchemaModulesGenerator {
private final Modules modules;
public JsonSchemaModulesGenerator(Modules modules) {
Validate.notNull(modules);
this.modules = modules;
}
public Modules getModules() {
return modules;
}
public void generate(JsonStructureWriter writer) {
final JsonProvider provider = JsonProvider.provider();
final JsonBuilderFactory builderFactory = provider
.createBuilderFactory(null);
for (final Module module : this.modules.getModules()) {
if (!module.isEmpty()) {
for (JsonSchema jsonSchema : module.getJsonSchemas()) {
final JsonSchemaModuleCompiler moduleCompiler = new JsonSchemaModuleCompiler(
this, module, jsonSchema);
final JsonSchemaBuilder moduleSchema = moduleCompiler
.compile();
final JsonObject moduleSchemaJsonObject = moduleSchema
.build(builderFactory);
writer.writeJsonStructure(module, moduleSchemaJsonObject,
jsonSchema.getFileName());
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy