1. /*
  2. * @(#)file SnmpNull.java
  3. * @(#)author Sun Microsystems, Inc.
  4. * @(#)version 4.9
  5. * @(#)date 04/09/15
  6. *
  7. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  8. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  9. *
  10. */
  11. package com.sun.jmx.snmp;
  12. /**
  13. * Represents an SNMP null value.
  14. * <p><b>This API is a Sun Microsystems internal API and is subject
  15. * to change without notice.</b></p>
  16. */
  17. public class SnmpNull extends SnmpValue {
  18. // CONSTRUCTORS
  19. //-------------
  20. /**
  21. * Constructs a new <CODE>SnmpNull</CODE>.
  22. */
  23. public SnmpNull() {
  24. tag = NullTag ;
  25. }
  26. /**
  27. * Constructs a new <CODE>SnmpNull</CODE>.
  28. * <BR>For mibgen private use only.
  29. */
  30. public SnmpNull(String dummy) {
  31. this();
  32. }
  33. /**
  34. * Constructs a new <CODE>SnmpNull</CODE> from the specified tag value.
  35. * @param t The initialization value.
  36. */
  37. public SnmpNull(int t) {
  38. tag = t ;
  39. }
  40. // PUBLIC METHODS
  41. //---------------
  42. /**
  43. * Returns the tag value of this <CODE>SnmpNull</CODE>.
  44. * @return The value.
  45. */
  46. public int getTag() {
  47. return tag ;
  48. }
  49. /**
  50. * Converts the <CODE>NULL</CODE> value to its ASN.1 <CODE>String</CODE> form.
  51. * When the tag is not the universal one, it is preprended
  52. * to the <CODE>String</CODE> form.
  53. * @return The <CODE>String</CODE> representation of the value.
  54. */
  55. public String toString() {
  56. String result = "" ;
  57. if (tag != 5) {
  58. result += "[" + tag + "] " ;
  59. }
  60. result += "NULL" ;
  61. switch(tag) {
  62. case errNoSuchObjectTag :
  63. result += " (noSuchObject)" ;
  64. break ;
  65. case errNoSuchInstanceTag :
  66. result += " (noSuchInstance)" ;
  67. break ;
  68. case errEndOfMibViewTag :
  69. result += " (endOfMibView)" ;
  70. break ;
  71. }
  72. return result ;
  73. }
  74. /**
  75. * Converts the <CODE>NULL</CODE> value to its <CODE>SnmpOid</CODE> form.
  76. * Normally, a <CODE>NULL</CODE> value cannot be used as an index value,
  77. * this method triggers an exception.
  78. * @return The OID representation of the value.
  79. */
  80. public SnmpOid toOid() {
  81. throw new IllegalArgumentException() ;
  82. }
  83. /**
  84. * Performs a clone action. This provides a workaround for the
  85. * <CODE>SnmpValue</CODE> interface.
  86. * @return The SnmpValue clone.
  87. */
  88. final synchronized public SnmpValue duplicate() {
  89. return (SnmpValue) clone() ;
  90. }
  91. /**
  92. * Clones the <CODE>SnmpNull</CODE> object, making a copy of its data.
  93. * @return The object clone.
  94. */
  95. final synchronized public Object clone() {
  96. SnmpNull newclone = null ;
  97. try {
  98. newclone = (SnmpNull) super.clone() ;
  99. newclone.tag = tag ;
  100. } catch (CloneNotSupportedException e) {
  101. throw new InternalError() ; // vm bug.
  102. }
  103. return newclone ;
  104. }
  105. /**
  106. * Returns a textual description of the type object.
  107. * @return ASN.1 textual description.
  108. */
  109. final public String getTypeName() {
  110. return name ;
  111. }
  112. /**
  113. * Checks if this <CODE>SnmpNull</CODE> object corresponds to a <CODE>noSuchObject</CODE> value.
  114. * @return <CODE>true</CODE> if the tag equals {@link com.sun.jmx.snmp.SnmpDataTypeEnums#errNoSuchObjectTag},
  115. * <CODE>false</CODE> otherwise.
  116. */
  117. public boolean isNoSuchObjectValue() {
  118. return (tag == SnmpDataTypeEnums.errNoSuchObjectTag);
  119. }
  120. /**
  121. * Checks if this <CODE>SnmpNull</CODE> object corresponds to a <CODE>noSuchInstance</CODE> value.
  122. * @return <CODE>true</CODE> if the tag equals {@link com.sun.jmx.snmp.SnmpDataTypeEnums#errNoSuchInstanceTag},
  123. * <CODE>false</CODE> otherwise.
  124. */
  125. public boolean isNoSuchInstanceValue() {
  126. return (tag == SnmpDataTypeEnums.errNoSuchInstanceTag);
  127. }
  128. /**
  129. * Checks if this <CODE>SnmpNull</CODE> object corresponds to an <CODE>endOfMibView</CODE> value.
  130. * @return <CODE>true</CODE> if the tag equals {@link com.sun.jmx.snmp.SnmpDataTypeEnums#errEndOfMibViewTag},
  131. * <CODE>false</CODE> otherwise.
  132. */
  133. public boolean isEndOfMibViewValue() {
  134. return (tag == SnmpDataTypeEnums.errEndOfMibViewTag);
  135. }
  136. // VARIABLES
  137. //----------
  138. /**
  139. * Name of the type.
  140. */
  141. final static String name = "Null" ;
  142. /**
  143. * This is the tag of the NULL value. By default, it is the universal tag value.
  144. */
  145. private int tag = 5 ;
  146. }