templates.ModelCloner.vm Maven / Gradle / Ivy
#* @vtlvariable name="packageName" type="java.lang.String" *#
#* @vtlvariable name="potentialRoots" type="java.util.ArrayList" *#
#* @vtlvariable name="ctx" type="org.kevoree.modeling.kotlin.generator.GenerationContext" *#
#* @vtlvariable name="packages" type="java.util.Collection" *#
#* @vtlvariable name="helper" type="org.kevoree.modeling.kotlin.generator.ProcessorHelperClass" *#
package ${packageName}.cloner
class DefaultModelCloner() : org.kevoree.modeling.api.ModelCloner {
override fun clone(o : A) : A? {
return clone(o,false)
}
override fun clone(o : A,readOnly : Boolean) : A? {
return clone(o,readOnly,false)
}
override fun cloneMutableOnly(o : A,readOnly : Boolean) : A? {
return clone(o,readOnly,true)
}
private fun clone(o : A,readOnly : Boolean,mutableOnly : Boolean) : A? {
#foreach($potentialRoot in $potentialRoots)
#if(!$potentialRoot.getClass().getName().toLowerCase().contains("eenum"))
#if($ctx.getJS())
if(o is ${helper.fqn($ctx,$potentialRoot)} || o is ${helper.fqn($ctx,$potentialRoot.getEPackage())}.impl.${potentialRoot.getName()}Impl) {
val context = java.util.HashMap()
#else
if(o is ${helper.fqn($ctx,$potentialRoot)}) {
val context = java.util.IdentityHashMap()
#end
(o as ${ctx.getKevoreeContainerImplFQN()}).getClonelazy(context, mainFactory,mutableOnly)
return (o as ${ctx.getKevoreeContainerImplFQN()}).resolve(context,readOnly,mutableOnly) as A
}
#end
#end
return null
}
var mainFactory : ${helper.fqn($ctx, $ctx.getBasePackageForUtilitiesGeneration())}.factory.MainFactory = ${helper.fqn($ctx, $ctx.getBasePackageForUtilitiesGeneration())}.factory.MainFactory()
#foreach($factoryFqn in $packages)
#set($lastIndexOfPoint = $factoryFqn.lastIndexOf(".") + 1)
#set($factoryName = $factoryFqn.substring($lastIndexOfPoint))
fun set$factoryName(fct : $factoryFqn) { mainFactory.set$factoryName(fct)}
##fun get$factoryName() : $factoryFqn { return mainFactory.get$factoryName()}
##override var ${pack.replace(".", "_")} : $pack = ${pack.substring(0, $pack.lastIndexOf("."))}.impl.Default${helper.getLastName($pack)}()
#end
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy