Exemplo n.º 1
0
  protected RenderableDataItem createItem(JSONObject json, iDataItemParserCallback callback) {
    JSONArray columns = json.optJSONArray("_columns");
    JSONArray rows = json.optJSONArray("_rows");

    if ((columns != null) && (rows != null)) {
      RenderableDataItem row = new RenderableDataItem();

      row.ensureCapacity(rows.size());
      addRows(row.getItems(), columns, rows, callback);
    }

    if (rows != null) {
      RenderableDataItem item = callback.createItem(null);

      item.ensureCapacity(rows.size());
      addItems(item.getItems(), rows, callback);

      return item;
    }

    JSONStructuredNode node = new JSONStructuredNode("row", json);
    DataItem di = new DataItem();

    di.fromStructuredNode(node);

    return callback.createItemEx(di);
  }
Exemplo n.º 2
0
  protected RenderableDataItem createRow(
      JSONArray columns, JSONObject json, iDataItemParserCallback callback) {
    RenderableDataItem row = new RenderableDataItem();
    RenderableDataItem item;
    int len = columns.size();

    row.ensureCapacity(len);

    for (int i = 0; i < len; i++) {
      String col = columns.getString(i);
      Object o = json.opt(col);

      if (o instanceof JSONArray) {
        item = callback.createItem(null);

        JSONArray a = (JSONArray) o;

        item.ensureCapacity(a.size());
        addItems(item.getItems(), a, callback);
      }

      if (o instanceof JSONObject) {
        item = createItem((JSONObject) o, callback);
      } else {
        item = callback.createItem(o);
      }

      row.add(item);
    }

    return row;
  }
Exemplo n.º 3
0
  public void parse(iWidget context, JSONObject json, iDataItemParserCallback callback)
      throws IOException {
    callback.startedParsing();

    JSONArray columns = (json == null) ? null : json.optJSONArray("_columns");
    JSONArray rows = (json == null) ? null : json.optJSONArray("_rows");

    try {
      if (rows != null) {
        addRows(null, columns, rows, callback);
      }

      callback.finishedParsing();
    } catch (Exception e) {
      if (!(e instanceof IOException)) {
        e = new IOException(e);
      }

      throw (IOException) e;
    }
  }