KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentJMX - JMXDefaultMOFactory.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 javax.management.*;
26
27 import org.snmp4j.agent.*;
28 import org.snmp4j.agent.mo.*;
29 import org.snmp4j.smi.*;
30
31
32 /**
33  * The <code>JMXDefaultMOFactory</code> extends the default SNMP4J-Agent
34  * {@link ManagedObject} factory to create {@link MOScalarJMX} and
35  * {@link MOTableJMX} instances instead of {@link MOScalar} and
36  * {@link DefaultMOTable} instances respectively.
37  * <p>
38  * Scalars are created ready-to-use with the supplied or a default
39  * JMXScalarSupport instance. For tables, a {@link DefaultMOMutableTableModel}
40  * is created at initialization that need to be replaced externally by
41  * a {@link JMXTableModel} to instrument a table with JMX.
42  *
43  * @author Frank Fock
44  * @version 1.0
45  */

46 public class JMXDefaultMOFactory extends DefaultMOFactory {
47
48   private MBeanServerConnection server;
49   private JMXScalarSupport scalarSupport;
50
51   /**
52    * Creates a <code>JMXDefaultMOFactory</code> instance backed by the specified
53    * MBean server. If the <code>JMXScalarSupport</code> member is not set before
54    * the factory is used, a default <code>MBeanAttributeMOScalarSupport</code>
55    * is used.
56    * @param server
57    * the MBeanServerConnection to be used by this JMXDefaultMOFactory.
58    */

59   public JMXDefaultMOFactory(MBeanServerConnection server) {
60     this(server, null);
61   }
62
63   /**
64    * Creates a <code>JMXDefaultMOFactory</code> instance backed by the specified
65    * MBean server and using the supplied JMXScalarSupport instance to create
66    * scalars.
67    *
68    * @param server MBeanServerConnection
69    * @param scalarSupport JMXScalarSupport
70    */

71   public JMXDefaultMOFactory(MBeanServerConnection server,
72                              JMXScalarSupport scalarSupport) {
73     this.server = server;
74     this.scalarSupport = scalarSupport;
75   }
76
77   public synchronized JMXScalarSupport getScalarSupport() {
78     if (scalarSupport == null) {
79       scalarSupport = new MBeanAttributeMOScalarSupport(server);
80     }
81     return scalarSupport;
82   }
83
84   public MBeanServerConnection getServer() {
85     return server;
86   }
87
88   public synchronized void setScalarSupport(JMXScalarSupport scalarSupport) {
89     this.scalarSupport = scalarSupport;
90   }
91
92   public MOScalar createScalar(OID id, MOAccess access, Variable value) {
93     return new MOScalarJMX(getScalarSupport(), id, access, value);
94   }
95
96   public MOScalar createScalar(OID id, MOAccess access, Variable value,
97                                String JavaDoc tcModuleName, String JavaDoc textualConvention) {
98     /**@todo use TC information */
99     return createScalar(id, access, value);
100   }
101
102   public MOTable createTable(OID oid, MOTableIndex indexDef, MOColumn[] columns,
103                              MOTableModel model) {
104     return new MOTableJMX(oid, indexDef, columns,
105                           createTableModel(oid, indexDef, columns));
106   }
107
108   public MOTable createTable(OID oid, MOTableIndex indexDef, MOColumn[] columns) {
109     return new MOTableJMX(oid, indexDef, columns,
110                           createTableModel(oid, indexDef, columns));
111   }
112 }
113
Popular Tags