private void restoreDynamicState(final DynamicState dynamicState) {

    this.uuid = dynamicState.uuid();
    this.sequence = dynamicState.sequence();

    indentedLogger()
        .logDebug(
            "initialization",
            "restoring dynamic state for UUID",
            "UUID",
            this.uuid,
            "sequence",
            Long.toString(this.sequence));

    // Restore request information
    restoreRequestInformation(dynamicState);
    restorePathMatchers(dynamicState);
    restoreTemplate(dynamicState);

    // Restore other encoded objects
    this.pendingUploads =
        new HashSet<String>(
            dynamicState.decodePendingUploadsJava()); // make copy as must be mutable
    this.lastAjaxResponse = dynamicState.decodeLastAjaxResponseJava();

    // Scope the containing document for the XForms API
    XFormsAPI.withContainingDocumentJava(
        this,
        new Runnable() {
          public void run() {
            Controls.withDynamicStateToRestoreJava(
                dynamicState.decodeInstancesControls(),
                new Runnable() {
                  public void run() {
                    // Restore models state
                    // Create XForms controls and models
                    createControlsAndModels();

                    // Restore top-level models state, including instances
                    restoreModelsState();

                    // Restore controls state
                    // Store serialized control state for retrieval later
                    xformsControls.createControlTree();

                    // Once the control tree is rebuilt, restore focus if needed
                    if (dynamicState.decodeFocusedControlJava() != null)
                      xformsControls.setFocusedControl(
                          xformsControls
                              .getCurrentControlTree()
                              .getControl(dynamicState.decodeFocusedControlJava()));
                  }
                });
          }
        });
  }
 public void toSAX(XMLReceiverHelper ch, long currentTime) {
   ch.startElement(
       "xxf",
       XFormsConstants.XXFORMS_NAMESPACE_URI,
       "server-events",
       new String[] {
         "delay",
         Long.toString(getTime() - currentTime),
         "discardable",
         isMaxDelay() ? "true" : null,
         "show-progress",
         Boolean.toString(isShowProgress()),
         "progress-message",
         isShowProgress() ? getProgressMessage() : null
       });
   ch.text(getEncodedDocument());
   ch.endElement();
 }