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

📄 snmp4jconfigmib.java

📁 你个snmp的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     //--AgentGen END
    }
  }
  /**
   * The <code>Snmp4jCfgStorageFormatValidator</code> implements the value
   * validation for <code>Snmp4jCfgStorageFormat</code>.
   */
  static class Snmp4jCfgStorageFormatValidator implements MOValueValidationListener {

    public void validate(MOValueValidationEvent validationEvent) {
      Variable newValue = validationEvent.getNewValue();
     //--AgentGen BEGIN=snmp4jCfgStorageFormat::validate
     if (((Integer32)newValue).getValue() != Snmp4jCfgStorageFormatEnum.binary) {
       validationEvent.setValidationStatus(PDU.wrongValue);
     }
     //--AgentGen END
    }
  }
  /**
   * The <code>Snmp4jCfgStorageOperationValidator</code> implements the value
   * validation for <code>Snmp4jCfgStorageOperation</code>.
   */
  static class Snmp4jCfgStorageOperationValidator implements MOValueValidationListener {

    public void validate(MOValueValidationEvent validationEvent) {
      Variable newValue = validationEvent.getNewValue();
     //--AgentGen BEGIN=snmp4jCfgStorageOperation::validate
     switch (newValue.toInt()) {
       case Snmp4jCfgStorageOperationEnum.restore:
       case Snmp4jCfgStorageOperationEnum.store:
         break;
       default:
         validationEvent.setValidationStatus(PDU.wrongValue);
     }
     //--AgentGen END
    }
  }

  // Enumerations
  public static final class Snmp4jCfgSecSrcAddrValidationEnum {
    public static final int enabled = 1;
    public static final int disabled = 2;
    public static final int notAvailable = 3;
  }

  public static final class Snmp4jCfgStorageFormatEnum {
    /* -- Default format */
    public static final int binary = 1;
    public static final int xml = 2;
  }
  public static final class Snmp4jCfgStorageRestoreModeEnum {
    public static final int replaceAndCreate = 1;
    public static final int updateAndCreate = 2;
    public static final int updateOnly = 3;
    public static final int createOnly = 4;
  }
  public static final class Snmp4jCfgStorageOperationEnum {
    /* -- no action */
    public static final int idle = 1;
    /* -- (re)store operation in progress */
    public static final int inProgress = 2;
    /* -- store current configuration */
    public static final int store = 3;
    /* -- restore configuration */
    public static final int restore = 4;
  }

  // Rows and Factories
  class Snmp4jCfgStorageEntryRowFactory
        extends DefaultMOMutableRow2PCFactory
  {
    public Snmp4jCfgStorageEntryRowFactory() {}

    public MOTableRow createRow(OID index, Variable[] values)
        throws UnsupportedOperationException
    {
      Snmp4jCfgStorageEntryRow row = new Snmp4jCfgStorageEntryRow(index, values);
     //--AgentGen BEGIN=snmp4jCfgStorageEntry::createRow
     ((Integer32)values[idxSnmp4jCfgStorageOperation]).
         setValue(Snmp4jCfgStorageOperationEnum.idle);
     //--AgentGen END
      return row;
    }

    public void freeRow(MOTableRow row) {
     //--AgentGen BEGIN=snmp4jCfgStorageEntry::freeRow
     //--AgentGen END
    }
  }

  class Snmp4jCfgStorageEntryRow extends DefaultMOMutableRow2PC {

    public Snmp4jCfgStorageEntryRow(OID index, Variable[] values) {
      super(index, values);
    }

    public OctetString getSnmp4jCfgStoragePath() {
      return (OctetString) getValue(idxSnmp4jCfgStoragePath);
    }

    public void setSnmp4jCfgStoragePath(OctetString newValue) {
      setValue(idxSnmp4jCfgStoragePath, newValue);
    }

    public Integer32 getSnmp4jCfgStorageFormat() {
      return (Integer32) getValue(idxSnmp4jCfgStorageFormat);
    }

    public void setSnmp4jCfgStorageFormat(Integer32 newValue) {
      setValue(idxSnmp4jCfgStorageFormat, newValue);
    }

    public TimeTicks getSnmp4jCfgStorageLastStore() {
      return (TimeTicks) getValue(idxSnmp4jCfgStorageLastStore);
    }

    public void setSnmp4jCfgStorageLastStore(TimeTicks newValue) {
      setValue(idxSnmp4jCfgStorageLastStore, newValue);
    }

    public TimeTicks getSnmp4jCfgStorageLastRestore() {
      return (TimeTicks) getValue(idxSnmp4jCfgStorageLastRestore);
    }

    public void setSnmp4jCfgStorageLastRestore(TimeTicks newValue) {
      setValue(idxSnmp4jCfgStorageLastRestore, newValue);
    }

    public Integer32 getSnmp4jCfgStorageRestoreMode() {
      return (Integer32) getValue(idxSnmp4jCfgStorageRestoreMode);
    }

    public void setSnmp4jCfgStorageRestoreMode(Integer32 newValue) {
      setValue(idxSnmp4jCfgStorageRestoreMode, newValue);
    }

    public Integer32 getSnmp4jCfgStorageOperation() {
      return (Integer32) getValue(idxSnmp4jCfgStorageOperation);
    }

    public void setSnmp4jCfgStorageOperation(Integer32 newValue) {
      setValue(idxSnmp4jCfgStorageOperation, newValue);
    }

    public Integer32 getSnmp4jCfgStorageStorageType() {
      return (Integer32) getValue(idxSnmp4jCfgStorageStorageType);
    }

    public void setSnmp4jCfgStorageStorageType(Integer32 newValue) {
      setValue(idxSnmp4jCfgStorageStorageType, newValue);
    }

    public Integer32 getSnmp4jCfgStorageStatus() {
      return (Integer32) getValue(idxSnmp4jCfgStorageStatus);
    }

    public void setSnmp4jCfgStorageStatus(Integer32 newValue) {
      setValue(idxSnmp4jCfgStorageStatus, newValue);
    }

    //--AgentGen BEGIN=snmp4jCfgStorageEntry::RowFactory

    public void prepareRow(SubRequest subRequest, MOTableRow changeSet) {
      if (PRIMARY_INDEX.equals(changeSet.getIndex())) {
        if (snmp4jCfgStorageEntryModel.getRow(PRIMARY_INDEX) == null) {
          subRequest.getRequest().setErrorStatus(PDU.noCreation);
        }
      }
    }

    public void commitRow(SubRequest subRequest, MOTableRow changeSet) {
      Integer32 operation = getSnmp4jCfgStorageOperation();
      Integer32 format = getSnmp4jCfgStorageFormat();
      if (format.getValue() == Snmp4jCfgStorageFormatEnum.binary) {
        MOPersistenceProvider provider = getPersistenceProvider(format.getValue());
        if (provider == null) {
          subRequest.getRequest().setErrorStatus(PDU.commitFailed);
        }
        else {
          Operation op =
              new Operation(this, provider,
                            getSnmp4jCfgStorageRestoreMode().getValue(),
                            operation.getValue());
          setValue(idxSnmp4jCfgStorageOperation,
                   new Integer32(Snmp4jCfgStorageOperationEnum.inProgress));
          op.start();
        }
      }
      else {
        subRequest.getRequest().setErrorStatus(PDU.commitFailed);
      }
    }

    //--AgentGen END
  }



