template.MapperTemplate.vsl Maven / Gradle / Ivy
## Velocity Template.
package ${functionPackage};
#foreach( $import in $imports)
import $import;
#end
/**
* Generated mapper function wrapper for a reference type.
*
* - output class : {@link ${outputClass}}
*
- input class : {@link ${filterSubjectClass}}
*
- map function : {@link ${targetClass}#${targetMethod}}
*
*
* @author Greg Higgins
*/
public class ${functionClass} extends AbstractFilterWrapper<${outputClass}> {
public ${sourceClass} filterSubject;
#if(${multiArgFunc})
private boolean filterSubjectUpdated;
#end
#foreach($sourceInfo in $sourceMappingList)
public ${sourceInfo.type} ${sourceInfo.id};
#if(!${sourceInfo.constant})
private boolean ${sourceInfo.id}Updated;
#end
#end
#if(!${newFunction})
@NoEventReference
public ${targetClass} f;
#end
private ${outputClass} result;
#if(${stateful})
@NoEventReference
public Object resetNotifier;
private boolean parentReset = false;
#end
@OnEvent
public boolean onEvent(){
${outputClass} oldValue = result;
#if(${newFunction})
#if(${multiArgFunc})
result = ${targetClass}.${targetMethod}(${input});
if(allSourcesUpdated()){
result = ${targetClass}.${targetMethod}(${input});
}
#else
result = ${targetClass}.${targetMethod}(${input});
#end
#else
#if(${multiArgFunc})
if(allSourcesUpdated()){
result = f.${targetMethod}(${input});
}
#else
result = f.${targetMethod}(${input});
#end
#foreach($functionInfo in $sourceFunctions)
if(${functionInfo.sourceInfo.id}Updated){
result = f.${targetMethod}(${functionInfo.paramString});
}
#end
#end
return #if(${multiArgFunc})allSourcesUpdated() & #end!notifyOnChangeOnly || (!result.equals(oldValue));
}
#if(!${newFunction} || ${multiArgFunc} )
#if(${multiArgFunc})
private boolean allSourcesUpdated(){
boolean updated = filterSubjectUpdated;
#foreach($sourceInfo in $sourceMappingList)
#if(!${sourceInfo.constant})
updated &= ${sourceInfo.id}Updated #if(${sourceInfo.wrapper}) | ${sourceInfo.id}.isValidOnStart()#end;
#end
#end
return updated;
}
@OnParentUpdate("filterSubject")
public void updated_filterSubject(${sourceClass} updated){
filterSubjectUpdated = true;
}
#end
#foreach($sourceInfo in $sourceMappingList)
#if(!${sourceInfo.constant})
@OnParentUpdate("${sourceInfo.id}")
public void updated_${sourceInfo.id}(${sourceInfo.type} updated){
${sourceInfo.id}Updated = true;
}
#end
#end
#end
#if(${stateful})
@OnParentUpdate("resetNotifier")
public void resetNotification(Object resetNotifier) {
parentReset = true;
if (isResetImmediate()) {
f.reset();
parentReset = false;
}
}
@AfterEvent
public void resetAfterEvent() {
if (parentReset | alwaysReset) {
f.reset();
}
parentReset = false;
}
@Override
public FilterWrapper<${outputClass}> resetNotifier(Object resetNotifier) {
this.resetNotifier = resetNotifier;
return this;
}
#end
@Override
public ${outputClass} event() {
return result;
}
@Override
public Class<${outputClass}> eventClass() {
return ${outputClass}.class;
}
@Initialise
public void init(){
result = null;
#if(${multiArgFunc})
filterSubjectUpdated = ${sourceConstant};
#end
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy