templates.trace.Event2Trace.vm Maven / Gradle / Ivy
#* @vtlvariable name="ctx" type="org.kevoree.modeling.kotlin.generator.GenerationContext" *#
#* @vtlvariable name="helper" type="org.kevoree.modeling.kotlin.generator.ProcessorHelperClass" *#
#set($packName = ${helper.fqn($ctx, $ctx.getBasePackageForUtilitiesGeneration())})
package ${packName}.trace
import ${packName}.events.ModelEvent
import ${packName}.trace.ModelTrace
import ${packName}.trace.ModelRemoveTrace
import ${packName}.trace.ModelRemoveAllTrace
import ${packName}.trace.ModelAddTrace
import ${packName}.trace.ModelSetTrace
import ${packName}.trace.ModelAddAllTrace
import java.util.ArrayList
import ${packName}.util.ActionType
import ${packName}.compare.ModelCompare
import ${packName}.util.ElementAttributeType
/**
* Created by duke on 25/07/13.
*/
public class Event2Trace {
val compare = ModelCompare()
public fun convert(event: ModelEvent): TraceSequence {
val result = ArrayList()
when(event.getType()){
ActionType.REMOVE -> {
result.add(ModelRemoveTrace(event.getSourcePath()!!, event.getElementAttributeName()!!, (event.getValue() as ${ctx.getKevoreeContainer().get()}).path()!!));
}
ActionType.REMOVE -> {
result.add(ModelRemoveAllTrace(event.getSourcePath()!!, event.getElementAttributeName()!!));
}
ActionType.ADD -> {
val casted = event.getValue() as ${ctx.getKevoreeContainer().get()}
val traces = compare.inter(casted, casted)
result.add(ModelAddTrace(event.getSourcePath()!!, event.getElementAttributeName()!!, casted.path(), casted.metaClassName()));
result.addAll(traces.getTraces())
}
ActionType.ADD_ALL -> {
val casted = event.getValue() as ${ctx.getKevoreeContainer().get()}
val paths = ArrayList()
val types = ArrayList()
for(elem in casted as Iterable){
val elemCasted = elem as ${ctx.getKevoreeContainer().get()}
val traces = compare.inter(elemCasted, elemCasted)
result.add(ModelAddTrace(event.getSourcePath()!!, event.getElementAttributeName()!!, elemCasted.path(), elemCasted.metaClassName()));
result.addAll(traces.getTraces())
//paths.add(elemCasted.path()!!)
//types.add(elemCasted.metaClassName())
}
//result.add(ModelAddAllTrace(event.getSourcePath()!!, event.getElementAttributeName()!!, paths, types));
//throw Exception("Not Implemented Yet !!! must respect order")
/*
for(elem in casted as Iterable){
val elemCasted = elem as ${ctx.getKevoreeContainer().get()}
paths.add(elemCasted.path()!!)
types.add(elemCasted.metaClassName())
} */
}
ActionType.SET -> {
if(event.getElementAttributeType() == ElementAttributeType.ATTRIBUTE){
result.add(ModelSetTrace(event.getSourcePath()!!, event.getElementAttributeName()!!, null, event.getValue().toString(), null));
} else {
result.add(ModelSetTrace(event.getSourcePath()!!, event.getElementAttributeName()!!, (event.getValue() as ${ctx.getKevoreeContainer().get()}).path(), null,null));
}
}
ActionType.RENEW_INDEX -> {
}
else -> {
throw Exception("Can't convert event : "+event);
}
}
return TraceSequence().populate(result);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy