All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hisrc.jsonix.execution.JsonixInvoker Maven / Gradle / Ivy

There is a newer version: 2.3.9
Show newest version
package org.hisrc.jsonix.execution;

import org.hisrc.jsonix.compilation.jsonschema.JsonSchemaModulesGenerator;
import org.hisrc.jsonix.compilation.jsonschema.JsonStructureWriter;
import org.hisrc.jsonix.compilation.mapping.ModulesCompiler;
import org.hisrc.jsonix.compilation.mapping.ProgramWriter;
import org.hisrc.jsonix.configuration.JsonSchemaConfiguration;
import org.hisrc.jsonix.configuration.ModulesConfiguration;
import org.hisrc.jsonix.configuration.ModulesConfigurationUnmarshaller;
import org.hisrc.jsonix.configuration.OutputConfiguration;
import org.hisrc.jsonix.context.DefaultJsonixContext;
import org.hisrc.jsonix.definition.Modules;
import org.hisrc.jsonix.settings.Settings;
import org.jvnet.jaxb2_commons.xjc.model.concrete.XJCCMInfoFactory;
import org.jvnet.jaxb2_commons.xml.bind.model.MModelInfo;
import org.slf4j.Logger;

import com.sun.tools.xjc.model.Model;
import com.sun.tools.xjc.model.nav.NClass;
import com.sun.tools.xjc.model.nav.NType;

public class JsonixInvoker {

	public void execute(Settings settings, Model model,
			ProgramWriter programWriter,
			JsonStructureWriter jsonStructureWriter) {

		final DefaultJsonixContext context = new DefaultJsonixContext();

		context.setLogLevel(settings.getLogLevel().asInt());

		final Logger logger = context.getLoggerFactory().getLogger(
				JsonixInvoker.class.getName());

		if (model == null) {
			logger.error("The model is null, there was probably a problem parsing schemas.");
			return;
		}

		final ModulesConfigurationUnmarshaller customizationHandler = new ModulesConfigurationUnmarshaller(
				context);

		final OutputConfiguration defaultOutputConfiguration = new OutputConfiguration(
				settings.getDefaultNaming().getName(),
				OutputConfiguration.STANDARD_FILE_NAME_PATTERN);

		final JsonSchemaConfiguration defaultJsonSchemaConfiguration = settings
				.isGenerateJsonSchema() ? new JsonSchemaConfiguration(
				JsonSchemaConfiguration.STANDARD_FILE_NAME_PATTERN) : null;

		final ModulesConfiguration modulesConfiguration = customizationHandler
				.unmarshal(model, defaultOutputConfiguration,
						defaultJsonSchemaConfiguration);

		final MModelInfo modelinfo = new XJCCMInfoFactory(model)
				.createModel();

		final Modules modules = modulesConfiguration.build(
				context, modelinfo);

		final ModulesCompiler modulesCompiler = new ModulesCompiler(
				modules);

		modulesCompiler.compile(programWriter);

		final JsonSchemaModulesGenerator jsonSchemaModulesGenerator = new JsonSchemaModulesGenerator(
				modules);
		jsonSchemaModulesGenerator.generate(jsonStructureWriter);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy