Exemple #1
0
/** @author szekely */
public class Node extends RepEntity implements Neighbor {

  private static Logger logger = LoggerFactory.getLogger(Node.class);

  public enum NodeStatus {
    original("O"),
    edited("E");

    private String codedValue;

    private NodeStatus(String userLabel) {
      this.codedValue = userLabel;
    }

    public String getCodedStatus() {
      return codedValue;
    }
  }

  // the HNode that defines my properties.
  private final String hNodeId;

  // possibly has a nested table, null if none
  private Table nestedTable = null;

  private NodeStatus status = NodeStatus.original;

  // The value stored in this cell.
  private CellValue value = CellValue.getEmptyValue();

  private CellValue originalValue = CellValue.getEmptyValue();

  // mariam
  /** The row that this node belongs to */
  private Row belongsToRow;

  Node(String id, String hNodeId) {
    super(id);
    this.hNodeId = hNodeId;
  }

  // mariam
  public void setBelongsToRow(Row row) {
    belongsToRow = row;
  }

  public Row getBelongsToRow() {
    return belongsToRow;
  }

  /**
   * Return the table that this node belongs to.
   *
   * @return the table that this node belongs to.
   */
  public Table getParentTable() {
    return belongsToRow.getBelongsToTable();
  }

  // /////////////

  public String getHNodeId() {
    return hNodeId;
  }

  public NodeStatus getStatus() {
    return status;
  }

  public CellValue getOriginalValue() {
    return originalValue;
  }

  public CellValue getValue() {
    return value;
  }

  public void setValue(CellValue value, NodeStatus status, RepFactory factory) {
    this.value = value;
    this.status = status;
    // Pedro 2012/09/14
    if (nestedTable != null) {
      logger.info(
          "Node in column '"
              + factory.getColumnName(hNodeId)
              + "' contains both value and nested table: "
              + toString()
              + " -- setting value '"
              + value.asString()
              + "'");
      nestedTable.addOrphanValue(value, factory);
    }
  }

  public void clearValue(NodeStatus status) {
    // pedro 2012-09-15: this was wrong because it was setting the value to
    // null.
    this.value = CellValue.getEmptyValue();
    this.status = status;
  }

  public void setValue(String value, NodeStatus status, RepFactory factory) {
    setValue(new StringCellValue(value), status, factory);
  }

  public Table getNestedTable() {
    return nestedTable;
  }

  public void setNestedTable(Table nestedTable, RepFactory factory) {
    this.nestedTable = nestedTable;
    // mariam
    if (nestedTable != null) {
      nestedTable.setNestedTableInNode(this);
      // pedro 2012-09-15
      if (!value.isEmptyValue()) {
        logger.info(
            "Node in column '"
                + factory.getColumnName(hNodeId)
                + "' contains both value and nested table: "
                + toString()
                + " -- setting value '"
                + value.asString()
                + "'");
        nestedTable.addOrphanValue(value, factory);
      }
    }
  }

  public boolean hasNestedTable() {
    return nestedTable != null;
  }

  public String toString() {
    StringBuffer b = new StringBuffer();
    b.append("N(");
    b.append(getId() + ",");
    b.append(hNodeId + ",");
    if (nestedTable != null) {
      b.append("*" + nestedTable.getId() + "/" + nestedTable.getHTableId() + ")");
    } else {
      b.append(value.asString() + ")");
    }
    return b.toString();
  }

  @Override
  public void prettyPrint(String prefix, PrintWriter pw, RepFactory factory) {
    pw.print(prefix + "  - ");
    pw.print(factory.getHNode(hNodeId).getColumnName() + "/" + id + "/" + hNodeId + ":");
    if (nestedTable != null) {
      pw.println();
      nestedTable.prettyPrint(prefix + "      ", pw, factory);
    } else {
      pw.println("<" + value.asString() + ">");
    }
  }

  @Override
  public boolean canReachNeighbor(String hNodeId) {
    return belongsToRow.canReachNeighbor(hNodeId);
  }

  @Override
  public Node getNeighbor(String hNodeId) {
    return belongsToRow.getNeighbor(hNodeId);
  }

  @Override
  public Node getNeighborByColumnName(String columnName, RepFactory factory) {
    return belongsToRow.getNeighborByColumnName(columnName, factory);
  }
}
Exemple #2
0
 public void clearValue(NodeStatus status) {
   // pedro 2012-09-15: this was wrong because it was setting the value to
   // null.
   this.value = CellValue.getEmptyValue();
   this.status = status;
 }