KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > mo > jmx > MOScalarJMX


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentJMX - MOScalarJMX.java
4   _##
5   _## Copyright (C) 2006-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## This program is free software; you can redistribute it and/or modify
8   _## it under the terms of the GNU General Public License version 2 as
9   _## published by the Free Software Foundation.
10   _##
11   _## This program is distributed in the hope that it will be useful,
12   _## but WITHOUT ANY WARRANTY; without even the implied warranty of
13   _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   _## GNU General Public License for more details.
15   _##
16   _## You should have received a copy of the GNU General Public License
17   _## along with this program; if not, write to the Free Software
18   _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19   _## MA 02110-1301 USA
20   _##
21   _##########################################################################*/

22
23 package org.snmp4j.agent.mo.jmx;
24
25 import org.snmp4j.agent.mo.MOScalar;
26 import org.snmp4j.smi.OID;
27 import org.snmp4j.agent.MOAccess;
28 import org.snmp4j.smi.Variable;
29 import org.snmp4j.agent.request.SubRequest;
30 import org.snmp4j.mp.SnmpConstants;
31 import org.snmp4j.PDU;
32
33 /**
34  * The <code>MOScalarJMX</code> actually implements a {@link MOScalar} that
35  * gets and sets its value through a {@link JMXScalarSupport} proxy instance.
36  * This proxy maps through several configuration and support objects one or more
37  * scalar SNMP values to MBean attributes and vice versa.
38  *
39  * @author Frank Fock
40  * @version 1.0
41  */

42 public class MOScalarJMX extends MOScalar {
43
44   private JMXScalarSupport valueProxy;
45
46   public MOScalarJMX(JMXScalarSupport valueProxy,
47                      OID oid, MOAccess access, Variable initialValue) {
48     super(oid, access, initialValue);
49     this.valueProxy = valueProxy;
50   }
51
52   public int isValueOK(SubRequest request) {
53     int status = super.isValueOK(request);
54     if (status == SnmpConstants.SNMP_ERROR_SUCCESS) {
55       Variable newValue = request.getVariableBinding().getVariable();
56       status = valueProxy.checkScalarValue(getOid(), newValue);
57     }
58     return status;
59   }
60
61   public void commit(SubRequest request) {
62     Variable newValue = request.getVariableBinding().getVariable();
63     int status = valueProxy.setScalarValue(getOid(), newValue);
64     if (status != PDU.noError) {
65       request.getStatus().setErrorStatus(status);
66     }
67     else {
68       super.commit(request);
69     }
70   }
71
72   public void get(SubRequest request) {
73     int status = valueProxy.getScalarValue(getOid(), super.getValue());
74     if (status != PDU.noError) {
75       request.getStatus().setErrorStatus(status);
76     }
77     super.get(request);
78   }
79
80   public void undo(SubRequest request) {
81     Variable newValue = (Variable) request.getUndoValue();
82     int status = valueProxy.setScalarValue(getOid(), newValue);
83     request.getStatus().setErrorStatus(status);
84   }
85
86   public boolean next(SubRequest request) {
87     int status = valueProxy.getScalarValue(getOid(), super.getValue());
88     if (status != PDU.noError) {
89       return false;
90     }
91     return super.next(request);
92   }
93
94   protected String JavaDoc toStringDetails() {
95     return ",valueProxy="+valueProxy;
96   }
97
98 }
99
Popular Tags