⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultmotable.java

📁 你个snmp的源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  public OID getOID() {
    return oid;
  }

  public void setModel(MOTableModel model) {
    this.model = model;
  }

  public void setVolatile(boolean isVolatile) {
    this.isVolatile = isVolatile;
  }

  public MOTableModel getModel() {
    return model;
  }

  public MOColumn[] getColumns() {
    return columns;
  }

  public MOTableIndex getIndexDef() {
    return indexDef;
  }

  public boolean isVolatile() {
    return isVolatile;
  }

  public OID getLowerBound() {
    return oid;
  }

  public OID getUpperBound() {
    OID upperBound = new OID(oid);
    int lastID = oid.size()-1;
    /**
     * This is not quite correct because we would have to search up the tree
     * if the last sub ID is 0xFFFFFFFF, but since a table OID must end on 1
     * by SMI rules we should be on the safe side here.
     */
    upperBound.set(lastID, oid.get(lastID)+1);
    return upperBound;
  }

  public boolean isLowerIncluded() {
    return false;
  }

  public boolean isUpperIncluded() {
    return false;
  }

  public boolean isCovered(MOScope other) {
    return DefaultMOScope.covers(this, other);
  }

  public boolean isOverlapping(MOScope other) {
    return DefaultMOScope.overlaps(this, other);
  }

  public synchronized void addMOChangeListener(MOChangeListener l) {
    if (moChangeListeners == null) {
      moChangeListeners = new Vector(2);
    }
    moChangeListeners.add(l);
  }

  public synchronized void removeMOChangeListener(MOChangeListener l) {
    if (moChangeListeners != null) {
      moChangeListeners.remove(l);
    }
  }

  protected void fireBeforePrepareMOChange(MOChangeEvent changeEvent) {
    if (moChangeListeners != null) {
      Vector listeners = moChangeListeners;
      int count = listeners.size();
      for (int i = 0; i < count; i++) {
        ((MOChangeListener) listeners.elementAt(i)).beforePrepareMOChange(changeEvent);
      }
    }
  }

  protected void fireAfterPrepareMOChange(MOChangeEvent changeEvent) {
    if (moChangeListeners != null) {
      Vector listeners = moChangeListeners;
      int count = listeners.size();
      for (int i = 0; i < count; i++) {
        ((MOChangeListener) listeners.elementAt(i)).afterPrepareMOChange(changeEvent);
      }
    }
  }

  protected void fireBeforeMOChange(MOChangeEvent changeEvent) {
    if (moChangeListeners != null) {
      Vector listeners = moChangeListeners;
      int count = listeners.size();
      for (int i = 0; i < count; i++) {
        ((MOChangeListener) listeners.elementAt(i)).beforeMOChange(changeEvent);
      }
    }
  }

  protected void fireAfterMOChange(MOChangeEvent changeEvent) {
    if (moChangeListeners != null) {
      Vector listeners = moChangeListeners;
      int count = listeners.size();
      for (int i = 0; i < count; i++) {
        ((MOChangeListener) listeners.elementAt(i)).afterMOChange(changeEvent);
      }
    }
  }

  public synchronized void addMOTableRowListener(MOTableRowListener l) {
    if (moTableRowListeners == null) {
      moTableRowListeners = new Vector(2);
    }
    moTableRowListeners.add(l);
  }

  public synchronized void removeMOTableRowListener(MOTableRowListener l) {
    if (moTableRowListeners != null) {
      moTableRowListeners.remove(l);
    }
  }

  protected void fireRowChanged(MOTableRowEvent event) {
    if (moTableRowListeners != null) {
      Vector listeners = moTableRowListeners;
      int count = listeners.size();
      for (int i = 0; i < count; i++) {
        ((MOTableRowListener) listeners.elementAt(i)).rowChanged(event);
      }
    }
  }

  public class ChangeSet implements MOTableRow {

    private OID index;
    private Variable[] values;
    private int lastChangedColumn = -1;

    public ChangeSet(OID index, Variable[] values) {
      this.index = index;
      this.values = values;
    }

    public OID getIndex() {
      return index;
    }

    public int getLastChangedColumn() {
      return lastChangedColumn;
    }

    public void setValue(int column, Variable value) {
      values[column] = value;
      this.lastChangedColumn = column;
    }

    public Variable getValue(int column) {
      return values[column];
    }

    public MOTableRow getBaseRow() {
      return null;
    }

    public int size() {
      return values.length;
    }

    public void setBaseRow(MOTableRow baseRow) {
      throw new UnsupportedOperationException();
    }
  }

  class CellProxy implements ManagedObject {

    private MOTableCellInfo cellInfo;
    private MOScope scope;

    public CellProxy(MOTableCellInfo cellInfo) {
      this.cellInfo = cellInfo;
      this.scope = new OIDScope(cellInfo.getCellOID());
    }

    public MOScope getScope() {
      return scope;
    }

    public OID find(MOScope range) {
      if (range.isCovered(scope)) {
        return cellInfo.getCellOID();
      }
      return null;
    }

    public void get(SubRequest request) {
      DefaultMOTable.this.get(request);
    }

    public boolean next(SubRequest request) {
      return DefaultMOTable.this.next(request);
    }

    public void prepare(SubRequest request) {
      DefaultMOTable.this.prepare(request);
    }

    public void commit(SubRequest request) {
      DefaultMOTable.this.commit(request);
    }

    public void undo(SubRequest request) {
      DefaultMOTable.this.undo(request);
    }

    public void cleanup(SubRequest request) {
      DefaultMOTable.this.cleanup(request);
    }

    public MOTable getTable() {
      return DefaultMOTable.this;
    }
  }

  class CellInfo implements MOTableCellInfo {

    private OID index;
    private int id = 0;
    private int col = -1;

    public CellInfo(OID oid) {
      this.index = getIndexPart(oid);
      if ((oid.size() > DefaultMOTable.this.oid.size()) &&
          (oid.startsWith(DefaultMOTable.this.oid))) {
        id = oid.get(DefaultMOTable.this.oid.size());
      }
/*
      else {
        id = columns[0].getColumnID();
      }
*/
    }

    public CellInfo(OID index, int column, int columnID) {
      this.index = index;
      this.col = column;
      this.id = columnID;
    }

    public OID getIndex() {
      return index;
    }

    public int getColumn() {
      if (col < 0) {
        col = getColumnIndex(id);
      }
      return col;
    }

    public int getColumnID() {
      return id;
    }

    public OID getCellOID() {
      return DefaultMOTable.this.getCellOID(index, col);
    }

  }

  public OID getID() {
    return getLowerBound();
  }

  public void load(MOInput input) throws IOException {
    if (input.getImportMode() == ImportModes.REPLACE_CREATE) {
      int count = removeAll();
      if (logger.isDebugEnabled()) {
        logger.debug("Removed "+count+" rows from "+getID()+
                     " because importing with a REPLACE import mode");
      }
    }
    Sequence seq = input.readSequence();
    for (int i=0; i<seq.getSize(); i++) {
      IndexedVariables rowValues = input.readIndexedVariables();
      boolean rowExists = model.containsRow(rowValues.getIndex());
      if ((input.getImportMode() == ImportModes.CREATE) && (rowExists)) {
        logger.debug("Row '" + rowValues.getIndex() +
                     "' not imported because it already exists in table " +
                     getID() + " and import mode is CREATE");
        continue;
      }
      if (rowExists) {
        removeRow(rowValues.getIndex());
      }
      /**@todo Do real update here instead of delete/create */
      if ((rowExists) ||
          ((input.getImportMode() == ImportModes.CREATE) ||
           (input.getImportMode() == ImportModes.REPLACE_CREATE) ||
           (input.getImportMode() == ImportModes.UPDATE_CREATE))) {
        MOTableRow row = null;
        try {
          row = createRow(rowValues.getIndex(), rowValues.getValues());
        }
        catch (UnsupportedOperationException uoex) {
          logger.debug("Could not create row by row factory: " +
                       uoex.getMessage());
          // ignore
        }
        if (row == null) {
          row =
              new DefaultMOTableRow(rowValues.getIndex(), rowValues.getValues());
          fireRowChanged(new MOTableRowEvent(this,
                                             this, row, MOTableRowEvent.CREATE));
        }
        addRow(row);
      }
    }
  }

  public void save(MOOutput output) throws IOException {
    List rowsToSave = new LinkedList();
    synchronized (model) {
      for (Iterator it = model.iterator(); it.hasNext(); ) {
        MOTableRow row = (MOTableRow) it.next();
        boolean volatileRow = false;
        for (int i = 0; i < columns.length; i++) {
          if (columns[i].isVolatile(row, i)) {
            volatileRow = true;
            break;
          }
        }
        if (!volatileRow) {
          Variable[] values = new Variable[columns.length];
          for (int i=0; i<columns.length; i++) {
            values[i] = row.getValue(i);
          }
          IndexedVariables rowValues =
              new IndexedVariables(row.getIndex(), values);
          rowsToSave.add(rowValues);
        }
      }
    }
    Sequence group = new Sequence(rowsToSave.size());
    output.writeSequence(group);
    for (Iterator it = rowsToSave.iterator(); it.hasNext(); ) {
      IndexedVariables rowValues = (IndexedVariables) it.next();
      output.writeIndexedVariables(rowValues);
    }
  }

  public Variable[] getDefaultValues() {
    Variable[] values = new Variable[getColumnCount()];
    for (int i = 0; (i < values.length); i++) {
      if (columns[i] instanceof MOMutableColumn) {
        values[i] = ((MOMutableColumn) columns[i]).getDefaultValue();
      }
    }
    return values;
  }

  public String toString() {
    return "DefaultMOTable[id="+getID()+",index="+getIndexDef()+",columns="+
        Arrays.asList(getColumns())+"]";
  }

  public boolean covers(OID oid) {
    return isCovered(new DefaultMOScope(oid, true, oid, true));
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -