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

📄 snmpvarbind.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @exception ClassCastException An attempt has been made to cast an object to a subclass of which      * it is not an instance.     */    final public SnmpIpAddress getSnmpIpAddressValue() throws ClassCastException {        return (SnmpIpAddress)this.value ;    }    /**     * Sets the <CODE>SnmpIpAddress</CODE> value part associated with this <CODE>SnmpVarBind</CODE>      * with the specified ipAddress value.     * The status is updated to indicate that the value is valid.     * @param val The new IP address value.     * @exception IllegalArgumentException The specified value does not correspond to an IP address.     * @see SnmpIpAddress     */    final public void setSnmpIpAddressValue(String val) throws IllegalArgumentException {        clearValue() ;        this.value = new SnmpIpAddress(val) ;        setValueValid() ;    }    /**     * Returns the value part associated with this <CODE>SnmpVarBind</CODE>.     * @return The <CODE>SnmpString</CODE> value for this variable.     * @exception ClassCastException An attempt has been made to cast an object to a subclass of which      * it is not an instance.     */    final public SnmpString getSnmpStringValue() throws ClassCastException {        return (SnmpString)this.value ;    }      /**     * Sets the <CODE>SnmpString</CODE> value part associated with this <CODE>SnmpVarBind</CODE>      * with the specified string value.     * The status is updated to indicate that the value is valid.     * @param val The new string value.     * @see SnmpString        */    final public void setSnmpStringValue(String val) {        clearValue() ;        this.value = new SnmpString(val) ;        setValueValid() ;    }    /**     * Returns the value part associated with this <CODE>SnmpVarBind</CODE>.     * @return The <CODE>SnmpOpaque</CODE> value for this variable.     * @exception ClassCastException An attempt has been made to cast an object to a subclass of which      * it is not an instance.          */    final public SnmpOpaque getSnmpOpaqueValue() throws ClassCastException {        return (SnmpOpaque)this.value ;    }      /**     * Sets the <CODE>SnmpOpaque</CODE> value part associated with this <CODE>SnmpVarBind</CODE>      * with the specified bytes array values.     * The status is updated to indicate that the value is valid.     * @param val The new bytes array value.     * @see SnmpOpaque     */    final public void setSnmpOpaqueValue(byte[] val) {        clearValue() ;        this.value = new SnmpOpaque(val) ;        setValueValid() ;    }    /**     * Returns the value part associated with this <CODE>SnmpVarBind</CODE>.     * @return The <CODE>SnmpStringFixed</CODE> value for this variable.     * @exception ClassCastException An attempt has been made to cast an object to a subclass of which      * it is not an instance.     */    final public SnmpStringFixed getSnmpStringFixedValue() throws ClassCastException {        return (SnmpStringFixed)this.value ;    }      /**     * Sets the <CODE>SnmpStringFixed</CODE> value part associated with this <CODE>SnmpVarBind</CODE>      * with the specified string value.     * The status is updated to indicate that the value is valid.     * @param val The new string value.     * @see SnmpStringFixed     */    final public void setSnmpStringFixedValue(String val) {        clearValue() ;        this.value = new SnmpStringFixed(val) ;        setValueValid() ;    }            // PUBLIC METHODS    //---------------    /**     * Consults the MIB table storage to resolve the name to its OID type structure.     * @param name The MIB variable name or a dot-formatted OID <CODE>String</CODE>.     * @return The <CODE>SnmpOidRecord</CODE> object containing information on the MIB variable.     * @exception SnmpStatusException An error occurred while resolving the MIB variable name.     */    public SnmpOidRecord resolveVarName(String name) throws SnmpStatusException {                SnmpOidTable mibTable = oid.getSnmpOidTable();        if (mibTable == null)            throw new SnmpStatusException(SnmpStatusException.noSuchName);        int index = name.indexOf('.');        if (index < 0) {            return mibTable.resolveVarName(name);        } else {            return mibTable.resolveVarOid(name);        }    }        /**     * Returns the status of the value associated with this <CODE>SnmpVarBind</CODE> as an integer.     * This value is one of {@link #stValueUnspecified}, {@link #stValueOk}, {@link #stValueNoSuchObject},     * {@link #stValueNoSuchInstance}, {@link #stValueEndOfMibView}.     * @return The status of the associated value.     */    final public int getValueStatus() {        return status ;    }    /**     * Returns the status of the value associated with this <CODE>SnmpVarBind</CODE> as a <CODE>String</CODE>.     * This value is a displayable representation of the status integer value.     * It is one of <CODE>Value not initialized</CODE>, <CODE>Valid Value</CODE>, <CODE>No such object</CODE>,     * <CODE>No such Instance</CODE>, <CODE>End of Mib View</CODE>.     * @return The status of the associated value.     */    final public String getValueStatusLegend() {        return statusLegend[status] ;    }        /**     * Checks whether the object contains a valid accessible value.     * @return <CODE>true</CODE> if the associated value is valid, <CODE>false</CODE> otherwise.     */    final public boolean isValidValue() {        return (status == stValueOk) ;    }    /**     * Checks whether the value associated with this <CODE>SnmpVarBind</CODE> is unspecified.     * @return <CODE>true</CODE> if the status is unspecified, <CODE>false</CODE> otherwise.     */    final public boolean isUnspecifiedValue() {        return (status == stValueUnspecified) ;    }    /**     * Clears the value associated with this <CODE>SnmpVarBind</CODE> and sets the status to      * <CODE>stValueUnspecified</CODE>.     */    final public void clearValue() {        this.value = null ;        status = stValueUnspecified ;    }        /**     * Checks whether the OID for this variable completely matches the OID part of the specified      * <CODE>SnmpVarBind</CODE> object.     * @param var The object whose OID part is to be matched.     * @return <CODE>true</CODE> if the OID part matches exactly, <CODE>false</CODE> otherwise.     */    final public boolean isOidEqual(SnmpVarBind var) {        return this.oid.equals(var.oid) ;    }    /**     * Adds an instance part to the OID in the <CODE>SnmpOid</CODE> object.     * Note that there is no <CODE>getInstance</CODE> method.      * This method will directly add the instance to the <CODE>SnmpOid</CODE> object.     * @param inst The sub-identifier to be appended to the OID.     */    final public void addInstance(long inst) {        oid.append(inst) ;        return ;    }    /**     * Adds an instance part to the OID in the <CODE>SnmpOid</CODE> object.     * Note that there is no <CODE>getInstance</CODE> method.      * This method will directly add the instance to the <CODE>SnmpOid</CODE> object.     * @param inst The sub-identifier array to be appended to the OID.     * @exception SnmpStatusException An error occurred while accessing a MIB node.     */    final public void addInstance(long[] inst) throws SnmpStatusException {        oid.addToOid(inst) ;        return ;    }    /**     * Adds an instance part to the OID in the <CODE>SnmpOid</CODE> object.     * Note that there is no <CODE>getInstance</CODE> method.      * This method will directly add the instance to the <CODE>SnmpOid</CODE> object.     * @param inst Dot-formatted sub-identifier <CODE>String</CODE> to be appended to the OID.     * @exception SnmpStatusException An error occurred while accessing a MIB node.     */    final public void addInstance(String inst) throws SnmpStatusException {        if (inst != null) {            oid.addToOid(inst) ;        }        return ;    }    /**     * Inserts a sub-id at the beginning of the OID of this <CODE>SnmpVarBind</CODE>.     * @param oid The sub-id to insert.     */    public void insertInOid(int oid) {        this.oid.insert(oid) ;    }    /**     * Appends the specified <CODE>SnmpOid</CODE> to the end of the OID of this <CODE>SnmpVarBind</CODE>.     * @param oid The OID to append.     */    public void appendInOid(SnmpOid oid) {        this.oid.append(oid) ;    }        /**     * Determines whether the <CODE>SnmpVarBind</CODE> has an SNMP exception      * (generated by agent in response to a request).     * @return <CODE>true</CODE> if the <CODE>SnmpVarBind</CODE> has an SNMP response exception,      * <CODE>false</CODE> otherwise.     */    final public synchronized boolean hasVarBindException() {        switch (status) {        case  stValueUnspecified :        case  stValueNoSuchObject :        case  stValueNoSuchInstance :        case  stValueEndOfMibView :            return true ;        }        return false ;    }    /**     * Clones and copies the OID and value part from another <CODE>SnmpVarBind</CODE> object.     * @param var The <CODE>SnmpVarBind</CODE> clone.     */    public void copyValueAndOid(SnmpVarBind var) {        setOid((SnmpOid) (var.oid.clone())) ;        copyValue(var) ;    }    /**     * Clones and copies only the value part from another <CODE>SnmpVarBind</CODE> object.     * @param var The <CODE>SnmpVarBind</CODE> clone.     */    public void copyValue(SnmpVarBind var) {        if (var.isValidValue()) {            this.value = var.getSnmpValue().duplicate() ;            setValueValid() ;        } else {            status = var.getValueStatus() ;	    if (status == stValueEndOfMibView)        value=endOfMibView;	    else if (status == stValueNoSuchObject)   value=noSuchObject;	    else if (status == stValueNoSuchInstance) value=noSuchInstance;        }    }    /**     * Clones the SNMP variable. It does not clone the value portion.     * @return A new object with the value part set to null.     */    public Object cloneWithoutValue() {        SnmpOid noid = (SnmpOid)this.oid.clone() ;        return new SnmpVarBind(noid) ;    }    /**     * Clones the SNMP variable (including value).     * @return The SNMP variable clone.     */    public Object clone() { //         SnmpVarBind v = null ;//         try {//             v = (SnmpVarBind) super.clone() ;//             v.copyValueAndOid(this) ;//         } catch (CloneNotSupportedException e) {//             throw new InternalError() ;//         }//         return v ;        SnmpVarBind v = new SnmpVarBind() ;        v.copyValueAndOid(this) ;        return v ;    }    /**     * Returns the printable ASCII representation for the corresponding variable value.     * @return The printable ASCII representation.     */    final public String getStringValue() {        return this.value.toString() ;    }    /**     * Set the value to {@link #noSuchObject}. This is equivalent to     * <code>setSnmpValue(SnmpVarBind.noSuchObject)</code>.     **/    final public void setNoSuchObject() {	value=noSuchObject;	status=stValueNoSuchObject;    }    /**     * Set the value to {@link #noSuchInstance}. This is equivalent to     * <code>setSnmpValue(SnmpVarBind.noSuchInstance)</code>.     **/    final public void setNoSuchInstance() {	value=noSuchInstance;	status=stValueNoSuchInstance;    }    /**     * Set the value to {@link #endOfMibView}. This is equivalent to     * <code>setSnmpValue(SnmpVarBind.endOfMibView)</code>.     **/    final public void setEndOfMibView() {	value=endOfMibView;	status=stValueEndOfMibView;    }     /**     * Returns the printable ASCII representation of this <CODE>SnmpVarBind</CODE>.     * @return The printable ASCII representation.     */    final public String toString() {        StringBuffer s = new StringBuffer(400) ;        s.append("Object ID : " + this.oid.toString()) ;         if (isValidValue()) {            s.append("  (Syntax : " + this.value.getTypeName() + ")\n") ;            s.append("Value : " + this.value.toString()) ;        } else {            s.append("\n" + "Value Exception : " + getValueStatusLegend()) ;        }        return s.toString() ;    }        // PRIVATE METHODS    //----------------        /**     * Sets the status to indicate that the value for this <CODE>SnmpVarBind</CODE> is valid.     */    private void setValueValid() {	if (value == endOfMibView)        status=stValueEndOfMibView;	else if (value == noSuchObject)   status=stValueNoSuchObject;	else if (value == noSuchInstance) status=stValueNoSuchInstance;        else status = stValueOk ;    }    private void handleLong(String oid, int index) throws NumberFormatException, SnmpStatusException {        String str;        if (index >0) {            str= oid.substring(0, index);        } else {            str= oid ;        }        // just parse the element.        //        Long.parseLong(str);    }   }

⌨️ 快捷键说明

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