Search in sources :

Example 1 with ProcessVariable

use of org.camunda.bpm.engine.cdi.annotation.ProcessVariable in project camunda-bpm-platform by camunda.

the class StartProcessInterceptor method extractVariables.

private Map<String, Object> extractVariables(StartProcess startProcessAnnotation, InvocationContext ctx) throws Exception {
    VariableMap variables = new VariableMapImpl();
    for (Field field : ctx.getMethod().getDeclaringClass().getDeclaredFields()) {
        if (!field.isAnnotationPresent(ProcessVariable.class) && !field.isAnnotationPresent(ProcessVariableTyped.class)) {
            continue;
        }
        field.setAccessible(true);
        String fieldName = null;
        ProcessVariable processStartVariable = field.getAnnotation(ProcessVariable.class);
        if (processStartVariable != null) {
            fieldName = processStartVariable.value();
        } else {
            ProcessVariableTyped processStartVariableTyped = field.getAnnotation(ProcessVariableTyped.class);
            fieldName = processStartVariableTyped.value();
        }
        if (fieldName == null || fieldName.length() == 0) {
            fieldName = field.getName();
        }
        Object value = field.get(ctx.getTarget());
        variables.put(fieldName, value);
    }
    return variables;
}
Also used : Field(java.lang.reflect.Field) VariableMapImpl(org.camunda.bpm.engine.variable.impl.VariableMapImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) ProcessVariable(org.camunda.bpm.engine.cdi.annotation.ProcessVariable) ProcessVariableTyped(org.camunda.bpm.engine.cdi.annotation.ProcessVariableTyped)

Aggregations

Field (java.lang.reflect.Field)1 ProcessVariable (org.camunda.bpm.engine.cdi.annotation.ProcessVariable)1 ProcessVariableTyped (org.camunda.bpm.engine.cdi.annotation.ProcessVariableTyped)1 VariableMap (org.camunda.bpm.engine.variable.VariableMap)1 VariableMapImpl (org.camunda.bpm.engine.variable.impl.VariableMapImpl)1