KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > agent > SnmpMibRequestImpl


1 /*
2  * @(#)file SnmpMibRequestImpl.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 1.14
5  * @(#)date 08/02/09
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.agent;
12
13 import java.util.Enumeration JavaDoc;
14 import java.util.Vector JavaDoc;
15
16
17 import com.sun.jmx.snmp.SnmpPdu;
18 import com.sun.jmx.snmp.SnmpVarBind;
19 import com.sun.jmx.snmp.SnmpEngine;
20
21 /**
22  * This class implements the SnmpMibRequest interface.
23  * It represents the part of a SNMP request that involves a specific
24  * MIB. One instance of this class will be created for every MIB
25  * involved in a SNMP request, and will be passed to the SnmpMibAgent
26  * in charge of handling that MIB.
27  *
28  * Instances of this class are allocated by the SNMP engine. You will
29  * never need to use this class directly. You will only access
30  * instances of this class through their SnmpMibRequest interface.
31  *
32  */

33 final class SnmpMibRequestImpl implements SnmpMibRequest {
34
35     /**
36      * @param engine The local engine.
37      * @param reqPdu The received pdu.
38      * @param vblist The vector of SnmpVarBind objects in which the
39      * MIB concerned by this request is involved.
40      * @param protocolVersion The protocol version of the SNMP request.
41      * @param userData User allocated contextual data. This object must
42      * be allocated on a per SNMP request basis through the
43      * SnmpUserDataFactory registered with the SnmpAdaptorServer,
44      * and is handed back to the user through SnmpMibRequest objects.
45      */

46     public SnmpMibRequestImpl(SnmpEngine engine,
47                   SnmpPdu reqPdu,
48                   Vector JavaDoc vblist,
49                   int protocolVersion,
50                   Object JavaDoc userData,
51                   String JavaDoc principal,
52                   int securityLevel,
53                   int securityModel,
54                   byte[] contextName,
55                   byte[] accessContextName) {
56     varbinds = vblist;
57     version = protocolVersion;
58     data = userData;
59     this.reqPdu = reqPdu;
60     this.engine = engine;
61     this.principal = principal;
62     this.securityLevel = securityLevel;
63     this.securityModel = securityModel;
64     this.contextName = contextName;
65     this.accessContextName = accessContextName;
66     }
67     // -------------------------------------------------------------------
68
// PUBLIC METHODS from SnmpMibRequest
69
// -------------------------------------------------------------------
70

71     /**
72      * Returns the local engine. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
73      * @return the local engine.
74      */

75     public SnmpEngine getEngine() {
76     return engine;
77     }
78     
79     /**
80      * Gets the incoming request principal. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
81      * @return The request principal.
82      **/

83     public String JavaDoc getPrincipal() {
84     return principal;
85     }
86     
87     /**
88      * Gets the incoming request security level. This level is defined in {@link com.sun.jmx.snmp.SnmpEngine SnmpEngine}. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise -1 is returned.
89      * @return The security level.
90      */

91     public int getSecurityLevel() {
92     return securityLevel;
93     }
94     /**
95      * Gets the incoming request security model. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise -1 is returned.
96      * @return The security model.
97      */

98     public int getSecurityModel() {
99     return securityModel;
100     }
101     /**
102      * Gets the incoming request context name. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
103      * @return The context name.
104      */

105     public byte[] getContextName() {
106     return contextName;
107     }
108     
109     /**
110      * Gets the incoming request context name used by Access Control Model in order to allow or deny the access to OIDs. This parameter is returned only if <CODE> SnmpV3AdaptorServer </CODE> is the adaptor receiving this request. Otherwise null is returned.
111      * @return The checked context.
112      */

113     public byte[] getAccessContextName() {
114     return accessContextName;
115     }
116     
117     // -------------------------------------------------------------------
118
// Implements the method defined in SnmpMibRequest interface.
119
// See SnmpMibRequest for the java doc.
120
// -------------------------------------------------------------------
121
public final SnmpPdu getPdu() {
122     return reqPdu;
123     }
124
125     // -------------------------------------------------------------------
126
// Implements the method defined in SnmpMibRequest interface.
127
// See SnmpMibRequest for the java doc.
128
// -------------------------------------------------------------------
129
public final Enumeration JavaDoc getElements() {return varbinds.elements();}
130
131     // -------------------------------------------------------------------
132
// Implements the method defined in SnmpMibRequest interface.
133
// See SnmpMibRequest for the java doc.
134
// -------------------------------------------------------------------
135
public final Vector JavaDoc getSubList() {return varbinds;}
136
137     // -------------------------------------------------------------------
138
// Implements the method defined in SnmpMibRequest interface.
139
// See SnmpMibRequest for the java doc.
140
// -------------------------------------------------------------------
141
public final int getSize() {
142     if (varbinds == null) return 0;
143     return varbinds.size();
144     }
145
146     // -------------------------------------------------------------------
147
// Implements the method defined in SnmpMibRequest interface.
148
// See SnmpMibRequest for the java doc.
149
// -------------------------------------------------------------------
150
public final int getVersion() {return version;}
151
152     // -------------------------------------------------------------------
153
// Implements the method defined in SnmpMibRequest interface.
154
// See SnmpMibRequest for the java doc.
155
// -------------------------------------------------------------------
156
public final int getRequestPduVersion() {return reqPdu.version;}
157
158     // -------------------------------------------------------------------
159
// Implements the method defined in SnmpMibRequest interface.
160
// See SnmpMibRequest for the java doc.
161
// -------------------------------------------------------------------
162
public final Object JavaDoc getUserData() {return data;}
163
164     // -------------------------------------------------------------------
165
// Implements the method defined in SnmpMibRequest interface.
166
// See SnmpMibRequest for the java doc.
167
// -------------------------------------------------------------------
168
public final int getVarIndex(SnmpVarBind varbind) {
169     return varbinds.indexOf(varbind);
170     }
171
172     // -------------------------------------------------------------------
173
// Implements the method defined in SnmpMibRequest interface.
174
// See SnmpMibRequest for the java doc.
175
// -------------------------------------------------------------------
176
public void addVarBind(SnmpVarBind varbind) {
177     varbinds.addElement(varbind);
178     }
179
180     // -------------------------------------------------------------------
181
// PACKAGE METHODS
182
// -------------------------------------------------------------------
183

184     // -------------------------------------------------------------------
185
// Allow to pass the request tree built during the check() phase
186
// to the set() method. Note: the if the tree is `null', then the
187
// set() method will rebuild a new tree identical to the tree built
188
// in the check() method.
189
//
190
// Passing this tree in the SnmpMibRequestImpl object allows to
191
// optimize the SET requests.
192
//
193
// -------------------------------------------------------------------
194
final void setRequestTree(SnmpRequestTree tree) {this.tree = tree;}
195
196     // -------------------------------------------------------------------
197
// Returns the SnmpRequestTree object built in the first operation
198
// phase for two-phase SNMP requests (like SET).
199
// -------------------------------------------------------------------
200
final SnmpRequestTree getRequestTree() {return tree;}
201
202     // -------------------------------------------------------------------
203
// Returns the underlying vector of SNMP varbinds (used for algorithm
204
// optimization).
205
// -------------------------------------------------------------------
206
final Vector JavaDoc getVarbinds() {return varbinds;}
207  
208     // -------------------------------------------------------------------
209
// Private variables
210
// -------------------------------------------------------------------
211

212     // Ideally these variables should be declared final but it makes
213
// the jdk1.1.x compiler complain (seems to be a compiler bug, jdk1.2
214
// is OK).
215
private Vector JavaDoc varbinds;
216     private int version;
217     private Object JavaDoc data;
218     private SnmpPdu reqPdu = null;
219     // Non final variable.
220
private SnmpRequestTree tree = null;
221     private SnmpEngine engine = null;
222     private String JavaDoc principal = null;
223     private int securityLevel = -1;
224     private int securityModel = -1;
225     private byte[] contextName = null;
226     private byte[] accessContextName = null;
227 }
228
Popular Tags