KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > ext > AgentppSimulationMib


1 /*_############################################################################
2   _##
3   _## SNMP4J-Agent - AgentppSimulationMib.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (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
22 package org.snmp4j.agent.mo.ext;
23
24
25 //--AgentGen BEGIN=_BEGIN
26
//--AgentGen END
27

28 import org.snmp4j.smi.*;
29 import org.snmp4j.mp.SnmpConstants;
30 import org.snmp4j.agent.*;
31 import org.snmp4j.agent.mo.*;
32 import org.snmp4j.agent.mo.snmp.*;
33 import org.snmp4j.agent.request.*;
34 import org.snmp4j.log.LogFactory;
35 import org.snmp4j.log.LogAdapter;
36
37 //--AgentGen BEGIN=_IMPORT
38
//--AgentGen END
39

40 public class AgentppSimulationMib
41 //--AgentGen BEGIN=_EXTENDS
42
//--AgentGen END
43
implements MOGroup
44 //--AgentGen BEGIN=_IMPLEMENTS
45
//--AgentGen END
46
{
47
48   private static final LogAdapter LOGGER =
49       LogFactory.getLogger(AgentppSimulationMib.class);
50
51 //--AgentGen BEGIN=_STATIC
52
//--AgentGen END
53

54   // Factory
55
private static MOFactory moFactory = DefaultMOFactory.getInstance();
56
57   // Constants
58
public static final OID oidAgentppSimMode =
59     new OID(new int[] { 1,3,6,1,4,1,4976,2,1,1,0 });
60   public static final OID oidAgentppSimDeleteRow =
61     new OID(new int[] { 1,3,6,1,4,1,4976,2,1,2,0 });
62   public static final OID oidAgentppSimDeleteTableContents =
63     new OID(new int[] { 1,3,6,1,4,1,4976,2,1,3,0 });
64
65   // Enumerations
66
public static final class AgentppSimModeEnum {
67     public static final int oper = 1;
68     public static final int config = 2;
69   }
70
71
72   // TextualConventions
73

74   // Scalars
75
private MOScalar agentppSimMode;
76   private MOScalar agentppSimDeleteRow;
77   private MOScalar agentppSimDeleteTableContents;
78
79   // Tables
80

81
82 //--AgentGen BEGIN=_MEMBERS
83
private MOServer moServer;
84   private OctetString myContext;
85 //--AgentGen END
86

87   public AgentppSimulationMib() {
88     agentppSimMode =
89       new AgentppSimMode(oidAgentppSimMode, MOAccessImpl.ACCESS_READ_WRITE);
90     agentppSimDeleteRow =
91       new AgentppSimDeleteRow(oidAgentppSimDeleteRow,
92                               MOAccessImpl.ACCESS_READ_WRITE);
93     agentppSimDeleteTableContents =
94       new AgentppSimDeleteTableContents(oidAgentppSimDeleteTableContents,
95                                         MOAccessImpl.ACCESS_READ_WRITE);
96 //--AgentGen BEGIN=_DEFAULTCONSTRUCTOR
97
//--AgentGen END
98
}
99
100 //--AgentGen BEGIN=_CONSTRUCTORS
101
//--AgentGen END
102

103
104
105
106   public void registerMOs(MOServer server, OctetString context)
107     throws DuplicateRegistrationException
108   {
109     // Scalar Objects
110
server.register(this.agentppSimMode, context);
111     server.register(this.agentppSimDeleteRow, context);
112     server.register(this.agentppSimDeleteTableContents, context);
113 //--AgentGen BEGIN=_registerMOs
114
moServer = server;
115     myContext = context;
116 //--AgentGen END
117
}
118
119   public void unregisterMOs(MOServer server, OctetString context) {
120     // Scalar Objects
121
server.unregister(this.agentppSimMode, context);
122     server.unregister(this.agentppSimDeleteRow, context);
123     server.unregister(this.agentppSimDeleteTableContents, context);
124 //--AgentGen BEGIN=_unregisterMOs
125
moServer = null;
126     myContext = null;
127 //--AgentGen END
128
}
129
130   // Notifications
131

132   // Scalars
133
public class AgentppSimMode extends EnumeratedScalar {
134     AgentppSimMode(OID oid, MOAccess access) {
135       super(oid, access, new Integer32(),
136             new int[] { AgentppSimModeEnum.oper,
137                         AgentppSimModeEnum.config });
138 //--AgentGen BEGIN=agentppSimMode
139
setValue(new Integer32(AgentppSimModeEnum.oper));
140       setVolatile(true);
141 //--AgentGen END
142
}
143
144     public int setValue(Variable newValue) {
145      //--AgentGen BEGIN=agentppSimMode::setValue
146
SimMOFactory.setSimulationModeEnabled(((Integer32)newValue).getValue() ==
147                                            AgentppSimModeEnum.config);
148      //--AgentGen END
149
return super.setValue(newValue);
150     }
151
152      //--AgentGen BEGIN=agentppSimMode::_METHODS
153
//--AgentGen END
154

155   }
156
157   public class AgentppSimDeleteRow extends MOScalar {
158     AgentppSimDeleteRow(OID oid, MOAccess access) {
159       super(oid, access, new OID());
160 //--AgentGen BEGIN=agentppSimDeleteRow
161
super.setValue(SnmpConstants.zeroDotZero);
162       setVolatile(true);
163 //--AgentGen END
164
}
165
166     public int isValueOK(SubRequest request) {
167       Variable newValue =
168         request.getVariableBinding().getVariable();
169       int valueOK = super.isValueOK(request);
170       if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) {
171         return valueOK;
172       }
173      //--AgentGen BEGIN=agentppSimDeleteRow::isValueOK
174
if (AgentppSimulationMib.this.moServer == null) {
175        return SnmpConstants.SNMP_ERROR_RESOURCE_UNAVAILABLE;
176      }
177      OID oid = (OID)newValue;
178      ManagedObject mo = getManagedObject(oid);
179      if (!(mo instanceof MOTable)) {
180        return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
181      }
182      MOTable table = (MOTable)mo;
183      OID index = new OID(oid.getValue(), table.getOID().size(),
184                          oid.size()-table.getOID().size());
185      MOTableRow row = table.getModel().getRow(index);
186      if (row == null) {
187        return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
188      }
189      //--AgentGen END
190
return valueOK;
191     }
192
193     public int setValue(Variable newValue) {
194      //--AgentGen BEGIN=agentppSimDeleteRow::setValue
195
if (AgentppSimulationMib.this.moServer == null) {
196        return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
197      }
198      OID oid = (OID)newValue;
199      ManagedObject mo = getManagedObject(oid);
200      if (!(mo instanceof MOTable)) {
201        return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
202      }
203      MOTable table = (MOTable)mo;
204      OID index = new OID(oid.getValue(), table.getOID().size(),
205                          oid.size()-table.getOID().size());
206      MOTableRow row = table.removeRow(index);
207      if (row == null) {
208        return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
209      }
210      //--AgentGen END
211
return super.setValue(newValue);
212     }
213
214      //--AgentGen BEGIN=agentppSimDeleteRow::_METHODS
215
//--AgentGen END
216

217   }
218
219   public class AgentppSimDeleteTableContents extends MOScalar {
220     AgentppSimDeleteTableContents(OID oid, MOAccess access) {
221       super(oid, access, new OID());
222 //--AgentGen BEGIN=agentppSimDeleteTableContents
223
setVolatile(true);
224 //--AgentGen END
225
}
226
227     public int isValueOK(SubRequest request) {
228       Variable newValue =
229         request.getVariableBinding().getVariable();
230       int valueOK = super.isValueOK(request);
231       if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) {
232         return valueOK;
233       }
234      //--AgentGen BEGIN=agentppSimDeleteTableContents::isValueOK
235
if (AgentppSimulationMib.this.moServer == null) {
236        return SnmpConstants.SNMP_ERROR_RESOURCE_UNAVAILABLE;
237      }
238      OID oid = (OID)newValue;
239      oid.append(0);
240      ManagedObject mo = getManagedObject(oid);
241      if ((!(mo instanceof MOTable)) ||
242          (!(((MOTable)mo).getModel() instanceof MOMutableTableModel))) {
243        return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
244      }
245      //--AgentGen END
246
return valueOK;
247     }
248
249     public int setValue(Variable newValue) {
250      //--AgentGen BEGIN=agentppSimDeleteTableContents::setValue
251
if (AgentppSimulationMib.this.moServer == null) {
252        return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
253      }
254      OID oid = (OID)newValue;
255      oid.append(0);
256      ManagedObject mo = getManagedObject(oid);
257      if ((!(mo instanceof MOTable)) &&
258          (!(((MOTable)mo).getModel() instanceof MOMutableTableModel))) {
259        return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
260      }
261      MOTable table = (MOTable)mo;
262      ((MOMutableTableModel)table.getModel()).clear();
263      //--AgentGen END
264
return super.setValue(newValue);
265     }
266
267      //--AgentGen BEGIN=agentppSimDeleteTableContents::_METHODS
268
//--AgentGen END
269

270   }
271
272
273   // Value Validators
274

275   // Rows and Factories
276

277
278 //--AgentGen BEGIN=_METHODS
279
private synchronized ManagedObject getManagedObject(OID oid) {
280     MOQuery query = new DefaultMOQuery(new DefaultMOContextScope(myContext,
281         oid, true, oid, true), true);
282     ManagedObject mo = AgentppSimulationMib.this.moServer.lookup(query);
283     return mo;
284   }
285 //--AgentGen END
286

287 //--AgentGen BEGIN=_CLASSES
288
//--AgentGen END
289

290 //--AgentGen BEGIN=_END
291
//--AgentGen END
292
}
293
294
295
Popular Tags