KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > AttributeChangeNotificationFilter


1 /*
2  * @(#)AttributeChangeNotificationFilter.java 4.25 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management;
9
10
11 // java import
12
import java.util.Enumeration JavaDoc;
13 import java.util.Vector JavaDoc;
14
15
16 /**
17  * This class implements of the {@link javax.management.NotificationFilter NotificationFilter}
18  * interface for the {@link javax.management.AttributeChangeNotification attribute change notification}.
19  * The filtering is performed on the name of the observed attribute.
20  * <P>
21  * It manages a list of enabled attribute names.
22  * A method allows users to enable/disable as many attribute names as required.
23  *
24  * @since 1.5
25  */

26 public class AttributeChangeNotificationFilter implements NotificationFilter JavaDoc, java.io.Serializable JavaDoc {
27     
28     /* Serial version */
29     private static final long serialVersionUID = -6347317584796410029L;
30
31     /**
32      * @serial {@link Vector} that contains the enabled attribute names.
33      * The default value is an empty vector.
34      */

35     private Vector JavaDoc enabledAttributes = new Vector JavaDoc();
36
37
38     /**
39      * Invoked before sending the specified notification to the listener.
40      * <BR>This filter compares the attribute name of the specified attribute change notification
41      * with each enabled attribute name.
42      * If the attribute name equals one of the enabled attribute names,
43      * the notification must be sent to the listener and this method returns <CODE>true</CODE>.
44      *
45      * @param notification The attribute change notification to be sent.
46      * @return <CODE>true</CODE> if the notification has to be sent to the listener, <CODE>false</CODE> otherwise.
47      */

48     public synchronized boolean isNotificationEnabled(Notification JavaDoc notification) {
49         
50         String JavaDoc type = notification.getType();
51         
52         if ((type == null) ||
53             (type.equals(AttributeChangeNotification.ATTRIBUTE_CHANGE) == false) ||
54             (!(notification instanceof AttributeChangeNotification JavaDoc))) {
55             return false;
56         }
57         
58         String JavaDoc attributeName =
59           ((AttributeChangeNotification JavaDoc)notification).getAttributeName();
60         return enabledAttributes.contains(attributeName);
61     }
62     
63     /**
64      * Enables all the attribute change notifications the attribute name of which equals
65      * the specified name to be sent to the listener.
66      * <BR>If the specified name is already in the list of enabled attribute names,
67      * this method has no effect.
68      *
69      * @param name The attribute name.
70      * @exception java.lang.IllegalArgumentException The attribute name parameter is null.
71      */

72     public synchronized void enableAttribute(String JavaDoc name) throws java.lang.IllegalArgumentException JavaDoc {
73         
74         if (name == null) {
75             throw new java.lang.IllegalArgumentException JavaDoc("The name cannot be null.");
76         }
77         if (!enabledAttributes.contains(name)) {
78             enabledAttributes.addElement(name);
79         }
80     }
81     
82     /**
83      * Disables all the attribute change notifications the attribute name of which equals
84      * the specified attribute name to be sent to the listener.
85      * <BR>If the specified name is not in the list of enabled attribute names,
86      * this method has no effect.
87      *
88      * @param name The attribute name.
89      */

90     public synchronized void disableAttribute(String JavaDoc name) {
91         enabledAttributes.removeElement(name);
92     }
93     
94     /**
95      * Disables all the attribute names.
96      */

97     public synchronized void disableAllAttributes() {
98         enabledAttributes.removeAllElements();
99     }
100     
101     /**
102      * Gets all the enabled attribute names for this filter.
103      *
104      * @return The list containing all the enabled attribute names.
105      */

106     public synchronized Vector JavaDoc getEnabledAttributes() {
107         return enabledAttributes;
108     }
109    
110 }
111
Popular Tags