001: /*
002: * SNMP Package
003: *
004: * Copyright (C) 2004, Jonathan Sevy <jsevy@mcs.drexel.edu>
005: *
006: * This is free software. Redistribution and use in source and binary forms, with
007: * or without modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright notice, this
011: * list of conditions and the following disclaimer.
012: * 2. Redistributions in binary form must reproduce the above copyright notice,
013: * this list of conditions and the following disclaimer in the documentation
014: * and/or other materials provided with the distribution.
015: * 3. The name of the author may not be used to endorse or promote products
016: * derived from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
019: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
021: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
023: * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
024: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
025: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
026: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: */
029:
030: package snmp;
031:
032: /**
033: * Abstract base class of all SNMP data type classes.
034: */
035:
036: public abstract class SNMPObject {
037:
038: /**
039: * Must return a Java object appropriate to represent the value/data contained
040: * in the SNMP object
041: */
042:
043: public abstract Object getValue();
044:
045: /**
046: * Must set the value of the SNMP object when supplied with an appropriate
047: * Java object containing an appropriate value.
048: */
049:
050: public abstract void setValue(Object o)
051: throws SNMPBadValueException;
052:
053: /**
054: * Should return an appropriate human-readable representation of the stored value.
055: */
056:
057: public abstract String toString();
058:
059: /**
060: * Must return the BER byte encoding (type, length, value) of the SNMP object.
061: */
062:
063: protected abstract byte[] getBEREncoding();
064:
065: /**
066: * Compares two SNMPObject subclass objects by checking their values for equality.
067: */
068:
069: public boolean equals(Object other) {
070: // false if other is null
071: if (other == null) {
072: return false;
073: }
074:
075: // check first to see that they're both of the same class
076: if (!this .getClass().equals(other.getClass())) {
077: return false;
078: }
079:
080: SNMPObject otherSNMPObject = (SNMPObject) other;
081:
082: // now see if their embedded values are equal
083: if (this .getValue().equals(otherSNMPObject.getValue())) {
084: return true;
085: } else {
086: return false;
087: }
088: }
089:
090: /**
091: * Generates a hash value so SNMP objects can be used in Hashtables.
092: */
093:
094: public int hashCode() {
095: // just use hashcode value of embedded value by default
096: if (this .getValue() != null) {
097: return this .getValue().hashCode();
098: } else {
099: return 0;
100: }
101: }
102:
103: }
|