Source Code Cross Referenced for NotificationFilterSupport.java in  » 6.0-JDK-Core » management » javax » management » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » management » javax.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025
026        package javax.management;
027
028        import java.util.List;
029        import java.util.Vector;
030
031        /**
032         * Provides an implementation of the {@link javax.management.NotificationFilter} interface.
033         * The filtering is performed on the notification type attribute.
034         * <P>
035         * Manages a list of enabled notification types.
036         * A method allows users to enable/disable as many notification types as required.
037         * <P>
038         * Then, before sending a notification to a listener registered with a filter,
039         * the notification broadcaster compares this notification type with all notification types
040         * enabled by the filter. The notification will be sent to the listener
041         * only if its filter enables this notification type.
042         * <P>
043         * Example:
044         * <BLOCKQUOTE>
045         * <PRE>
046         * NotificationFilterSupport myFilter = new NotificationFilterSupport();
047         * myFilter.enableType("my_example.my_type");
048         * myBroadcaster.addListener(myListener, myFilter, null);
049         * </PRE>
050         * </BLOCKQUOTE>
051         * The listener <CODE>myListener</CODE> will only receive notifications the type of which equals/starts with "my_example.my_type".
052         *
053         * @see javax.management.NotificationBroadcaster#addNotificationListener
054         *
055         * @since 1.5
056         */
057        public class NotificationFilterSupport implements  NotificationFilter {
058
059            /* Serial version */
060            private static final long serialVersionUID = 6579080007561786969L;
061
062            /**
063             * @serial {@link Vector} that contains the enabled notification types.
064             *         The default value is an empty vector.
065             */
066            private List<String> enabledTypes = new Vector<String>();
067
068            /**
069             * Invoked before sending the specified notification to the listener.
070             * <BR>This filter compares the type of the specified notification with each enabled type.
071             * If the notification type matches one of the enabled types,
072             * the notification should be sent to the listener and this method returns <CODE>true</CODE>.
073             *
074             * @param notification The notification to be sent.
075             * @return <CODE>true</CODE> if the notification should be sent to the listener, <CODE>false</CODE> otherwise.
076             */
077            public synchronized boolean isNotificationEnabled(
078                    Notification notification) {
079
080                String type = notification.getType();
081
082                if (type == null) {
083                    return false;
084                }
085                try {
086                    for (String prefix : enabledTypes) {
087                        if (type.startsWith(prefix)) {
088                            return true;
089                        }
090                    }
091                } catch (java.lang.NullPointerException e) {
092                    // Should never occurs...
093                    return false;
094                }
095                return false;
096            }
097
098            /**
099             * Enables all the notifications the type of which starts with the specified prefix
100             * to be sent to the listener.
101             * <BR>If the specified prefix is already in the list of enabled notification types,
102             * this method has no effect.
103             * <P>
104             * Example:
105             * <BLOCKQUOTE>
106             * <PRE>
107             * // Enables all notifications the type of which starts with "my_example" to be sent.
108             * myFilter.enableType("my_example");
109             * // Enables all notifications the type of which is "my_example.my_type" to be sent.
110             * myFilter.enableType("my_example.my_type");
111             * </PRE>
112             * </BLOCKQUOTE>
113             *
114             * Note that:
115             * <BLOCKQUOTE><CODE>
116             * myFilter.enableType("my_example.*");
117             * </CODE></BLOCKQUOTE>
118             * will no match any notification type.
119             *
120             * @param prefix The prefix.
121             * @exception java.lang.IllegalArgumentException The prefix parameter is null.
122             */
123            public synchronized void enableType(String prefix)
124                    throws IllegalArgumentException {
125
126                if (prefix == null) {
127                    throw new IllegalArgumentException(
128                            "The prefix cannot be null.");
129                }
130                if (!enabledTypes.contains(prefix)) {
131                    enabledTypes.add(prefix);
132                }
133            }
134
135            /**
136             * Removes the given prefix from the prefix list.
137             * <BR>If the specified prefix is not in the list of enabled notification types,
138             * this method has no effect.
139             *
140             * @param prefix The prefix.
141             */
142            public synchronized void disableType(String prefix) {
143                enabledTypes.remove(prefix);
144            }
145
146            /**
147             * Disables all notification types.
148             */
149            public synchronized void disableAllTypes() {
150                enabledTypes.clear();
151            }
152
153            /**
154             * Gets all the enabled notification types for this filter.
155             *
156             * @return The list containing all the enabled notification types.
157             */
158            public synchronized Vector<String> getEnabledTypes() {
159                return (Vector<String>) enabledTypes;
160            }
161
162        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.