KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > mp > StateReference


1 /*_############################################################################
2   _##
3   _## SNMP4J - StateReference.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.mp;
22
23 import java.util.*;
24
25 import org.snmp4j.*;
26 import org.snmp4j.security.*;
27 import org.snmp4j.smi.*;
28 import java.io.Serializable JavaDoc;
29
30
31 /**
32  * The <code>StateReference</code> class represents state information associated
33  * with SNMP messages. The state reference is used to send response or report
34  * (SNMPv3 only). Depending on the security model not all fields may be filled.
35  *
36  * @author Frank Fock
37  * @version 1.2
38  */

39 public class StateReference implements Serializable JavaDoc {
40
41   private static final long serialVersionUID = 7385215386971310699L;
42
43   private Address address;
44   private transient TransportMapping transportMapping;
45   private byte[] contextEngineID;
46   private byte[] contextName;
47   private SecurityModel securityModel;
48   private byte[] securityName;
49   private int securityLevel;
50   private SecurityStateReference securityStateReference;
51   private int msgID;
52   private int maxSizeResponseScopedPDU;
53   private int msgFlags;
54   private PduHandle pduHandle;
55   private byte[] securityEngineID;
56   private int errorCode = 0;
57
58   /**
59    * Default constructor.
60    */

61   public StateReference() {
62   }
63
64   /**
65    * Creates a state reference for community based security models.
66    * @param pduHandle PduHandle
67    * @param peerAddress Address
68    * @param peerTransport
69    * the <code>TransportMapping</code> to be used to communicate with the
70    * peer.
71    * @param secModel SecurityModel
72    * @param secName
73    * a community string.
74    * @param errorCode
75    * an error code associated with the SNMP message.
76    */

77   public StateReference(PduHandle pduHandle,
78                         Address peerAddress,
79                         TransportMapping peerTransport,
80                         SecurityModel secModel,
81                         byte[] secName,
82                         int errorCode) {
83     this(0, 0, 65535, pduHandle, peerAddress, peerTransport,
84          null, secModel, secName,
85          SecurityLevel.NOAUTH_NOPRIV, null, null, null, errorCode);
86   }
87
88   /**
89    * Creates a state reference for SNMPv3 messages.
90    * @param msgID int
91    * @param msgFlags int
92    * @param maxSizeResponseScopedPDU int
93    * @param pduHandle PduHandle
94    * @param peerAddress Address
95    * @param peerTransport
96    * the <code>TransportMapping</code> to be used to communicate with the
97    * peer.
98    * @param secEngineID byte[]
99    * @param secModel SecurityModel
100    * @param secName byte[]
101    * @param secLevel int
102    * @param contextEngineID byte[]
103    * @param contextName byte[]
104    * @param secStateReference SecurityStateReference
105    * @param errorCode int
106    */

107   public StateReference(int msgID,
108                         int msgFlags,
109                         int maxSizeResponseScopedPDU,
110                         PduHandle pduHandle,
111                         Address peerAddress,
112                         TransportMapping peerTransport,
113                         byte[] secEngineID,
114                         SecurityModel secModel,
115                         byte[] secName,
116                         int secLevel,
117                         byte[] contextEngineID,
118                         byte[] contextName,
119                         SecurityStateReference secStateReference,
120                         int errorCode) {
121     this.msgID = msgID;
122     this.msgFlags = msgFlags;
123     this.maxSizeResponseScopedPDU = maxSizeResponseScopedPDU;
124     this.pduHandle = pduHandle;
125     this.address = peerAddress;
126     this.transportMapping = peerTransport;
127     this.securityEngineID = secEngineID;
128     this.securityModel = secModel;
129     this.securityName = secName;
130     this.securityLevel = secLevel;
131     this.contextEngineID = contextEngineID;
132     this.contextName = contextName;
133     this.securityStateReference = secStateReference;
134     this.errorCode = errorCode;
135   }
136
137   public boolean isReportable() {
138     return ((msgFlags & 0x04) > 0);
139   }
140
141   public Address getAddress() {
142     return address;
143   }
144   public void setAddress(org.snmp4j.smi.Address address) {
145     this.address = address;
146   }
147   public void setContextEngineID(byte[] contextEngineID) {
148     this.contextEngineID = contextEngineID;
149   }
150   public byte[] getContextEngineID() {
151     return contextEngineID;
152   }
153   public void setContextName(byte[] contextName) {
154     this.contextName = contextName;
155   }
156   public byte[] getContextName() {
157     return contextName;
158   }
159   public void setSecurityModel(SecurityModel securityModel) {
160     this.securityModel = securityModel;
161   }
162   public SecurityModel getSecurityModel() {
163     return securityModel;
164   }
165   public void setSecurityName(byte[] securityName) {
166     this.securityName = securityName;
167   }
168   public byte[] getSecurityName() {
169     return securityName;
170   }
171   public void setSecurityLevel(int securityLevel) {
172     this.securityLevel = securityLevel;
173   }
174   public int getSecurityLevel() {
175     return securityLevel;
176   }
177   public void setSecurityStateReference(SecurityStateReference securityStateReference) {
178     this.securityStateReference = securityStateReference;
179   }
180   public SecurityStateReference getSecurityStateReference() {
181     return securityStateReference;
182   }
183   public void setMsgID(int msgID) {
184     this.msgID = msgID;
185   }
186   public int getMsgID() {
187     return msgID;
188   }
189   public void setMsgFlags(int msgFlags) {
190     this.msgFlags = msgFlags;
191   }
192   public int getMsgFlags() {
193     return msgFlags;
194   }
195   public void setMaxSizeResponseScopedPDU(int maxSizeResponseScopedPDU) {
196     this.maxSizeResponseScopedPDU = maxSizeResponseScopedPDU;
197   }
198   public int getMaxSizeResponseScopedPDU() {
199     return maxSizeResponseScopedPDU;
200   }
201   public PduHandle getPduHandle() {
202     return pduHandle;
203   }
204
205   public byte[] getSecurityEngineID() {
206     return securityEngineID;
207   }
208
209   public int getErrorCode() {
210     return errorCode;
211   }
212
213   public TransportMapping getTransportMapping() {
214     return transportMapping;
215   }
216
217   public void setPduHandle(PduHandle pduHandle) {
218     this.pduHandle = pduHandle;
219   }
220
221   public void setSecurityEngineID(byte[] securityEngineID) {
222     this.securityEngineID = securityEngineID;
223   }
224
225   public void setErrorCode(int errorCode) {
226     this.errorCode = errorCode;
227   }
228
229   public void setTransportMapping(TransportMapping transportMapping) {
230     this.transportMapping = transportMapping;
231   }
232
233   public boolean equals(Object JavaDoc o) {
234     if (o instanceof StateReference) {
235       StateReference other = (StateReference) o;
236       return ((msgID == other.msgID) &&
237               ((pduHandle == null) && (other.pduHandle == null)) ||
238                (pduHandle != null) && (pduHandle.equals(other.getPduHandle())) &&
239               (Arrays.equals(securityEngineID, other.securityEngineID)) &&
240               (securityModel.equals(other.securityModel)) &&
241               (Arrays.equals(securityName, other.securityName)) &&
242               (securityLevel == other.securityLevel) &&
243               (Arrays.equals(contextEngineID, other.contextEngineID)) &&
244               (Arrays.equals(contextName, other.contextName)));
245     }
246     return false;
247   }
248
249   public int hashCode() {
250     return msgID;
251   }
252
253   public String JavaDoc toString() {
254     return "StateReference[msgID="+msgID+",pduHandle="+pduHandle+
255         ",securityEngineID="+OctetString.fromByteArray(securityEngineID)+
256         ",securityModel="+securityModel+
257         ",securityName="+OctetString.fromByteArray(securityName)+
258         ",securityLevel="+securityLevel+
259         ",contextEngineID="+OctetString.fromByteArray(contextEngineID)+
260         ",contextName="+OctetString.fromByteArray(contextName)+"]";
261   }
262 }
263
Popular Tags