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: * Object representing the SNMP Null data type.
034: */
035:
036: public class SNMPNull extends SNMPObject {
037:
038: protected byte tag = SNMPBERCodec.SNMPNULL;
039:
040: /**
041: * Returns Java null reference.
042: */
043:
044: public Object getValue() {
045: return null;
046: }
047:
048: /**
049: * Always throws SNMPBadValueException (which null value did you want, anyway?)
050: */
051:
052: public void setValue(Object o) throws SNMPBadValueException {
053: throw new SNMPBadValueException(" Null: attempt to set value ");
054: }
055:
056: /**
057: * Return BER encoding for a null object: two bytes, tag and length of 0.
058: */
059:
060: protected byte[] getBEREncoding() {
061: byte[] encoding = new byte[2];
062:
063: // set tag byte
064: encoding[0] = SNMPBERCodec.SNMPNULL;
065:
066: // len = 0 since no payload!
067: encoding[1] = 0;
068:
069: // no V!
070:
071: return encoding;
072: }
073:
074: /**
075: * Checks just that both are instances of SNMPNull (no embedded value to check).
076: */
077:
078: public boolean equals(Object other) {
079: // false if other is null
080: if (other == null) {
081: return false;
082: }
083:
084: // check that they're both of the same class
085: if (this .getClass().equals(other.getClass())) {
086: return true;
087: } else {
088: return false;
089: }
090: }
091:
092: /**
093: * Returns String "Null"..
094: */
095:
096: public String toString() {
097: return new String("Null");
098: }
099:
100: }
|