001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mx.notification;
023:
024: import javax.management.NotificationFilter;
025: import javax.management.NotificationListener;
026:
027: /**
028: * The default notification listener registration.
029: *
030: * @see org.jboss.mx.notification.ListenerRegistry
031: * @see org.jboss.mx.notification.ListenerRegistrationFactory
032: *
033: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
034: * @version $Revision: 57200 $
035: */
036: public class DefaultListenerRegistration implements
037: ListenerRegistration {
038: // Attributes ----------------------------------------------------
039:
040: /**
041: * The notification listener
042: */
043: private NotificationListener listener;
044:
045: /**
046: * The notification filter
047: */
048: private NotificationFilter filter;
049:
050: /**
051: * The handback object
052: */
053: private Object handback;
054:
055: // Constructor ---------------------------------------------------
056:
057: /**
058: * Create a listener registration
059: *
060: * @param listener the notification listener
061: * @param filter the notification filter
062: * @param handback the handback object
063: */
064: public DefaultListenerRegistration(NotificationListener listener,
065: NotificationFilter filter, Object handback) {
066: this .listener = listener;
067: this .filter = filter;
068: this .handback = handback;
069: }
070:
071: // Public --------------------------------------------------------
072:
073: // ListenerRegistration Implementation ---------------------------
074:
075: public NotificationListener getListener() {
076: return listener;
077: }
078:
079: public NotificationFilter getFilter() {
080: return filter;
081: }
082:
083: public Object getHandback() {
084: return handback;
085: }
086:
087: public NotificationListener getRegisteredListener() {
088: return listener;
089: }
090:
091: public NotificationFilter getRegisteredFilter() {
092: return filter;
093: }
094:
095: public void removed() {
096: }
097:
098: public boolean equals(Object obj) {
099: if (obj == null
100: || (obj instanceof ListenerRegistration) == false)
101: return false;
102: ListenerRegistration other = (ListenerRegistration) obj;
103:
104: if (getRegisteredListener().equals(
105: other.getRegisteredListener()) == false)
106: return false;
107:
108: NotificationFilter myFilter = getRegisteredFilter();
109: NotificationFilter otherFilter = other.getRegisteredFilter();
110: if (myFilter != null && myFilter.equals(otherFilter) == false)
111: return false;
112: else if (myFilter == null && otherFilter != null)
113: return false;
114:
115: Object myHandback = getHandback();
116: Object otherHandback = other.getHandback();
117: if (myHandback != null
118: && myHandback.equals(otherHandback) == false)
119: return false;
120: else if (myHandback == null && otherHandback != null)
121: return false;
122:
123: return true;
124: }
125:
126: public int hashCode() {
127: int result = listener.hashCode();
128: if (filter != null)
129: result += filter.hashCode();
130: if (handback != null)
131: result += handback.hashCode();
132: return result;
133: }
134:
135: public String toString() {
136: StringBuffer buffer = new StringBuffer(50);
137: buffer.append(getClass()).append(":");
138: buffer.append(" listener=").append(getRegisteredListener());
139: buffer.append(" filter=").append(getRegisteredFilter());
140: buffer.append(" handback=").append(getHandback());
141: return buffer.toString();
142: }
143: }
|