001: /*_############################################################################
002: _##
003: _## SNMP4J-Agent - AgentppSimulationMib.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.agent.mo.ext;
022:
023: //--AgentGen BEGIN=_BEGIN
024: //--AgentGen END
025:
026: import org.snmp4j.smi.*;
027: import org.snmp4j.mp.SnmpConstants;
028: import org.snmp4j.agent.*;
029: import org.snmp4j.agent.mo.*;
030: import org.snmp4j.agent.mo.snmp.*;
031: import org.snmp4j.agent.request.*;
032: import org.snmp4j.log.LogFactory;
033: import org.snmp4j.log.LogAdapter;
034:
035: //--AgentGen BEGIN=_IMPORT
036: //--AgentGen END
037:
038: public class AgentppSimulationMib
039: //--AgentGen BEGIN=_EXTENDS
040: //--AgentGen END
041: implements MOGroup
042: //--AgentGen BEGIN=_IMPLEMENTS
043: //--AgentGen END
044: {
045:
046: private static final LogAdapter LOGGER = LogFactory
047: .getLogger(AgentppSimulationMib.class);
048:
049: //--AgentGen BEGIN=_STATIC
050: //--AgentGen END
051:
052: // Factory
053: private static MOFactory moFactory = DefaultMOFactory.getInstance();
054:
055: // Constants
056: public static final OID oidAgentppSimMode = new OID(new int[] { 1,
057: 3, 6, 1, 4, 1, 4976, 2, 1, 1, 0 });
058: public static final OID oidAgentppSimDeleteRow = new OID(new int[] {
059: 1, 3, 6, 1, 4, 1, 4976, 2, 1, 2, 0 });
060: public static final OID oidAgentppSimDeleteTableContents = new OID(
061: new int[] { 1, 3, 6, 1, 4, 1, 4976, 2, 1, 3, 0 });
062:
063: // Enumerations
064: public static final class AgentppSimModeEnum {
065: public static final int oper = 1;
066: public static final int config = 2;
067: }
068:
069: // TextualConventions
070:
071: // Scalars
072: private MOScalar agentppSimMode;
073: private MOScalar agentppSimDeleteRow;
074: private MOScalar agentppSimDeleteTableContents;
075:
076: // Tables
077:
078: //--AgentGen BEGIN=_MEMBERS
079: private MOServer moServer;
080: private OctetString myContext;
081:
082: //--AgentGen END
083:
084: public AgentppSimulationMib() {
085: agentppSimMode = new AgentppSimMode(oidAgentppSimMode,
086: MOAccessImpl.ACCESS_READ_WRITE);
087: agentppSimDeleteRow = new AgentppSimDeleteRow(
088: oidAgentppSimDeleteRow, MOAccessImpl.ACCESS_READ_WRITE);
089: agentppSimDeleteTableContents = new AgentppSimDeleteTableContents(
090: oidAgentppSimDeleteTableContents,
091: MOAccessImpl.ACCESS_READ_WRITE);
092: //--AgentGen BEGIN=_DEFAULTCONSTRUCTOR
093: //--AgentGen END
094: }
095:
096: //--AgentGen BEGIN=_CONSTRUCTORS
097: //--AgentGen END
098:
099: public void registerMOs(MOServer server, OctetString context)
100: throws DuplicateRegistrationException {
101: // Scalar Objects
102: server.register(this .agentppSimMode, context);
103: server.register(this .agentppSimDeleteRow, context);
104: server.register(this .agentppSimDeleteTableContents, context);
105: //--AgentGen BEGIN=_registerMOs
106: moServer = server;
107: myContext = context;
108: //--AgentGen END
109: }
110:
111: public void unregisterMOs(MOServer server, OctetString context) {
112: // Scalar Objects
113: server.unregister(this .agentppSimMode, context);
114: server.unregister(this .agentppSimDeleteRow, context);
115: server.unregister(this .agentppSimDeleteTableContents, context);
116: //--AgentGen BEGIN=_unregisterMOs
117: moServer = null;
118: myContext = null;
119: //--AgentGen END
120: }
121:
122: // Notifications
123:
124: // Scalars
125: public class AgentppSimMode extends EnumeratedScalar {
126: AgentppSimMode(OID oid, MOAccess access) {
127: super (oid, access, new Integer32(),
128: new int[] { AgentppSimModeEnum.oper,
129: AgentppSimModeEnum.config });
130: //--AgentGen BEGIN=agentppSimMode
131: setValue(new Integer32(AgentppSimModeEnum.oper));
132: setVolatile(true);
133: //--AgentGen END
134: }
135:
136: public int setValue(Variable newValue) {
137: //--AgentGen BEGIN=agentppSimMode::setValue
138: SimMOFactory
139: .setSimulationModeEnabled(((Integer32) newValue)
140: .getValue() == AgentppSimModeEnum.config);
141: //--AgentGen END
142: return super .setValue(newValue);
143: }
144:
145: //--AgentGen BEGIN=agentppSimMode::_METHODS
146: //--AgentGen END
147:
148: }
149:
150: public class AgentppSimDeleteRow extends MOScalar {
151: AgentppSimDeleteRow(OID oid, MOAccess access) {
152: super (oid, access, new OID());
153: //--AgentGen BEGIN=agentppSimDeleteRow
154: super .setValue(SnmpConstants.zeroDotZero);
155: setVolatile(true);
156: //--AgentGen END
157: }
158:
159: public int isValueOK(SubRequest request) {
160: Variable newValue = request.getVariableBinding()
161: .getVariable();
162: int valueOK = super .isValueOK(request);
163: if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) {
164: return valueOK;
165: }
166: //--AgentGen BEGIN=agentppSimDeleteRow::isValueOK
167: if (AgentppSimulationMib.this .moServer == null) {
168: return SnmpConstants.SNMP_ERROR_RESOURCE_UNAVAILABLE;
169: }
170: OID oid = (OID) newValue;
171: ManagedObject mo = getManagedObject(oid);
172: if (!(mo instanceof MOTable)) {
173: return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
174: }
175: MOTable table = (MOTable) mo;
176: OID index = new OID(oid.getValue(), table.getOID().size(),
177: oid.size() - table.getOID().size());
178: MOTableRow row = table.getModel().getRow(index);
179: if (row == null) {
180: return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
181: }
182: //--AgentGen END
183: return valueOK;
184: }
185:
186: public int setValue(Variable newValue) {
187: //--AgentGen BEGIN=agentppSimDeleteRow::setValue
188: if (AgentppSimulationMib.this .moServer == null) {
189: return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
190: }
191: OID oid = (OID) newValue;
192: ManagedObject mo = getManagedObject(oid);
193: if (!(mo instanceof MOTable)) {
194: return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
195: }
196: MOTable table = (MOTable) mo;
197: OID index = new OID(oid.getValue(), table.getOID().size(),
198: oid.size() - table.getOID().size());
199: MOTableRow row = table.removeRow(index);
200: if (row == null) {
201: return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
202: }
203: //--AgentGen END
204: return super .setValue(newValue);
205: }
206:
207: //--AgentGen BEGIN=agentppSimDeleteRow::_METHODS
208: //--AgentGen END
209:
210: }
211:
212: public class AgentppSimDeleteTableContents extends MOScalar {
213: AgentppSimDeleteTableContents(OID oid, MOAccess access) {
214: super (oid, access, new OID());
215: //--AgentGen BEGIN=agentppSimDeleteTableContents
216: setVolatile(true);
217: //--AgentGen END
218: }
219:
220: public int isValueOK(SubRequest request) {
221: Variable newValue = request.getVariableBinding()
222: .getVariable();
223: int valueOK = super .isValueOK(request);
224: if (valueOK != SnmpConstants.SNMP_ERROR_SUCCESS) {
225: return valueOK;
226: }
227: //--AgentGen BEGIN=agentppSimDeleteTableContents::isValueOK
228: if (AgentppSimulationMib.this .moServer == null) {
229: return SnmpConstants.SNMP_ERROR_RESOURCE_UNAVAILABLE;
230: }
231: OID oid = (OID) newValue;
232: oid.append(0);
233: ManagedObject mo = getManagedObject(oid);
234: if ((!(mo instanceof MOTable))
235: || (!(((MOTable) mo).getModel() instanceof MOMutableTableModel))) {
236: return SnmpConstants.SNMP_ERROR_WRONG_VALUE;
237: }
238: //--AgentGen END
239: return valueOK;
240: }
241:
242: public int setValue(Variable newValue) {
243: //--AgentGen BEGIN=agentppSimDeleteTableContents::setValue
244: if (AgentppSimulationMib.this .moServer == null) {
245: return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
246: }
247: OID oid = (OID) newValue;
248: oid.append(0);
249: ManagedObject mo = getManagedObject(oid);
250: if ((!(mo instanceof MOTable))
251: && (!(((MOTable) mo).getModel() instanceof MOMutableTableModel))) {
252: return SnmpConstants.SNMP_ERROR_COMMIT_FAILED;
253: }
254: MOTable table = (MOTable) mo;
255: ((MOMutableTableModel) table.getModel()).clear();
256: //--AgentGen END
257: return super .setValue(newValue);
258: }
259:
260: //--AgentGen BEGIN=agentppSimDeleteTableContents::_METHODS
261: //--AgentGen END
262:
263: }
264:
265: // Value Validators
266:
267: // Rows and Factories
268:
269: //--AgentGen BEGIN=_METHODS
270: private synchronized ManagedObject getManagedObject(OID oid) {
271: MOQuery query = new DefaultMOQuery(new DefaultMOContextScope(
272: myContext, oid, true, oid, true), true);
273: ManagedObject mo = AgentppSimulationMib.this .moServer
274: .lookup(query);
275: return mo;
276: }
277: //--AgentGen END
278:
279: //--AgentGen BEGIN=_CLASSES
280: //--AgentGen END
281:
282: //--AgentGen BEGIN=_END
283: //--AgentGen END
284: }
|