org.joinedworkz.common.java.DtoCartridge.xtend Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-java Show documentation
Show all versions of common-java Show documentation
DSL based modeling framework - facilities common java
package org.joinedworkz.common.java
import java.util.Properties
import javax.inject.Inject
import javax.inject.Singleton
import org.joinedworkz.common.helper.CmnModelHelper
import org.joinedworkz.common.java.generator.DtoClassGenerator
import org.joinedworkz.common.java.generator.EnumerationClassGenerator
import org.joinedworkz.core.facility.AbstractCartridge
import org.joinedworkz.core.facility.Outlet
import org.joinedworkz.core.facility.Outlets
import org.joinedworkz.core.model.CmnEnumeration
import org.joinedworkz.core.model.CmnFieldContainer
import org.joinedworkz.core.model.CmnModel
import org.joinedworkz.core.model.CmnObject
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@Singleton
class DtoCartridge extends AbstractCartridge {
final static Logger log = LoggerFactory.getLogger(DtoCartridge);
@Inject
protected extension CmnModelHelper cmnModelHelper
@Inject
protected DtoClassGenerator dtoClassGenerator;
@Inject
protected EnumerationClassGenerator enumerationClassGenerator;
override apply(CmnObject cmnObj, Outlets outlets) {
apply(cmnObj, outlets, null)
}
override void apply(CmnObject obj, Outlets outlets, Properties joinedWorkzProperties) {
val generatedJavaSourceSlot = outlets.get("generatedJavaSource")
if (obj instanceof CmnModel) {
log.info("Invoke generator '{}' on model '{}'", dtoClassGenerator.class.canonicalName, obj.namespace)
for (modelElement : obj.modelElements) {
modelElement.generateModelElement(generatedJavaSourceSlot, joinedWorkzProperties)
}
}
}
def void generateModelElement(CmnObject obj, Outlet outlet, Properties joinedWorkzProperties) {
if (obj.isDtoObject) {
dtoClassGenerator.generateClass(createGeneratorContext(obj as CmnFieldContainer, outlet, joinedWorkzProperties))
} else if (obj instanceof CmnEnumeration) {
enumerationClassGenerator.generateClass(createGeneratorContext(obj, outlet, joinedWorkzProperties))
}
}
def ClassGeneratorContext createGeneratorContext(T classObject, Outlet outlet, Properties joinedWorkzProperties) {
return new ClassGeneratorContext(classObject, outlet, joinedWorkzProperties)
}
}