KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > remote > NotificationTuple


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package mx4j.remote;
10
11 import javax.management.Notification JavaDoc;
12 import javax.management.NotificationFilter JavaDoc;
13 import javax.management.NotificationListener JavaDoc;
14 import javax.management.ObjectName JavaDoc;
15
16 /**
17  * @version $Revision: 1.5 $
18  */

19 public class NotificationTuple
20 {
21    private static final NotificationFilter JavaDoc NO_FILTER = new NotificationFilter JavaDoc()
22    {
23       public boolean isNotificationEnabled(Notification JavaDoc notification)
24       {
25          return true;
26       }
27
28       public String JavaDoc toString()
29       {
30          return "no filter";
31       }
32    };
33    private static final Object JavaDoc NO_HANDBACK = new Object JavaDoc()
34    {
35       public String JavaDoc toString()
36       {
37          return "no handback";
38       }
39    };
40
41    private final ObjectName JavaDoc observed;
42    private final NotificationListener JavaDoc listener;
43    private final NotificationFilter JavaDoc filter;
44    private final Object JavaDoc handback;
45    private boolean invokeFilter;
46
47    public NotificationTuple(ObjectName JavaDoc observed, NotificationListener JavaDoc listener)
48    {
49       this(observed, listener, NO_FILTER, NO_HANDBACK);
50    }
51
52    public NotificationTuple(ObjectName JavaDoc observed, NotificationListener JavaDoc listener, NotificationFilter JavaDoc filter, Object JavaDoc handback)
53    {
54       this.observed = observed;
55       this.listener = listener;
56       this.filter = filter;
57       this.handback = handback;
58       this.invokeFilter = false;
59    }
60
61    public ObjectName JavaDoc getObjectName()
62    {
63       return observed;
64    }
65
66    public NotificationListener JavaDoc getNotificationListener()
67    {
68       return listener;
69    }
70
71    public Object JavaDoc getHandback()
72    {
73       if (handback == NO_HANDBACK) return null;
74       return handback;
75    }
76
77    public NotificationFilter JavaDoc getNotificationFilter()
78    {
79       if (filter == NO_FILTER) return null;
80       return filter;
81    }
82
83    public void setInvokeFilter(boolean invoke)
84    {
85       this.invokeFilter = invoke;
86    }
87
88    public boolean getInvokeFilter()
89    {
90       if (!invokeFilter) return false;
91       NotificationFilter JavaDoc filter = getNotificationFilter();
92       if (filter == null) return false;
93       return true;
94    }
95
96    public boolean equals(Object JavaDoc obj)
97    {
98       if (this == obj) return true;
99       if (!(obj instanceof NotificationTuple)) return false;
100
101       final NotificationTuple other = (NotificationTuple)obj;
102
103       if (!observed.equals(other.observed)) return false;
104       if (!listener.equals(other.listener)) return false;
105
106       // Special treatment for special filter
107
if (filter == NO_FILTER) return true;
108       if (other.filter == NO_FILTER) return true;
109
110       if (filter != null ? !filter.equals(other.filter) : other.filter != null) return false;
111       if (handback != null ? !handback.equals(other.handback) : other.handback != null) return false;
112
113       return true;
114    }
115
116    public int hashCode()
117    {
118       int result;
119       result = observed.hashCode();
120       result = 29 * result + listener.hashCode();
121       result = 29 * result + (filter != null ? filter.hashCode() : 0);
122       result = 29 * result + (handback != null ? handback.hashCode() : 0);
123       return result;
124    }
125
126    public String JavaDoc toString()
127    {
128       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("NotificationTuple [");
129       buffer.append(observed).append(", ");
130       buffer.append(listener).append(", ");
131       buffer.append(filter).append(", ");
132       buffer.append(handback).append("]");
133       return buffer.toString();
134    }
135 }
136
Popular Tags