KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > smi > Null


1 /*_############################################################################
2   _##
3   _## SNMP4J - Null.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

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 /**
29  * The <code>Null</code> class represents SMI Null and the derived
30  * SMIv2 exception syntaxes.
31  *
32  * @author Frank Fock
33  * @version 1.8
34  */

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 JavaDoc {
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 JavaDoc o) {
76     if (o instanceof Null) {
77       return (((Null) o).getSyntax() == getSyntax());
78     }
79     return false;
80   }
81
82   public int compareTo(Object JavaDoc o) {
83     return (getSyntax() - ((Null)o).getSyntax());
84   }
85
86   public String JavaDoc 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 JavaDoc {
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 JavaDoc("Syntax " + syntax +
105                                          " is incompatible with Null type");
106     }
107     this.syntax = syntax;
108   }
109
110   public Object JavaDoc 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   /**
125    * Returns the syntax of this Null variable.
126    * @return
127    * {@link SMIConstants#SYNTAX_NULL} or one of the exception syntaxes
128    * {@link SMIConstants#EXCEPTION_NO_SUCH_OBJECT},
129    * {@link SMIConstants#EXCEPTION_NO_SUCH_INSTANCE}, or
130    * {@link SMIConstants#EXCEPTION_END_OF_MIB_VIEW}
131    * @since 1.7
132    */

133   public final int toInt() {
134     return getSyntax();
135   }
136
137   /**
138    * Returns the syntax of this Null variable.
139    * @return
140    * {@link SMIConstants#SYNTAX_NULL} or one of the exception syntaxes
141    * {@link SMIConstants#EXCEPTION_NO_SUCH_OBJECT},
142    * {@link SMIConstants#EXCEPTION_NO_SUCH_INSTANCE}, or
143    * {@link SMIConstants#EXCEPTION_END_OF_MIB_VIEW}
144    * @since 1.7
145    */

146   public final long toLong() {
147     return getSyntax();
148   }
149
150   public OID toSubIndex(boolean impliedLength) {
151     throw new UnsupportedOperationException JavaDoc();
152   }
153
154   public void fromSubIndex(OID subIndex, boolean impliedLength) {
155     throw new UnsupportedOperationException JavaDoc();
156   }
157 }
158
159
Popular Tags