KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentJMX - AbstractJMXTableSupport.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 package org.snmp4j.agent.mo.jmx;
23
24 import java.util.*;
25
26 import org.snmp4j.agent.mo.*;
27 import org.snmp4j.smi.*;
28 import org.snmp4j.PDU;
29 import javax.management.ObjectName JavaDoc;
30
31 public abstract class AbstractJMXTableSupport implements JMXTableSupport {
32
33   protected Map<OID,JMXTableDetailSupport> columnValueMappings =
34       new HashMap<OID,JMXTableDetailSupport>(10);
35
36   public AbstractJMXTableSupport() {
37   }
38
39   public abstract OID getLastIndex(OID tableOID);
40
41   public int getRow(OID tableOID, MOTableRow row) {
42     Object JavaDoc rowKey = mapToRowId(tableOID, row.getIndex());
43     if (rowKey != null) {
44       JMXTableDetailSupport detailSupport = getTableDetailSupport(tableOID);
45       if (detailSupport != null) {
46         ObjectName JavaDoc mBean =
47             detailSupport.getRowSupport().getRowMBean(tableOID, rowKey);
48         for (int i = 0; i < row.size(); i++) {
49           Variable v = row.getValue(i);
50           detailSupport.getColumnSupport().getColumnValue(mBean, i, v);
51         }
52       }
53       return PDU.noError;
54     }
55     return PDU.resourceUnavailable;
56   }
57
58   protected synchronized JMXTableDetailSupport getTableDetailSupport(OID tableOID) {
59     return columnValueMappings.get(tableOID);
60   }
61
62   public abstract int getRowCount(OID tableOID);
63
64   public abstract Iterator rowIdIterator(OID tableOID);
65
66   public abstract OID mapToIndex(OID tableOID, Object JavaDoc rowIdentifier);
67
68   public abstract Object JavaDoc mapToRowId(OID tableOID, OID rowIndex);
69
70   class JMXTableDetailSupport {
71     private JMXColumnSupport columnSupport;
72     private JMXRowSupport rowSupport;
73
74     public JMXTableDetailSupport(JMXRowSupport rowSupport,
75                                  JMXColumnSupport columnSupport) {
76       this.rowSupport = rowSupport;
77       this.columnSupport = columnSupport;
78     }
79
80     public JMXRowSupport getRowSupport() {
81       return rowSupport;
82     }
83
84     public JMXColumnSupport getColumnSupport() {
85       return columnSupport;
86     }
87
88   }
89
90 }
91
Popular Tags