/*_############################################################################
_##
_## SNMP4J-AgentJMX - MOScalarJMX.java
_##
_## Copyright (C) 2006-2009 Frank Fock (SNMP4J.org)
_##
_## This program is free software; you can redistribute it and/or modify
_## it under the terms of the GNU General Public License version 2 as
_## published by the Free Software Foundation.
_##
_## This program is distributed in the hope that it will be useful,
_## but WITHOUT ANY WARRANTY; without even the implied warranty of
_## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
_## GNU General Public License for more details.
_##
_## You should have received a copy of the GNU General Public License
_## along with this program; if not, write to the Free Software
_## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
_## MA 02110-1301 USA
_##
_##########################################################################*/
package org.snmp4j.agent.mo.jmx;
import org.snmp4j.agent.mo.MOScalar;
import org.snmp4j.smi.OID;
import org.snmp4j.agent.MOAccess;
import org.snmp4j.smi.Variable;
import org.snmp4j.agent.request.SubRequest;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.PDU;
/**
* The <code>MOScalarJMX</code> actually implements a {@link MOScalar} that
* gets and sets its value through a {@link JMXScalarSupport} proxy instance.
* This proxy maps through several configuration and support objects one or more
* scalar SNMP values to MBean attributes and vice versa.
*
* @author Frank Fock
* @version 1.0
*/
public class MOScalarJMX extends MOScalar {
private JMXScalarSupport valueProxy;
public MOScalarJMX(JMXScalarSupport valueProxy,
OID oid, MOAccess access, Variable initialValue) {
super(oid, access, initialValue);
this.valueProxy = valueProxy;
}
public int isValueOK(SubRequest request) {
int status = super.isValueOK(request);
if (status == SnmpConstants.SNMP_ERROR_SUCCESS) {
Variable newValue = request.getVariableBinding().getVariable();
status = valueProxy.checkScalarValue(getOid(), newValue);
}
return status;
}
public void commit(SubRequest request) {
Variable newValue = request.getVariableBinding().getVariable();
int status = valueProxy.setScalarValue(getOid(), newValue);
if (status != PDU.noError) {
request.getStatus().setErrorStatus(status);
}
else {
super.commit(request);
}
}
public void get(SubRequest request) {
int status = valueProxy.getScalarValue(getOid(), super.getValue());
if (status != PDU.noError) {
request.getStatus().setErrorStatus(status);
}
super.get(request);
}
public void undo(SubRequest request) {
Variable newValue = (Variable) request.getUndoValue();
int status = valueProxy.setScalarValue(getOid(), newValue);
request.getStatus().setErrorStatus(status);
}
public boolean next(SubRequest request) {
int status = valueProxy.getScalarValue(getOid(), super.getValue());
if (status != PDU.noError) {
return false;
}
return super.next(request);
}
protected String toStringDetails() {
return ",valueProxy="+valueProxy;
}
}