private static mxGraphModel getMxGraphModel(String gxml) {
   mxCodec codec = new mxCodec();
   org.w3c.dom.Document doc = mxXmlUtils.parseXml(gxml);
   codec = new mxCodec(doc);
   mxGraphModel model = (mxGraphModel) codec.decode(doc.getDocumentElement());
   return model;
 }
  /** Saves XML+PNG format. */
  protected void saveXmlPng(TrackSchemeFrame frame, String filename, Color bg) throws IOException {
    final mxGraphComponent graphComponent = trackScheme.getGUI().graphComponent;
    final mxGraph graph = trackScheme.getGraph();

    // Creates the image for the PNG file
    BufferedImage image =
        mxCellRenderer.createBufferedImage(
            graph, null, 1, bg, graphComponent.isAntiAlias(), null, graphComponent.getCanvas());

    // Creates the URL-encoded XML data
    mxCodec codec = new mxCodec();
    String xml = URLEncoder.encode(mxXmlUtils.getXml(codec.encode(graph.getModel())), "UTF-8");
    mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image);
    param.setCompressedText(new String[] {"mxGraphModel", xml});

    // Saves as a PNG file
    FileOutputStream outputStream = new FileOutputStream(new File(filename));
    try {
      mxPngImageEncoder encoder = new mxPngImageEncoder(outputStream, param);

      if (image != null) {
        encoder.encode(image);
      } else {
        JOptionPane.showMessageDialog(graphComponent, "No Image Data");
      }
    } finally {
      outputStream.close();
    }
  }
  @Test
  public void testPng() throws Exception {
    String path =
        ProcessDefManagerTest.class.getClassLoader().getResource("graphsub.xml").getPath();
    String value = FileUtils.readFileToString(new File(path));
    mxCodec codec = new mxCodec();
    org.w3c.dom.Document doc = mxXmlUtils.parseXml(value);
    codec = new mxCodec(doc);
    mxGraphModel model = (mxGraphModel) codec.decode(doc.getDocumentElement());
    mxGraph graph = new mxGraph();
    graph.setModel(model);
    BufferedImage image =
        mxCellRenderer.createBufferedImage(graph, null, 1, Color.WHITE, true, null);
    byte[] ret = null;
    ByteArrayOutputStream outputStream = null;
    try {
      outputStream = new ByteArrayOutputStream();
      ImageIO.write(image, "png", outputStream);
      ret = outputStream.toByteArray();
      FileUtils.writeByteArrayToFile(new File("/Users/lihao/Downloads/graph.png"), ret);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemple #4
0
  public void test1() throws Exception {

    // Creates graph with model
    mxGraph graph = new mxGraph();
    Object parent = graph.getDefaultParent();
    Object v1, v2;

    graph.getModel().beginUpdate();
    try {
      v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30);
      v2 = graph.insertVertex(parent, null, "World!", 200, 150, 80, 30);
      graph.insertEdge(parent, null, "e1", v1, v2);
    } finally {
      graph.getModel().endUpdate();
    }

    mxCodec codec = new mxCodec();
    Node node = codec.encode(graph.getModel());
    String xml1 = mxXmlUtils.getXml(node);

    System.out.println("xml=" + mxUtils.getPrettyXml(node));

    Document doc = mxDomUtils.createDocument();
    doc.appendChild(doc.importNode(node, true));
    codec = new mxCodec(doc);
    Object model = codec.decode(node);

    codec = new mxCodec();
    node = codec.encode(model);
    String xml2 = mxXmlUtils.getXml(node);

    assertEquals(xml1, xml2);
  }
Exemple #5
0
  @SuppressWarnings("unchecked")
  public void test2() throws Exception {
    Map<String, Object> map = new Hashtable<String, Object>();
    map.put("a", "b");
    map.put("b", new mxCell("Hello, World!"));

    mxCodec codec = new mxCodec();
    Node node = codec.encode(map);
    String xml1 = mxXmlUtils.getXml(node);

    codec = new mxCodec();
    Map<String, Object> map2 = (Hashtable<String, Object>) codec.decode(node);

    codec = new mxCodec();
    node = codec.encode(map2);
    String xml2 = mxXmlUtils.getXml(node);

    assertEquals(xml1, xml2);
    assertEquals(map.size(), map2.size());
    assertEquals(map.get("a"), map2.get("a"));
  }
  public void actionPerformed(ActionEvent e) {

    final mxGraphComponent graphComponent = trackScheme.getGUI().graphComponent;
    final mxGraph graph = trackScheme.getGraph();
    FileFilter selectedFilter = null;
    DefaultFileFilter xmlPngFilter = new DefaultFileFilter(".png", "PNG+XML file (.png)");
    FileFilter vmlFileFilter = new DefaultFileFilter(".html", "VML file (.html)");
    String filename = null;
    boolean dialogShown = false;

    String wd;

    if (lastDir != null) {
      wd = lastDir;
    } else {
      wd = System.getProperty("user.dir");
    }

    JFileChooser fc = new JFileChooser(wd);

    // Adds the default file format
    FileFilter defaultFilter = xmlPngFilter;
    fc.addChoosableFileFilter(defaultFilter);

    // Adds special vector graphics formats and HTML
    fc.addChoosableFileFilter(new DefaultFileFilter(".pdf", "PDF file (.pdf)"));
    fc.addChoosableFileFilter(new DefaultFileFilter(".svg", "SVG file (.svg)"));
    fc.addChoosableFileFilter(new DefaultFileFilter(".html", "HTML file (.html)"));
    fc.addChoosableFileFilter(vmlFileFilter);
    fc.addChoosableFileFilter(new DefaultFileFilter(".txt", "Graph Drawing file (.txt)"));
    fc.addChoosableFileFilter(new DefaultFileFilter(".mxe", "mxGraph Editor file (.mxe)"));

    // Adds a filter for each supported image format
    Object[] imageFormats = ImageIO.getReaderFormatNames();

    // Finds all distinct extensions
    HashSet<String> formats = new HashSet<String>();

    for (int i = 0; i < imageFormats.length; i++) {
      String ext = imageFormats[i].toString().toLowerCase();
      formats.add(ext);
    }

    imageFormats = formats.toArray();

    for (int i = 0; i < imageFormats.length; i++) {
      String ext = imageFormats[i].toString();
      fc.addChoosableFileFilter(
          new DefaultFileFilter("." + ext, ext.toUpperCase() + " File  (." + ext + ")"));
    }

    // Adds filter that accepts all supported image formats
    fc.addChoosableFileFilter(new DefaultFileFilter.ImageFileFilter("All Images"));
    fc.setFileFilter(defaultFilter);
    int rc = fc.showDialog(null, "Save");
    dialogShown = true;

    if (rc != JFileChooser.APPROVE_OPTION) {
      return;
    } else {
      lastDir = fc.getSelectedFile().getParent();
    }

    filename = fc.getSelectedFile().getAbsolutePath();
    selectedFilter = fc.getFileFilter();

    if (selectedFilter instanceof DefaultFileFilter) {
      String ext = ((DefaultFileFilter) selectedFilter).getExtension();

      if (!filename.toLowerCase().endsWith(ext)) {
        filename += ext;
      }
    }

    if (new File(filename).exists()
        && JOptionPane.showConfirmDialog(graphComponent, "Overwrite existing file?")
            != JOptionPane.YES_OPTION) {
      return;
    }

    try {
      String ext = filename.substring(filename.lastIndexOf('.') + 1);

      if (ext.equalsIgnoreCase("svg")) {
        mxSvgCanvas canvas =
            (mxSvgCanvas)
                mxCellRenderer.drawCells(
                    graph,
                    null,
                    1,
                    null,
                    new CanvasFactory() {
                      public mxICanvas createCanvas(int width, int height) {
                        TrackSchemeSvgCanvas canvas =
                            new TrackSchemeSvgCanvas(mxDomUtils.createSvgDocument(width, height));
                        canvas.setEmbedded(true);
                        return canvas;
                      }
                    });

        mxUtils.writeFile(mxXmlUtils.getXml(canvas.getDocument()), filename);

      } else if (selectedFilter == vmlFileFilter) {
        mxUtils.writeFile(
            mxXmlUtils.getXml(
                mxCellRenderer.createVmlDocument(graph, null, 1, null, null).getDocumentElement()),
            filename);

      } else if (ext.equalsIgnoreCase("html")) {
        mxUtils.writeFile(
            mxXmlUtils.getXml(
                mxCellRenderer.createHtmlDocument(graph, null, 1, null, null).getDocumentElement()),
            filename);

      } else if (ext.equalsIgnoreCase("mxe") || ext.equalsIgnoreCase("xml")) {
        mxCodec codec = new mxCodec();
        String xml = mxXmlUtils.getXml(codec.encode(graph.getModel()));
        mxUtils.writeFile(xml, filename);

      } else if (ext.equalsIgnoreCase("txt")) {
        String content = mxGdCodec.encode(graph); // .getDocumentString();
        mxUtils.writeFile(content, filename);

      } else if (ext.equalsIgnoreCase("pdf")) {
        exportGraphToPdf(graph, filename);

      } else {
        Color bg = null;

        if ((!ext.equalsIgnoreCase("gif") && !ext.equalsIgnoreCase("png"))
            || JOptionPane.showConfirmDialog(graphComponent, "Transparent Background?")
                != JOptionPane.YES_OPTION) {
          bg = graphComponent.getBackground();
        }

        if (selectedFilter == xmlPngFilter || (ext.equalsIgnoreCase("png") && !dialogShown)) {
          saveXmlPng(trackScheme.getGUI(), filename, bg);
        } else {
          BufferedImage image =
              mxCellRenderer.createBufferedImage(
                  graph,
                  null,
                  1,
                  bg,
                  graphComponent.isAntiAlias(),
                  null,
                  graphComponent.getCanvas());

          if (image != null) {
            ImageIO.write(image, ext, new File(filename));
          } else {
            JOptionPane.showMessageDialog(graphComponent, "No Image Data");
          }
        }
      }

    } catch (Throwable ex) {
      ex.printStackTrace();
      JOptionPane.showMessageDialog(
          graphComponent, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
    }
  }
  @Override
  public String encode(AbstractMeta meta) throws Exception {
    TransMeta transMeta = (TransMeta) meta;

    mxGraph graph = new mxGraph();
    graph.getModel().beginUpdate();
    mxCell parent = (mxCell) graph.getDefaultParent();
    Document doc = mxUtils.createDocument();

    try {
      Element e = super.encodeCommRootAttr(transMeta, doc);
      e.setAttribute("trans_version", transMeta.getTransversion());
      e.setAttribute("trans_type", transMeta.getTransformationType().getCode());
      e.setAttribute("trans_status", String.valueOf(transMeta.getTransstatus()));

      // variables
      Properties sp = new Properties();
      JSONArray jsonArray = new JSONArray();

      String[] keys = Variables.getADefaultVariableSpace().listVariables();
      for (int i = 0; i < keys.length; i++) {
        sp.put(keys[i], Variables.getADefaultVariableSpace().getVariable(keys[i]));
      }

      List<String> vars = transMeta.getUsedVariables();
      for (int i = 0; i < vars.size(); i++) {
        String varname = vars.get(i);
        if (!varname.startsWith(Const.INTERNAL_VARIABLE_PREFIX)
            && Const.indexOfString(varname, transMeta.listParameters()) < 0) {
          JSONObject param = new JSONObject();
          param.put("var_name", varname);
          param.put("var_value", sp.getProperty(varname, ""));
          jsonArray.add(param);
        }
      }

      for (String varname : Const.INTERNAL_JOB_VARIABLES) {
        String value = transMeta.getVariable(varname);
        if (!Const.isEmpty(value)) {

          JSONObject param = new JSONObject();
          param.put("var_name", varname);
          param.put("var_value", value);
          jsonArray.add(param);
        }
      }
      e.setAttribute("variables", jsonArray.toString());

      TransLogTable transLogTable = transMeta.getTransLogTable();
      JSONObject jsonObject = new JSONObject();
      jsonObject.put("connection", transLogTable.getConnectionName());
      jsonObject.put("schema", transLogTable.getSchemaName());
      jsonObject.put("table", transLogTable.getTableName());
      jsonObject.put("size_limit_lines", transLogTable.getLogSizeLimit());
      jsonObject.put("interval", transLogTable.getLogInterval());
      jsonObject.put("timeout_days", transLogTable.getTimeoutInDays());
      JSONArray fields = new JSONArray();
      for (LogTableField field : transLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("subjectAllowed", field.isSubjectAllowed());
        if (field.isSubjectAllowed()) {
          jsonField.put("subject", field.getSubject() == null ? "" : field.getSubject().toString());
        } else {
          jsonField.put("subject", "-");
        }
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("transLogTable", jsonObject.toString());

      StepLogTable stepLogTable = transMeta.getStepLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", stepLogTable.getConnectionName());
      jsonObject.put("schema", stepLogTable.getSchemaName());
      jsonObject.put("table", stepLogTable.getTableName());
      jsonObject.put("timeout_days", stepLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : stepLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("stepLogTable", jsonObject.toString());

      PerformanceLogTable performanceLogTable = transMeta.getPerformanceLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", performanceLogTable.getConnectionName());
      jsonObject.put("schema", performanceLogTable.getSchemaName());
      jsonObject.put("table", performanceLogTable.getTableName());
      jsonObject.put("interval", performanceLogTable.getLogInterval());
      jsonObject.put("timeout_days", performanceLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : performanceLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("performanceLogTable", jsonObject.toString());

      MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
      jsonObject = new JSONObject();
      jsonObject.put("connection", metricsLogTable.getConnectionName());
      jsonObject.put("schema", metricsLogTable.getSchemaName());
      jsonObject.put("table", metricsLogTable.getTableName());
      jsonObject.put("timeout_days", metricsLogTable.getTimeoutInDays());
      fields = new JSONArray();
      for (LogTableField field : metricsLogTable.getFields()) {
        JSONObject jsonField = new JSONObject();
        jsonField.put("id", field.getId());
        jsonField.put("enabled", field.isEnabled());
        jsonField.put("name", field.getFieldName());
        jsonField.put("description", StringEscapeHelper.encode(field.getDescription()));
        fields.add(jsonField);
      }
      jsonObject.put("fields", fields);
      e.setAttribute("metricsLogTable", jsonObject.toString());

      jsonObject = new JSONObject();
      jsonObject.put(
          "connection",
          transMeta.getMaxDateConnection() == null
              ? ""
              : transMeta.getMaxDateConnection().getName());
      jsonObject.put("table", transMeta.getMaxDateTable());
      jsonObject.put("field", transMeta.getMaxDateField());
      jsonObject.put("offset", transMeta.getMaxDateOffset());
      jsonObject.put("maxdiff", transMeta.getMaxDateDifference());
      e.setAttribute("maxdate", jsonObject.toString());

      e.setAttribute("size_rowset", String.valueOf(transMeta.getSizeRowset()));
      e.setAttribute("sleep_time_empty", String.valueOf(transMeta.getSleepTimeEmpty()));
      e.setAttribute("sleep_time_full", String.valueOf(transMeta.getSleepTimeFull()));
      e.setAttribute("unique_connections", transMeta.isUsingUniqueConnections() ? "Y" : "N");
      e.setAttribute("feedback_shown", transMeta.isFeedbackShown() ? "Y" : "N");
      e.setAttribute("feedback_size", String.valueOf(transMeta.getFeedbackSize()));
      e.setAttribute(
          "using_thread_priorities", transMeta.isUsingThreadPriorityManagment() ? "Y" : "N");
      e.setAttribute(
          "capture_step_performance", transMeta.isCapturingStepPerformanceSnapShots() ? "Y" : "N");
      e.setAttribute(
          "step_performance_capturing_delay",
          String.valueOf(transMeta.getStepPerformanceCapturingDelay()));
      e.setAttribute(
          "step_performance_capturing_size_limit",
          transMeta.getStepPerformanceCapturingSizeLimit());

      super.encodeSlaveServers(e, transMeta);
      encodeClusterSchema(e, transMeta);
      encodePartitionSchema(e, transMeta);

      try {
        if (transMeta.getKey() != null) {
          e.setAttribute("key_for_session_key", XMLHandler.encodeBinaryData(transMeta.getKey()));
        } else {
          e.setAttribute("key_for_session_key", "");
        }
      } catch (Exception e1) {
        e1.printStackTrace();
        e.setAttribute("key_for_session_key", "");
      }
      e.setAttribute("is_key_private", transMeta.isPrivateKey() ? "Y" : "N");

      super.encodeNote(doc, graph, transMeta);

      super.encodeDatabases(e, transMeta);
      parent.setValue(e);

      // encode steps and hops
      HashMap<StepMeta, Object> cells = new HashMap<StepMeta, Object>();
      List<StepMeta> list = transMeta.getSteps();
      for (int i = 0; i < list.size(); i++) {
        StepMeta step = (StepMeta) list.get(i);
        Point p = step.getLocation();
        StepEncoder stepEncoder = (StepEncoder) PluginFactory.getBean(step.getStepID());

        PluginInterface plugin =
            PluginRegistry.getInstance().getPlugin(StepPluginType.class, step.getStepID());
        Object cell =
            graph.insertVertex(
                parent,
                null,
                stepEncoder.encodeStep(step),
                p.x,
                p.y,
                40,
                40,
                "icon;image=" + SvgImageUrl.getUrl(plugin));
        cells.put(step, cell);
      }

      for (int i = 0; i < transMeta.nrTransHops(); i++) {
        TransHopMeta transHopMeta = transMeta.getTransHop(i);

        Object v1 = cells.get(transHopMeta.getFromStep());
        Object v2 = cells.get(transHopMeta.getToStep());

        graph.insertEdge(parent, null, TransHopMetaCodec.encode(transHopMeta), v1, v2);
      }
    } finally {
      graph.getModel().endUpdate();
    }

    mxCodec codec = new mxCodec();
    return mxUtils.getPrettyXml(codec.encode(graph.getModel()));
  }
  @Override
  public AbstractMeta decode(String graphXml) throws Exception {
    mxGraph graph = new mxGraph();
    mxCodec codec = new mxCodec();
    Document doc = mxUtils.parseXml(graphXml);
    codec.decode(doc.getDocumentElement(), graph.getModel());
    mxCell root = (mxCell) graph.getDefaultParent();

    TransMeta transMeta = new TransMeta();
    decodeCommRootAttr(root, transMeta);
    transMeta.setTransstatus(Const.toInt(root.getAttribute("trans_status"), -1));
    transMeta.setTransversion(root.getAttribute("trans_version"));

    if (transMeta.getRepository() != null)
      transMeta.setSharedObjects(transMeta.getRepository().readTransSharedObjects(transMeta));
    else transMeta.setSharedObjects(transMeta.readSharedObjects());

    transMeta.importFromMetaStore();

    decodeDatabases(root, transMeta);
    decodeNote(graph, transMeta);

    int count = graph.getModel().getChildCount(root);
    for (int i = 0; i < count; i++) {
      mxCell cell = (mxCell) graph.getModel().getChildAt(root, i);
      if (cell.isVertex()) {
        Element e = (Element) cell.getValue();
        if (PropsUI.TRANS_STEP_NAME.equals(e.getTagName())) {
          StepDecoder stepDecoder = (StepDecoder) PluginFactory.getBean(cell.getAttribute("ctype"));
          StepMeta stepMeta =
              stepDecoder.decodeStep(cell, transMeta.getDatabases(), transMeta.getMetaStore());
          stepMeta.setParentTransMeta(transMeta);
          if (stepMeta.isMissing()) {
            transMeta.addMissingTrans((MissingTrans) stepMeta.getStepMetaInterface());
          }

          StepMeta check = transMeta.findStep(stepMeta.getName());
          if (check != null) {
            if (!check.isShared()) {
              // Don't overwrite shared objects
              transMeta.addOrReplaceStep(stepMeta);
            } else {
              check.setDraw(stepMeta.isDrawn()); // Just keep the  drawn flag  and location
              check.setLocation(stepMeta.getLocation());
            }
          } else {
            transMeta.addStep(stepMeta); // simply add it.
          }
        }
      }
    }

    // Have all StreamValueLookups, etc. reference the correct source steps...
    //
    for (int i = 0; i < transMeta.nrSteps(); i++) {
      StepMeta stepMeta = transMeta.getStep(i);
      StepMetaInterface sii = stepMeta.getStepMetaInterface();
      if (sii != null) {
        sii.searchInfoAndTargetSteps(transMeta.getSteps());
      }
    }

    count = graph.getModel().getChildCount(root);
    for (int i = 0; i < count; i++) {
      mxCell cell = (mxCell) graph.getModel().getChildAt(root, i);
      if (cell.isEdge()) {
        mxCell source = (mxCell) cell.getSource();
        mxCell target = (mxCell) cell.getTarget();

        TransHopMeta hopinf = new TransHopMeta(null, null, true);
        String[] stepNames = transMeta.getStepNames();
        for (int j = 0; j < stepNames.length; j++) {
          if (stepNames[j].equalsIgnoreCase(source.getAttribute("label")))
            hopinf.setFromStep(transMeta.getStep(j));
          if (stepNames[j].equalsIgnoreCase(target.getAttribute("label")))
            hopinf.setToStep(transMeta.getStep(j));
        }
        transMeta.addTransHop(hopinf);
      }
    }

    JSONObject jsonObject = JSONObject.fromObject(root.getAttribute("transLogTable"));
    TransLogTable transLogTable = transMeta.getTransLogTable();
    transLogTable.setConnectionName(jsonObject.optString("connection"));
    transLogTable.setSchemaName(jsonObject.optString("schema"));
    transLogTable.setTableName(jsonObject.optString("table"));
    transLogTable.setLogSizeLimit(jsonObject.optString("size_limit_lines"));
    transLogTable.setLogInterval(jsonObject.optString("interval"));
    transLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    JSONArray jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = transLogTable.findField(id);
        if (field == null) {
          field = transLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
          field.setSubject(StepMeta.findStep(transMeta.getSteps(), fieldJson.optString("subject")));
        }
      }
    }

    jsonObject = JSONObject.fromObject(root.getAttribute("stepLogTable"));
    StepLogTable stepLogTable = transMeta.getStepLogTable();
    stepLogTable.setConnectionName(jsonObject.optString("connection"));
    stepLogTable.setSchemaName(jsonObject.optString("schema"));
    stepLogTable.setTableName(jsonObject.optString("table"));
    stepLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = stepLogTable.findField(id);
        if (field == null && i < stepLogTable.getFields().size()) {
          field = stepLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
        }
      }
    }

    jsonObject = JSONObject.fromObject(root.getAttribute("performanceLogTable"));
    PerformanceLogTable performanceLogTable = transMeta.getPerformanceLogTable();
    performanceLogTable.setConnectionName(jsonObject.optString("connection"));
    performanceLogTable.setSchemaName(jsonObject.optString("schema"));
    performanceLogTable.setTableName(jsonObject.optString("table"));
    performanceLogTable.setLogInterval(jsonObject.optString("interval"));
    performanceLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = performanceLogTable.findField(id);
        if (field == null && i < performanceLogTable.getFields().size()) {
          field = performanceLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
        }
      }
    }

    jsonObject = JSONObject.fromObject(root.getAttribute("metricsLogTable"));
    MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
    metricsLogTable.setConnectionName(jsonObject.optString("connection"));
    metricsLogTable.setSchemaName(jsonObject.optString("schema"));
    metricsLogTable.setTableName(jsonObject.optString("table"));
    metricsLogTable.setTimeoutInDays(jsonObject.optString("timeout_days"));
    jsonArray = jsonObject.optJSONArray("fields");
    if (jsonArray != null) {
      for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject fieldJson = jsonArray.getJSONObject(i);
        String id = fieldJson.optString("id");
        LogTableField field = metricsLogTable.findField(id);
        if (field == null && i < metricsLogTable.getFields().size()) {
          field = metricsLogTable.getFields().get(i);
        }
        if (field != null) {
          field.setFieldName(fieldJson.optString("name"));
          field.setEnabled(fieldJson.optBoolean("enabled"));
        }
      }
    }

    jsonArray = JSONArray.fromObject(root.getAttribute("partitionschemas"));
    for (int i = 0; i < jsonArray.size(); i++) {
      jsonObject = jsonArray.getJSONObject(i);
      PartitionSchema partitionSchema = decodePartitionSchema(jsonObject);
      PartitionSchema check = transMeta.findPartitionSchema(partitionSchema.getName());
      if (check != null) {
        if (!check.isShared()) {
          transMeta.addOrReplacePartitionSchema(partitionSchema);
        }
      } else {
        transMeta.getPartitionSchemas().add(partitionSchema);
      }
    }

    decodeSlaveServers(root, transMeta);

    jsonArray = JSONArray.fromObject(root.getAttribute("clusterSchemas"));
    for (int i = 0; i < jsonArray.size(); i++) {
      jsonObject = jsonArray.getJSONObject(i);
      ClusterSchema clusterSchema = decodeClusterSchema(jsonObject, transMeta.getSlaveServers());
      clusterSchema.shareVariablesWith(transMeta);

      ClusterSchema check = transMeta.findClusterSchema(clusterSchema.getName());
      if (check != null) {
        if (!check.isShared()) {
          transMeta.addOrReplaceClusterSchema(clusterSchema);
        }
      } else {
        transMeta.getClusterSchemas().add(clusterSchema);
      }
    }

    for (int i = 0; i < transMeta.nrSteps(); i++) {
      transMeta.getStep(i).setClusterSchemaAfterLoading(transMeta.getClusterSchemas());
    }

    transMeta.setSizeRowset(Const.toInt(root.getAttribute("size_rowset"), Const.ROWS_IN_ROWSET));
    transMeta.setSleepTimeEmpty(
        Const.toInt(root.getAttribute("sleep_time_empty"), Const.TIMEOUT_GET_MILLIS));
    transMeta.setSleepTimeFull(
        Const.toInt(root.getAttribute("sleep_time_full"), Const.TIMEOUT_PUT_MILLIS));
    transMeta.setUsingUniqueConnections(
        "Y".equalsIgnoreCase(root.getAttribute("unique_connections")));

    transMeta.setFeedbackShown(!"N".equalsIgnoreCase(root.getAttribute("feedback_shown")));
    transMeta.setFeedbackSize(Const.toInt(root.getAttribute("feedback_size"), Const.ROWS_UPDATE));
    transMeta.setUsingThreadPriorityManagment(
        !"N".equalsIgnoreCase(root.getAttribute("using_thread_priorities")));

    transMeta.setCapturingStepPerformanceSnapShots(
        "Y".equalsIgnoreCase(root.getAttribute("capture_step_performance")));
    transMeta.setStepPerformanceCapturingDelay(
        Const.toLong(root.getAttribute("step_performance_capturing_delay"), 1000));
    transMeta.setStepPerformanceCapturingSizeLimit(
        root.getAttribute("step_performance_capturing_size_limit"));

    transMeta.setKey(XMLHandler.stringToBinary(root.getAttribute("key_for_session_key")));
    transMeta.setPrivateKey("Y".equals(root.getAttribute("is_key_private")));

    return transMeta;
  }