/**
   * Generates the xml representation and mount in rootNode the structure to be included. Fills the
   * XMLNode structure with the form representation and returns the string.
   */
  public String generateFormXML(Form form, XMLNode rootNode) throws Exception {
    rootNode.addAttribute(ATTR_ID, form.getId().toString());

    addXMLNode("subject", form.getSubject(), rootNode);
    addXMLNode("name", form.getName(), rootNode);
    addXMLNode("displayMode", form.getDisplayMode(), rootNode);
    addXMLNode("labelMode", form.getLabelMode(), rootNode);
    addXMLNode("showMode", form.getShowMode(), rootNode);
    addXMLNode(
        "status", (form.getStatus() != null ? String.valueOf(form.getStatus()) : null), rootNode);
    addXMLNode("formTemplate", form.getFormTemplate(), rootNode);

    for (Field field : form.getFormFields()) {
      generateFieldXML(field, rootNode);
    }

    for (DataHolder dataHolder : form.getHolders()) {
      generateDataHolderXML(dataHolder, rootNode);
    }

    StringWriter sw = new StringWriter();
    rootNode.writeXML(sw, true);

    return sw.toString();
  }
 protected void evaluateFormulaForField(
     Form form,
     String namespace,
     Field field,
     Object loadedObject,
     FormStatusData statusData,
     FormChangeResponse response,
     Date date) {
   evaluatedFields.add(field.getFieldName());
   String defaultFormula = field.getDefaultValueFormula();
   if (defaultFormula != null && defaultFormula.startsWith("=")) {
     Object value =
         evaluateFormula(
             form,
             namespace,
             defaultFormula.substring(1),
             loadedObject,
             statusData,
             response,
             field,
             date);
     FormStatusData status1 = formProcessor.read(form, namespace);
     Object currentFieldValue = status1.getCurrentValue(field.getFieldName());
     if ((currentFieldValue != null && value == null)
         || (value != null && !value.equals(currentFieldValue))) {
       FieldHandler fieldHandler = fieldHandlersManager.getHandler(field.getFieldType());
       Map fieldValuesMap =
           fieldHandler.getParamValue(
               namespace
                   + FormProcessor.NAMESPACE_SEPARATOR
                   + form.getId()
                   + FormProcessor.NAMESPACE_SEPARATOR
                   + field.getFieldName(),
               value,
               field.getFieldPattern());
       formProcessor.setValues(form, namespace, fieldValuesMap, fieldValuesMap, true);
     }
   }
 }