String[] variable = variableRecords[i];
String[] nextVariable = null;
if (i + 1 < variableRecords.length) {
nextVariable = variableRecords[i + 1];
}
final VariableOwner owner = getVariableOwner(variable[VAR_PID]);
if (owner != null && owner.isEnabled()) {
// TODO this should be Map<String, Object>, but the
// VariableOwner API does not guarantee the key is a
// string
Map<String, Object> m;
if (nextVariable != null
&& variable[VAR_PID]
.equals(nextVariable[VAR_PID])) {
// we have more than one value changes in row for
// one variable owner, collect em in HashMap
m = new HashMap<String, Object>();
m.put(variable[VAR_NAME],
convertVariableValue(
variable[VAR_TYPE].charAt(0),
variable[VAR_VALUE]));
} else {
// use optimized single value map
m = Collections.singletonMap(
variable[VAR_NAME],
convertVariableValue(
variable[VAR_TYPE].charAt(0),
variable[VAR_VALUE]));
}
// collect following variable changes for this owner
while (nextVariable != null
&& variable[VAR_PID]
.equals(nextVariable[VAR_PID])) {
i++;
variable = nextVariable;
if (i + 1 < variableRecords.length) {
nextVariable = variableRecords[i + 1];
} else {
nextVariable = null;
}
m.put(variable[VAR_NAME],
convertVariableValue(
variable[VAR_TYPE].charAt(0),
variable[VAR_VALUE]));
}
try {
owner.changeVariables(request, m);
// Special-case of closing browser-level windows:
// track browser-windows currently open in client
if (owner instanceof Window
&& ((Window) owner).getParent() == null) {
final Boolean close = (Boolean) m.get("close");
if (close != null && close.booleanValue()) {
closingWindowName = ((Window) owner)
.getName();
}
}
} catch (Exception e) {
if (owner instanceof Component) {
handleChangeVariablesError(application2,
(Component) owner, e, m);
} else {
// TODO DragDropService error handling
throw new RuntimeException(e);
}
}
} else {
// Handle special case where window-close is called
// after the window has been removed from the
// application or the application has closed
if ("close".equals(variable[VAR_NAME])
&& "true".equals(variable[VAR_VALUE])) {
// Silently ignore this
continue;
}
// Ignore variable change
String msg = "Warning: Ignoring variable change for ";
if (owner != null) {
msg += "disabled component " + owner.getClass();
String caption = ((Component) owner).getCaption();
if (caption != null) {
msg += ", caption=" + caption;
}
} else {