Package org.snmp4j.agent.mo.jmx

Source Code of org.snmp4j.agent.mo.jmx.MBeanNotificationObjectInfo

/*_############################################################################
  _##
  _##  SNMP4J-AgentJMX - MBeanNotificationObjectInfo.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.jmx.types.TypedAttribute;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.VariableBinding;
import javax.management.openmbean.CompositeDataSupport;
import org.snmp4j.agent.mo.jmx.types.SMIVariant;
import org.snmp4j.smi.Variable;

/**
* The <code>MBeanNotificationObjectInfo</code> maps a SNMP object class OID
* and value type to a MBean attribute.
*
* @author Frank Fock
* @version 1.0
*/
public class MBeanNotificationObjectInfo {

  private OID classID;
  private Variable valueType;
  private TypedAttribute attribute;

  public MBeanNotificationObjectInfo(OID classID,
                                     Variable valueType,
                                     TypedAttribute attribute) {
    this.classID = classID;
    this.valueType = valueType;
    this.attribute = attribute;
  }

  public VariableBinding getVariableBinding(Object mBeanNotifyUserObject,
                                            OID index) {
    Object value;
    if (mBeanNotifyUserObject instanceof CompositeDataSupport) {
      CompositeDataSupport data = (CompositeDataSupport)mBeanNotifyUserObject;
      value = data.get(attribute.getName());
    }
    else {
      value = mBeanNotifyUserObject;
    }
    Variable smiValue = (Variable) valueType.clone();
    SMIVariant smiVariant = new SMIVariant(smiValue);
    value = attribute.transformFromNative(value, null);
    smiVariant.setValue(value);
    OID oid = new OID(classID);
    if (index != null) {
      oid.append(index);
    }
    return new VariableBinding(oid, smiValue);
  }

}
TOP

Related Classes of org.snmp4j.agent.mo.jmx.MBeanNotificationObjectInfo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.