1 20 21 package org.snmp4j.smi; 22 23 import java.io.*; 24 import org.snmp4j.asn1.BER; 25 import org.snmp4j.asn1.BERInputStream; 26 import org.snmp4j.asn1.BER.MutableByte; 27 28 35 public class Null extends AbstractVariable { 36 37 private static final long serialVersionUID = 6907924131098190092L; 38 39 private int syntax = SMIConstants.SYNTAX_NULL; 40 41 public static final Null noSuchObject = 42 new Null(SMIConstants.EXCEPTION_NO_SUCH_OBJECT); 43 public static final Null noSuchInstance = 44 new Null(SMIConstants.EXCEPTION_NO_SUCH_INSTANCE); 45 public static final Null endOfMibView = 46 new Null(SMIConstants.EXCEPTION_END_OF_MIB_VIEW); 47 public static final Null instance = 48 new Null(SMIConstants.SYNTAX_NULL); 49 50 public Null() { 51 } 52 53 public Null(int exceptionSyntax) { 54 setSyntax(exceptionSyntax); 55 } 56 57 public void decodeBER(BERInputStream inputStream) throws java.io.IOException { 58 MutableByte type = new BER.MutableByte(); 59 BER.decodeNull(inputStream, type); 60 this.syntax = type.getValue() & 0xFF; 61 } 62 63 public int getSyntax() { 64 return syntax; 65 } 66 67 public int hashCode() { 68 return getSyntax(); 69 } 70 71 public int getBERLength() { 72 return 2; 73 } 74 75 public boolean equals(Object o) { 76 if (o instanceof Null) { 77 return (((Null) o).getSyntax() == getSyntax()); 78 } 79 return false; 80 } 81 82 public int compareTo(Object o) { 83 return (getSyntax() - ((Null)o).getSyntax()); 84 } 85 86 public String toString() { 87 switch (getSyntax()) { 88 case SMIConstants.EXCEPTION_NO_SUCH_OBJECT: 89 return "noSuchObject"; 90 case SMIConstants.EXCEPTION_NO_SUCH_INSTANCE: 91 return "noSuchInstance"; 92 case SMIConstants.EXCEPTION_END_OF_MIB_VIEW: 93 return "endOfMibView"; 94 } 95 return "Null"; 96 } 97 98 public void encodeBER(OutputStream outputStream) throws java.io.IOException { 99 BER.encodeHeader(outputStream, (byte)getSyntax(), 0); 100 } 101 102 public void setSyntax(int syntax) { 103 if ((syntax != SMIConstants.SYNTAX_NULL) && (!isExceptionSyntax(syntax))) { 104 throw new IllegalArgumentException ("Syntax " + syntax + 105 " is incompatible with Null type"); 106 } 107 this.syntax = syntax; 108 } 109 110 public Object clone() { 111 return new Null(this.syntax); 112 } 113 114 public static boolean isExceptionSyntax(int syntax) { 115 switch (syntax) { 116 case SMIConstants.EXCEPTION_NO_SUCH_OBJECT: 117 case SMIConstants.EXCEPTION_NO_SUCH_INSTANCE: 118 case SMIConstants.EXCEPTION_END_OF_MIB_VIEW: 119 return true; 120 } 121 return false; 122 } 123 124 133 public final int toInt() { 134 return getSyntax(); 135 } 136 137 146 public final long toLong() { 147 return getSyntax(); 148 } 149 150 public OID toSubIndex(boolean impliedLength) { 151 throw new UnsupportedOperationException (); 152 } 153 154 public void fromSubIndex(OID subIndex, boolean impliedLength) { 155 throw new UnsupportedOperationException (); 156 } 157 } 158 159 | Popular Tags |