Engine-cdi: type-safe injects of process variables

Hi,

In ProcessVariables.java the producer for process variables returns Object, leaving the cast to the client.

@ Produces
@ ProcessVariable
protected Object getProcessVariable(InjectionPoint ip) {
String processVariableName = getVariableName(ip);

return businessProcess.getVariable(processVariableName);
}

I wonder, why this could not be extended to type-safe injects by replicating the producer to all possible return values

@ Produces
@ ProcessVariable
protected Boolean getProcessVariable(InjectionPoint ip) {
String processVariableName = getVariableName(ip);

return businessProcess.getVariable(processVariableName);
}

@ Produces
@ ProcessVariable
protected String getProcessVariable(InjectionPoint ip) {
String processVariableName = getVariableName(ip);

return businessProcess.getVariable(processVariableName);
}

etc. The underlying businessProcess.getVariable() supports this. Playing around with this approach in Wildfly 10 (Weld 2.3.5) it works, I can inject all my process variables with the expected type.

@ Inject
@ ProcessVariable
Boolean approved;

I’m not an expert in CDI, so this may a dependency on the CDI spec and implementation version; but if not, I would like to see these producers added to camunda-engine-cdi

Cheers
Johannes

Reply to myself, as I found out. The approach works only iff all occurences to Object are converted to a subtype, otherwise it is an ambiguous dependency - because all producers satisfy the injection point.

@ Inject
@ ProcessVariable
Object approved;

Means, that this should have been introduced at the very first in camunda-engine-cdi, and now it would break the existing code base.

Hi @kifj,

that’s an interesting point. What do you think about creating specialized annotations for process variables (e.g. @BooleanProcessVariable)?

Best regards,
Philipp

1 Like

Yes, special qualifiers for each return type would work.

If you think the specialized annotations would help you then feel free to work on a pull request. We’re always happy to integrate good ideas from the community!

1 Like