KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentJMX - MBeanAttributeMOTableInfo.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 java.io.IOException JavaDoc;
26 import javax.management.*;
27 import org.snmp4j.agent.mo.jmx.types.*;
28
29 /**
30  * The <code>MBeanAttributeMOTableInfo</code> class describes the mapping from
31  * the attributes of an MBean to a SNMP conceptual table and vice versa.
32  *
33  * @author Frank Fock
34  * @version 1.0
35  */

36 public class MBeanAttributeMOTableInfo extends MBeanMOInfo {
37
38   private MBeanAttributeKeyProvider keyProvider;
39   private String JavaDoc[] indexAttributes;
40   private TypedAttribute[] columns;
41   private JMXIndexSupport indexSupport;
42
43   /**
44    * Creates a table mapping for the supplied MBean name.
45    *
46    * @param name
47    * the name of the MBean that provides the table data.
48    * @param keyProvider
49    * a key provider that provides the keys that identify rows in the table.
50    * @param columns
51    * the attributes that represent the columns of the table.
52    * @param keyAttributes
53    * the name of the attributes in <code>columns</code> that represent the
54    * primary key of the row.
55    * @param indexSupport
56    * provides the mapping between the row keys and their corresponding
57    * SNMP index values.
58    */

59   public MBeanAttributeMOTableInfo(ObjectName name,
60                                    MBeanAttributeKeyProvider keyProvider,
61                                    TypedAttribute[] columns,
62                                    String JavaDoc[] keyAttributes,
63                                    JMXIndexSupport indexSupport) {
64     super(name);
65     this.keyProvider = keyProvider;
66     this.indexAttributes = keyAttributes;
67     this.columns = columns;
68     this.indexSupport = indexSupport;
69   }
70
71   public String JavaDoc[] getIndexAttributes() {
72     return indexAttributes;
73   }
74
75   public TypedAttribute[] getColumns() {
76     return columns;
77   }
78
79   public MBeanAttributeKeyProvider getKeyProvider() {
80     return keyProvider;
81   }
82
83   public JMXIndexSupport getIndexSupport() {
84     return indexSupport;
85   }
86
87   public Object JavaDoc getKey(MBeanServerConnection server, ObjectName row) throws
88       IOException JavaDoc, ReflectionException, InstanceNotFoundException {
89     Object JavaDoc[] key = new Object JavaDoc[indexAttributes.length];
90     AttributeList keyObjects = server.getAttributes(row, indexAttributes);
91     for (int i=0; i<keyObjects.size(); i++) {
92       key[i] = ((Attribute)keyObjects.get(i)).getValue();
93     }
94     if (key.length == 1) {
95       return key[0];
96     }
97     return key;
98   }
99 }
100
Popular Tags