public RestVariable createRestVariable(String name, Object value, RestVariableScope scope,
String id, int variableType, boolean includeBinaryValue, String serverRootUrl) {
RestVariableConverter converter = null;
RestVariable restVar = new RestVariable();
restVar.setVariableScope(scope);
restVar.setName(name);
if (value != null) {
// Try converting the value
for (RestVariableConverter c : variableConverters) {
if (c.getVariableType().isAssignableFrom(value.getClass())) {
converter = c;
break;
}
}
if (converter != null) {
converter.convertVariableValue(value, restVar);
restVar.setType(converter.getRestTypeName());
} else {
// Revert to default conversion, which is the serializable/byte-array form
if (value instanceof Byte[] || value instanceof byte[]) {
restVar.setType(BYTE_ARRAY_VARIABLE_TYPE);
} else {
restVar.setType(SERIALIZABLE_VARIABLE_TYPE);
}
if (includeBinaryValue) {
restVar.setValue(value);
}
if (variableType == VARIABLE_TASK) {
restVar.setValueUrl(formatUrl(serverRootUrl, RestUrls.URL_TASK_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_EXECUTION) {
restVar.setValueUrl(formatUrl(serverRootUrl, RestUrls.URL_EXECUTION_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_PROCESS) {
restVar.setValueUrl(formatUrl(serverRootUrl, RestUrls.URL_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_HISTORY_TASK) {
restVar.setValueUrl(formatUrl(serverRootUrl, RestUrls.URL_HISTORIC_TASK_INSTANCE_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_HISTORY_PROCESS) {
restVar.setValueUrl(formatUrl(serverRootUrl, RestUrls.URL_HISTORIC_PROCESS_INSTANCE_VARIABLE_DATA, id, name));
} else if (variableType == VARIABLE_HISTORY_VARINSTANCE) {
restVar.setValueUrl(formatUrl(serverRootUrl, RestUrls.URL_HISTORIC_VARIABLE_INSTANCE_DATA, id));
} else if (variableType == VARIABLE_HISTORY_DETAIL) {
restVar.setValueUrl(formatUrl(serverRootUrl, RestUrls.URL_HISTORIC_DETAIL_VARIABLE_DATA, id));
}
}
}
return restVar;
}