001: /*_############################################################################
002: _##
003: _## SNMP4J-AgentJMX - MBeanAttributeMOTableInfo.java
004: _##
005: _## Copyright (C) 2006-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## This program is free software; you can redistribute it and/or modify
008: _## it under the terms of the GNU General Public License version 2 as
009: _## published by the Free Software Foundation.
010: _##
011: _## This program is distributed in the hope that it will be useful,
012: _## but WITHOUT ANY WARRANTY; without even the implied warranty of
013: _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: _## GNU General Public License for more details.
015: _##
016: _## You should have received a copy of the GNU General Public License
017: _## along with this program; if not, write to the Free Software
018: _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
019: _## MA 02110-1301 USA
020: _##
021: _##########################################################################*/
022:
023: package org.snmp4j.agent.mo.jmx;
024:
025: import java.io.IOException;
026: import javax.management.*;
027: import org.snmp4j.agent.mo.jmx.types.*;
028:
029: /**
030: * The <code>MBeanAttributeMOTableInfo</code> class describes the mapping from
031: * the attributes of an MBean to a SNMP conceptual table and vice versa.
032: *
033: * @author Frank Fock
034: * @version 1.0
035: */
036: public class MBeanAttributeMOTableInfo extends MBeanMOInfo {
037:
038: private MBeanAttributeKeyProvider keyProvider;
039: private String[] indexAttributes;
040: private TypedAttribute[] columns;
041: private JMXIndexSupport indexSupport;
042:
043: /**
044: * Creates a table mapping for the supplied MBean name.
045: *
046: * @param name
047: * the name of the MBean that provides the table data.
048: * @param keyProvider
049: * a key provider that provides the keys that identify rows in the table.
050: * @param columns
051: * the attributes that represent the columns of the table.
052: * @param keyAttributes
053: * the name of the attributes in <code>columns</code> that represent the
054: * primary key of the row.
055: * @param indexSupport
056: * provides the mapping between the row keys and their corresponding
057: * SNMP index values.
058: */
059: public MBeanAttributeMOTableInfo(ObjectName name,
060: MBeanAttributeKeyProvider keyProvider,
061: TypedAttribute[] columns, String[] keyAttributes,
062: JMXIndexSupport indexSupport) {
063: super (name);
064: this .keyProvider = keyProvider;
065: this .indexAttributes = keyAttributes;
066: this .columns = columns;
067: this .indexSupport = indexSupport;
068: }
069:
070: public String[] getIndexAttributes() {
071: return indexAttributes;
072: }
073:
074: public TypedAttribute[] getColumns() {
075: return columns;
076: }
077:
078: public MBeanAttributeKeyProvider getKeyProvider() {
079: return keyProvider;
080: }
081:
082: public JMXIndexSupport getIndexSupport() {
083: return indexSupport;
084: }
085:
086: public Object getKey(MBeanServerConnection server, ObjectName row)
087: throws IOException, ReflectionException,
088: InstanceNotFoundException {
089: Object[] key = new Object[indexAttributes.length];
090: AttributeList keyObjects = server.getAttributes(row,
091: indexAttributes);
092: for (int i = 0; i < keyObjects.size(); i++) {
093: key[i] = ((Attribute) keyObjects.get(i)).getValue();
094: }
095: if (key.length == 1) {
096: return key[0];
097: }
098: return key;
099: }
100: }
|