public class MasterJoinFlowProcessor extends RendezvousProcessor {
@Override
public void emitRendezvous(Context context) {
MasterKindFlowAnalyzer masterAnalyzer = new MasterKindFlowAnalyzer(context);
ModelFactory f = context.getModelFactory();
FlowElementPortDescription tx = context.getInputPort(MasterJoin.ID_INPUT_TRANSACTION);
FlowElementPortDescription joinedPort = context.getOutputPort(MasterJoin.ID_OUTPUT_JOINED);
FlowElementPortDescription missedPort = context.getOutputPort(MasterJoin.ID_OUTPUT_MISSED);
DataObjectMirror resultCache = context.createModelCache(joinedPort.getDataType());
DataClass outputType = getEnvironment().getDataClasses().load(joinedPort.getDataType());
List<Statement> process = Lists.create();
process.add(resultCache.createReset());
Joined annotation = TypeUtil.erase(joinedPort.getDataType()).getAnnotation(Joined.class);
Set<String> saw = Sets.create();
for (Joined.Term term : annotation.terms()) {
DataClass inputType = getEnvironment().getDataClasses().load(term.source());
Expression input;
if (term.source().equals(context.getInputPort(MasterJoin.ID_INPUT_MASTER).getDataType())) {
input = masterAnalyzer.getGetRawMasterExpression();
} else {
input = context.getProcessInput(tx);
}
for (Joined.Mapping mapping : term.mappings()) {
if (saw.contains(mapping.destination())) {
continue;
}
saw.add(mapping.destination());
Property sourceProperty = inputType.findProperty(mapping.source());
Property destinationProperty = outputType.findProperty(mapping.destination());
process.add(destinationProperty.createSetter(
resultCache.get(),
sourceProperty.createGetter(input)));
}
}
ResultMirror joined = context.getOutput(joinedPort);
process.add(joined.createAdd(resultCache.get()));
ResultMirror missed = context.getOutput(missedPort);
context.addProcess(tx, f.newIfStatement(
masterAnalyzer.getHasMasterExpresion(),
f.newBlock(process),
f.newBlock(missed.createAdd(context.getProcessInput(tx)))));
}