KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mx > notification > DefaultListenerRegistration


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * 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.notification;
23
24 import javax.management.NotificationFilter JavaDoc;
25 import javax.management.NotificationListener JavaDoc;
26
27 /**
28  * The default notification listener registration.
29  *
30  * @see org.jboss.mx.notification.ListenerRegistry
31  * @see org.jboss.mx.notification.ListenerRegistrationFactory
32  *
33  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
34  * @version $Revision: 37459 $
35  */

36 public class DefaultListenerRegistration
37    implements ListenerRegistration
38 {
39    // Attributes ----------------------------------------------------
40

41    /**
42     * The notification listener
43     */

44    private NotificationListener JavaDoc listener;
45
46    /**
47     * The notification filter
48     */

49    private NotificationFilter JavaDoc filter;
50
51    /**
52     * The handback object
53     */

54    private Object JavaDoc handback;
55
56    // Constructor ---------------------------------------------------
57

58    /**
59     * Create a listener registration
60     *
61     * @param listener the notification listener
62     * @param filter the notification filter
63     * @param handback the handback object
64     */

65    public DefaultListenerRegistration(NotificationListener JavaDoc listener,
66                                       NotificationFilter JavaDoc filter,
67                                       Object JavaDoc handback)
68    {
69       this.listener = listener;
70       this.filter = filter;
71       this.handback = handback;
72    }
73
74    // Public --------------------------------------------------------
75

76    // ListenerRegistration Implementation ---------------------------
77

78    public NotificationListener JavaDoc getListener()
79    {
80       return listener;
81    }
82
83    public NotificationFilter JavaDoc getFilter()
84    {
85       return filter;
86    }
87
88    public Object JavaDoc getHandback()
89    {
90       return handback;
91    }
92
93    public NotificationListener JavaDoc getRegisteredListener()
94    {
95       return listener;
96    }
97
98    public NotificationFilter JavaDoc getRegisteredFilter()
99    {
100       return filter;
101    }
102
103    public void removed()
104    {
105    }
106
107    public boolean equals(Object JavaDoc obj)
108    {
109       if (obj == null || (obj instanceof ListenerRegistration) == false)
110          return false;
111       ListenerRegistration other = (ListenerRegistration) obj;
112
113       if (getRegisteredListener().equals(other.getRegisteredListener()) == false)
114          return false;
115
116       NotificationFilter JavaDoc myFilter = getRegisteredFilter();
117       NotificationFilter JavaDoc otherFilter = other.getRegisteredFilter();
118       if (myFilter != null && myFilter.equals(otherFilter) == false)
119          return false;
120       else if (myFilter == null && otherFilter != null)
121          return false;
122
123       Object JavaDoc myHandback = getHandback();
124       Object JavaDoc otherHandback = other.getHandback();
125       if (myHandback != null && myHandback.equals(otherHandback) == false)
126          return false;
127       else if (myHandback == null && otherHandback != null)
128          return false;
129
130       return true;
131    }
132
133    public int hashCode()
134    {
135       int result = listener.hashCode();
136       if (filter != null)
137          result += filter.hashCode();
138       if (handback != null)
139          result += handback.hashCode();
140       return result;
141    }
142
143    public String JavaDoc toString()
144    {
145       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
146       buffer.append(getClass()).append(":");
147       buffer.append(" listener=").append(getRegisteredListener());
148       buffer.append(" filter=") .append(getRegisteredFilter());
149       buffer.append(" handback=").append(getHandback());
150       return buffer.toString();
151    }
152 }
153
Popular Tags