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

com.reprezen.genflow.rapidml.xsd.DataModelSchemaGenerator.xtend Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright © 2013, 2016 Modelsolv, Inc.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is, and remains the property
 * of ModelSolv, Inc. See the file license.html in the root directory of
 * this project for further information.
 *******************************************************************************/
package com.reprezen.genflow.rapidml.xsd

import com.reprezen.genflow.api.template.IGenTemplateContext
import com.reprezen.genflow.api.zenmodel.ZenModelExtractOutputItem
import com.reprezen.rapidml.DataModel
import com.reprezen.rapidml.EnumConstant
import com.reprezen.rapidml.Enumeration
import com.reprezen.rapidml.SingleValueType
import com.reprezen.rapidml.UserDefinedType
import com.reprezen.rapidml.ZenModel
import java.io.File

class DataModelSchemaGenerator extends ZenModelExtractOutputItem {
	extension XMLSchemaHelper xmlSchemaHelper

	override init(IGenTemplateContext context) {
		val model = context.primarySource.load as ZenModel
		val helpers = new Helpers(context, model)
		this.xmlSchemaHelper = helpers.xmlSchemaHelper
	}

	override File getOutputFile(ZenModel zenModel, DataModel dataModel) {
		return new File(dataModel.xsdFileName(zenModel))
	}

	override String generate(ZenModel zenModel, DataModel dataModel) {
		return '''
			
			«dataModel.generateXSDDoc»
			«FOR dataType : dataModel.ownedDataTypes SEPARATOR ""»
				«IF (dataType instanceof Enumeration) || (dataType instanceof UserDefinedType)»
					«generate(dataType as SingleValueType)»
				«ENDIF»
			«ENDFOR»
			
		'''
	}

	def private generateNamespaceAdditions(DataModel dataModel) {
		'''
			xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
			jaxb:version="2.0"
		'''
	}

	def private dispatch generate(Enumeration en) {
		'''
			
			«en.generateEnumAnnotation»
				
					«FOR enumConstant : en.enumConstants SEPARATOR ""»
						«enumConstant.generateEnumConstant»
					«ENDFOR»
				
			
		'''
	}

	def private dispatch generate(UserDefinedType userDefinedType) {
		'''
			
				«generateRestriction(userDefinedType.baseTypeName, userDefinedType.allConstraints)»
			
		'''
	}

	def private generateEnumAnnotation(Enumeration en) {
		'''
			
				
					
				
			
		'''
	}

	def private generateEnumConstant(EnumConstant enumConstant) {
		'''
			
				«enumConstant.generateEnumConstantAnnotation»
			
		'''
	}

	def private generateEnumConstantAnnotation(EnumConstant enumConstant) {
		'''
			
				
					
				
			
		'''
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy