public void write(UI ui, Writer writer) throws IOException {
Collection<ClientMethodInvocation> pendingInvocations = collectPendingRpcCalls(ui
.getConnectorTracker().getDirtyVisibleConnectors());
JsonArray rpcCalls = Json.createArray();
for (ClientMethodInvocation invocation : pendingInvocations) {
// add invocation to rpcCalls
try {
JsonArray invocationJson = Json.createArray();
invocationJson.set(0, invocation.getConnector().getConnectorId());
invocationJson.set(1, invocation.getInterfaceName());
invocationJson.set(2, invocation.getMethodName());
JsonArray paramJson = Json.createArray();
for (int i = 0; i < invocation.getParameterTypes().length; ++i) {
Type parameterType = invocation.getParameterTypes()[i];
JsonValue referenceParameter = null;
// TODO Use default values for RPC parameter types
// if (!JsonCodec.isInternalType(parameterType)) {
// try {
// referenceParameter = parameterType.newInstance();
// } catch (Exception e) {
// logger.log(Level.WARNING,
// "Error creating reference object for parameter of type "
// + parameterType.getName());
// }
// }
EncodeResult encodeResult = JsonCodec.encode(
invocation.getParameters()[i], referenceParameter,
parameterType, ui.getConnectorTracker());
paramJson.set(i, encodeResult.getEncodedValue());
}
invocationJson.set(3, paramJson);
rpcCalls.set(rpcCalls.length(), invocationJson);
} catch (JsonException e) {
throw new PaintException(