Source Code Cross Referenced for NotificationFilterSupport.java in  » JMX » jfoxmx » javax » management » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » jfoxmx » javax.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.org
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package javax.management;
009:
010:        import java.io.Serializable;
011:        import java.util.List;
012:        import java.util.Vector;
013:        import java.util.Iterator;
014:        import java.util.ArrayList;
015:
016:        /**
017:         * Provides an implementation of the {@link javax.management.NotificationFilter} interface.
018:         * The filtering is performed on the notification type attribute.
019:         * <P>
020:         * Manages a list of enabled notification types.
021:         * A method allows users to enable/disable as many notification types as required.
022:         * <P>
023:         * Then, before sending a notification to a listener registered with a filter,
024:         * the notification broadcaster compares this notification type with all notification types
025:         * enabled by the filter. The notification will be sent to the listener
026:         * only if its filter enables this notification type.
027:         * <P>
028:         * Example:
029:         * <BLOCKQUOTE>
030:         * <PRE>
031:         * NotificationFilterSupport myFilter = new NotificationFilterSupport();
032:         * myFilter.enableType("my_example.my_type");
033:         * myBroadcaster.addListener(myListener, myFilter, null);
034:         * </PRE>
035:         * </BLOCKQUOTE>
036:         * The listener <CODE>myListener</CODE> will only receive notifications the type of which equals/starts with "my_example.my_type".
037:         *
038:         * @see javax.management.NotificationBroadcaster#addNotificationListener
039:         *
040:         * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
041:         */
042:
043:        public class NotificationFilterSupport implements  NotificationFilter,
044:                Serializable {
045:
046:            /**
047:             * Vector that contains the enabled notification types.
048:             * The default value is an empty vector.
049:             */
050:            private List enabledTypes = new ArrayList();
051:
052:            /**
053:             * Invoked before sending the specified notification to the listener.
054:             * <BR>This filter compares the type of the specified notification with each enabled type.
055:             * If the notification type matches one of the enabled types,
056:             * the notification should be sent to the listener and this method returns <CODE>true</CODE>.
057:             *
058:             * @param notification The notification to be sent.
059:             * @return <CODE>true</CODE> if the notification should be sent to the listener, <CODE>false</CODE> otherwise.
060:             */
061:            public synchronized boolean isNotificationEnabled(
062:                    Notification notification) {
063:
064:                String type = notification.getType();
065:                if (type == null)
066:                    return false;
067:
068:                for (Iterator iter = enabledTypes.iterator(); iter.hasNext();) {
069:                    String prefix = (String) iter.next();
070:                    if (type.startsWith(prefix)) {
071:                        return true;
072:                    }
073:                }
074:
075:                return false;
076:            }
077:
078:            /**
079:             * Enables all the notifications the type of which starts with the specified prefix
080:             * to be sent to the listener.
081:             * <BR>If the specified prefix is already in the list of enabled notification types,
082:             * this method has no effect.
083:             * <P>
084:             * Example:
085:             * <BLOCKQUOTE>
086:             * <PRE>
087:             * // Enables all notifications the type of which starts with "my_example" to be sent.
088:             * myFilter.enableType("my_example");
089:             * // Enables all notifications the type of which is "my_example.my_type" to be sent.
090:             * myFilter.enableType("my_example.my_type");
091:             * </PRE>
092:             * </BLOCKQUOTE>
093:             *
094:             * Note that:
095:             * <BLOCKQUOTE><CODE>
096:             * myFilter.enableType("my_example.*");
097:             * </CODE></BLOCKQUOTE>
098:             * will no match any notification type.
099:             *
100:             * @param prefix The prefix.
101:             * @exception java.lang.IllegalArgumentException The prefix parameter is null.
102:             */
103:            public synchronized void enableType(String prefix)
104:                    throws java.lang.IllegalArgumentException {
105:
106:                if (prefix == null) {
107:                    throw new java.lang.IllegalArgumentException(
108:                            "The prefix cannot be null.");
109:                }
110:                if (!enabledTypes.contains(prefix)) {
111:                    enabledTypes.add(prefix);
112:                }
113:            }
114:
115:            /**
116:             * Disables all notifications the type of which starts with the specified prefix
117:             * to be sent to the listener.
118:             * <BR>If the specified prefix is not in the list of enabled notification types,
119:             * this method has no effect.
120:             *
121:             * @param prefix The prefix.
122:             */
123:            public synchronized void disableType(String prefix) {
124:                enabledTypes.remove(prefix);
125:            }
126:
127:            /**
128:             * Disables all notification types.
129:             */
130:            public synchronized void disableAllTypes() {
131:                enabledTypes.clear();
132:            }
133:
134:            /**
135:             * Gets all the enabled notification types for this filter.
136:             *
137:             * @return The list containing all the enabled notification types.
138:             */
139:            public synchronized Vector getEnabledTypes() {
140:                return new Vector(enabledTypes);
141:            }
142:
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.