KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentJMX - MBeanNotificationInfo.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 org.snmp4j.smi.VariableBinding;
26 import org.snmp4j.smi.OID;
27 import org.snmp4j.smi.OctetString;
28
29 /**
30  * The <code>MBeanNotificationInfo</code> class represents information for
31  * a MBean notification to SNMP notification type mapping. Since MBean
32  * notifications contain payload information that does not include information
33  * about the payload's structural source. As a consequence, the payload cannot
34  * always be mapped to a SNMP notification without additional information about
35  * table indexing. This information is provided by a
36  * {@link JMXNotificationIndexSupport} instance then.
37  *
38  * @author Frank Fock
39  * @version 1.0
40  */

41 public class MBeanNotificationInfo {
42
43   private JMXNotificationIndexSupport indexSupport;
44   private MBeanNotificationObjectInfo[] objects;
45   private OctetString context = new OctetString();
46
47   /**
48    * Creates a notification mapping between a MBean notification to a SNMP
49    * notification. The notification mapping uses the default context.
50    * @param objects
51    * the mappings of the SNMP notification payload to MBean attributes.
52    * @param indexSupport
53    * the index support instance that provides indexes for the notification
54    * payload object OIDs where necessary.
55    */

56   public MBeanNotificationInfo(MBeanNotificationObjectInfo[] objects,
57                                JMXNotificationIndexSupport indexSupport) {
58     this.indexSupport = indexSupport;
59     this.objects = objects;
60   }
61
62   /**
63    * Creates a notification mapping between a MBean notification to a SNMP
64    * notification.
65    * @param objects
66    * the mappings of the SNMP notification payload to MBean attributes.
67    * @param indexSupport
68    * the index support instance that provides indexes for the notification
69    * payload object OIDs where necessary.
70    * @param context
71    * the context of the notification. Default is a zero length string.
72    */

73   public MBeanNotificationInfo(MBeanNotificationObjectInfo[] objects,
74                                JMXNotificationIndexSupport indexSupport,
75                                OctetString context) {
76     this(objects, indexSupport);
77     this.context = context;
78   }
79
80   public VariableBinding[] getNotificationPayload(Object JavaDoc notificationObject) {
81     VariableBinding[] vbs = new VariableBinding[objects.length];
82     if (indexSupport != null) {
83       synchronized (indexSupport) {
84         indexSupport.intialize(notificationObject);
85         for (int i=0; i<objects.length; i++) {
86           MBeanNotificationObjectInfo oinfo = objects[i];
87           OID index = indexSupport.getIndex(i);
88           vbs[i] = oinfo.getVariableBinding(notificationObject, index);
89         }
90       }
91     }
92     else {
93       for (int i=0; i<objects.length; i++) {
94         MBeanNotificationObjectInfo oinfo = objects[i];
95         vbs[i] = oinfo.getVariableBinding(notificationObject, null);
96       }
97     }
98     return vbs;
99   }
100
101   public OctetString getContext() {
102     return context;
103   }
104
105 }
106
Popular Tags