KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jmx > export > NotificationListenerBean


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jmx.export;
18
19 import javax.management.NotificationFilter JavaDoc;
20 import javax.management.NotificationListener JavaDoc;
21
22 import org.springframework.beans.factory.InitializingBean;
23 import org.springframework.util.Assert;
24
25 /**
26  * Helper class that aggregates a {@link javax.management.NotificationListener},
27  * a {@link javax.management.NotificationFilter}, and an arbitrary handback
28  * object.
29  *
30  * <p>Also provides support for associating the encapsulated
31  * {@link javax.management.NotificationListener} with any number of
32  * MBeans from which it wishes to receive
33  * {@link javax.management.Notification Notifications} via the
34  * {@link #setMappedObjectNames mappedObjectNames} property.
35  *
36  * @author Rob Harrop
37  * @since 2.0
38  */

39 public class NotificationListenerBean implements InitializingBean {
40
41     private NotificationListener JavaDoc notificationListener;
42
43     private NotificationFilter JavaDoc notificationFilter;
44
45     private Object JavaDoc handback;
46
47     private String JavaDoc[] mappedObjectNames;
48
49
50     /**
51      * Create a new instance of the {@link NotificationListenerBean} class.
52      */

53     public NotificationListenerBean() {
54     }
55
56     /**
57      * Create a new instance of the {@link NotificationListenerBean} class.
58      * @param notificationListener the encapsulated listener
59      */

60     public NotificationListenerBean(NotificationListener JavaDoc notificationListener) {
61         this.notificationListener = notificationListener;
62     }
63
64
65     /**
66      * Set the {@link javax.management.NotificationListener}.
67      * @param notificationListener said {@link javax.management.NotificationListener}
68      */

69     public void setNotificationListener(NotificationListener JavaDoc notificationListener) {
70         this.notificationListener = notificationListener;
71     }
72
73     /**
74      * Get the {@link javax.management.NotificationListener}.
75      * @return said {@link javax.management.NotificationListener}
76      */

77     public NotificationListener JavaDoc getNotificationListener() {
78         return notificationListener;
79     }
80
81     /**
82      * Set the {@link javax.management.NotificationFilter} associated
83      * with the encapsulated {@link #getNotificationFilter() NotificationFilter}.
84      * <p>May be <code>null</code>.
85      * @param notificationFilter said {@link javax.management.NotificationFilter}
86      */

87     public void setNotificationFilter(NotificationFilter JavaDoc notificationFilter) {
88         this.notificationFilter = notificationFilter;
89     }
90
91     /**
92      * Return the {@link javax.management.NotificationFilter} associated
93      * with the encapsulated {@link #getNotificationFilter() NotificationFilter}.
94      * <p>May be <code>null</code>.
95      * @return said {@link javax.management.NotificationFilter}
96      */

97     public NotificationFilter JavaDoc getNotificationFilter() {
98         return notificationFilter;
99     }
100
101     /**
102      * Set the (arbitrary) object that will be 'handed back' as-is by an
103      * {@link javax.management.NotificationBroadcaster} when notifying
104      * any {@link javax.management.NotificationListener}.
105      * <p>May be <code>null</code>.
106      * @param handback the handback object.
107      * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, Object)
108      */

109     public void setHandback(Object JavaDoc handback) {
110         this.handback = handback;
111     }
112
113     /**
114      * Return the (arbitrary) object that will be 'handed back' as-is by an
115      * {@link javax.management.NotificationBroadcaster} when notifying
116      * any {@link javax.management.NotificationListener}.
117      * @return the handback object
118      * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, Object)
119      */

120     public Object JavaDoc getHandback() {
121         return handback;
122     }
123
124     /**
125      * Set the {@link javax.management.ObjectName} of the single MBean
126      * that the encapsulated {@link #getNotificationFilter() NotificationFilter}
127      * will be registered with to listen for
128      * {@link javax.management.Notification Notifications}.
129      * @param mappedObjectName the {@link javax.management.ObjectName} identifying the
130      * target MBean that the encapsulated {@link #getNotificationFilter() NotificationFilter}
131      * is to be registered with
132      */

133     public void setMappedObjectName(String JavaDoc mappedObjectName) {
134         setMappedObjectNames(mappedObjectName != null ? new String JavaDoc[] {mappedObjectName} : null);
135     }
136
137     /**
138      * Set the array of {@link javax.management.ObjectName ObjectNames} of the MBeans
139      * that the encapsulated {@link #getNotificationFilter() NotificationFilter}
140      * will be registered with to listen for
141      * {@link javax.management.Notification Notifications}.
142      * @param mappedObjectNames the array of {@link javax.management.ObjectName ObjectName}
143      * String representations, identifying the target MBeans that the encapsulated
144      * {@link #getNotificationFilter() NotificationFilter} is to be registered with
145      */

146     public void setMappedObjectNames(String JavaDoc[] mappedObjectNames) {
147         this.mappedObjectNames = mappedObjectNames;
148     }
149
150     /**
151      * Return the list of {@link javax.management.ObjectName ObjectNames} String
152      * representations for which the encapsulated
153      * {@link #getNotificationFilter() NotificationFilter} will
154      * be registered as a listener for {@link javax.management.Notification Notifications}.
155      */

156     public String JavaDoc[] getMappedObjectNames() {
157         return mappedObjectNames;
158     }
159
160
161     /**
162      * Check that this {@link NotificationListenerBean} has been
163      * correctly configured.
164      */

165     public void afterPropertiesSet() {
166         Assert.notNull(this.notificationListener, "Property 'notificationListener' is required");
167     }
168
169 }
170
Popular Tags