01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.mx.server;
23:
24: import javax.management.Notification;
25: import javax.management.NotificationListener;
26: import javax.management.ObjectName;
27:
28: /**
29: * A notification listener used to forward notifications to listeners
30: * added through the mbean server.<p>
31: *
32: * The original source is replaced with the object name.
33: *
34: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
35: * @version $Revision: 57200 $
36: */
37: public class NotificationListenerProxy implements NotificationListener {
38: // Constants ---------------------------------------------------
39:
40: // Attributes --------------------------------------------------
41:
42: /**
43: * The original listener
44: */
45: private NotificationListener listener;
46:
47: /**
48: * The object name we are proxying
49: */
50: private ObjectName name;
51:
52: // Static ------------------------------------------------------
53:
54: // Constructors ------------------------------------------------
55:
56: /**
57: * Create a new Notification Listener Proxy
58: *
59: * @param name the object name
60: * @param listener the original listener
61: */
62: public NotificationListenerProxy(ObjectName name,
63: NotificationListener listener) {
64: this .name = name;
65: this .listener = listener;
66: }
67:
68: // Public ------------------------------------------------------
69:
70: // implementation NotificationListener -------------------------
71:
72: public void handleNotification(Notification notification,
73: Object handback) {
74: if (notification == null)
75: return;
76:
77: // Forward the notification with the object name as source
78: // FIXME: This overwrites the original source, there is no way
79: // to put it back with the current spec
80: notification.setSource(name);
81: listener.handleNotification(notification, handback);
82: }
83:
84: // overrides ---------------------------------------------------
85:
86: // Protected ---------------------------------------------------
87:
88: // Private -----------------------------------------------------
89:
90: // Inner classes -----------------------------------------------
91: }
|