//--AgentGen BEGIN=_METHODS

  public void setSnmpCommunityMIB(SnmpCommunityMIB snmpCommunityMIB) {
    this.snmpCommunityMIB = snmpCommunityMIB;
  }

  public void setDefaultConfigFile(File defaultConfigFile) {
    this.defaultConfigFile = defaultConfigFile;

    Snmp4jCfgStorageEntryRow primary = (Snmp4jCfgStorageEntryRow)
        snmp4jCfgStorageEntryModel.getRow(PRIMARY_INDEX);
    if (primary == null) {
      Variable[] vbs = snmp4jCfgStorageEntry.getDefaultValues();
      vbs[idxSnmp4jCfgStorageStatus] = new Integer32(RowStatus.active);
      primary = (Snmp4jCfgStorageEntryRow)
          snmp4jCfgStorageEntry.createRow(PRIMARY_INDEX, vbs);
      primary.setSnmp4jCfgStorageStorageType(
          new Integer32(StorageType.permanent));
      primary.setSnmp4jCfgStorageOperation(
          new Integer32(Snmp4jCfgStorageOperationEnum.idle));
      snmp4jCfgStorageEntry.addRow(primary);
    }
    primary.setSnmp4jCfgStoragePath(new OctetString(defaultConfigFile.getPath()));
  }

  public void setPersistenceProvider(int format,
                                     MOPersistenceProvider provider) {
    persistenceProvider[format-1] = provider;
  }

  public MOPersistenceProvider getPersistenceProvider(int format) {
    return persistenceProvider[format-1];
  }

  public SnmpCommunityMIB getCoexistenceInfoProvider() {
    return this.snmpCommunityMIB;
  }

//--AgentGen END

//--AgentGen BEGIN=_CLASSES

  private class Operation extends Thread {

    private Snmp4jCfgStorageEntryRow row;
    private int operation;
    private int restoreType;
    private MOPersistenceProvider provider;

    public Operation(Snmp4jCfgStorageEntryRow row,
                     MOPersistenceProvider provider,
                     int restoreType,
                     int operation) {
      this.operation = operation;
      this.provider = provider;
      this.restoreType = restoreType;
      this.row = row;
    }

    public void run() {
      switch (operation) {
        case Snmp4jCfgStorageOperationEnum.store: {
          File f = new File(row.getValue(idxSnmp4jCfgStoragePath).toString());
          try {
            FileOutputStream fos = new FileOutputStream(f);
            provider.saveConfig(fos);
            fos.close();
            row.setValue(idxSnmp4jCfgStorageLastStore, sysUpTime.get());
            row.setValue(idxSnmp4jCfgStorageOperation,
                         new Integer32(Snmp4jCfgStorageOperationEnum.idle));
          }
          catch (IOException iox) {
            logger.warn("Failed to store config to '"+f+"': "+iox.getMessage());
            row.setValue(idxSnmp4jCfgStorageOperation,
                         new Integer32(Snmp4jCfgStorageOperationEnum.idle));
          }
          break;
        }
        case Snmp4jCfgStorageOperationEnum.restore: {
          File f = new File(row.getValue(idxSnmp4jCfgStoragePath).toString());
          if (f.exists() && f.canRead()) {
            try {
              FileInputStream fis = new FileInputStream(f);
              provider.loadConfig(fis, restoreType);
              fis.close();
              row.setValue(idxSnmp4jCfgStorageLastRestore, sysUpTime.get());
              row.setValue(idxSnmp4jCfgStorageOperation,
                           new Integer32(Snmp4jCfgStorageOperationEnum.idle));
            }
            catch (IOException iox) {
              logger.warn("Failed to store config to '" + f + "': "+
                          iox.getMessage());
            }
          }
          else {
            logger.warn("File '"+f+"' does not exists or is not readable");
          }
          break;
        }
      }
    }
  }

//--AgentGen END

//--AgentGen BEGIN=_END
//--AgentGen END
}


⌨️ 快捷键说明

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