Source Code Cross Referenced for NotificationFilterSupport.java in  » JMX » XMOJO » 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 » XMOJO » javax.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * The XMOJO Project 5
003:         * Copyright © 2003 XMOJO.org. All rights reserved.
004:
005:         * NO WARRANTY
006:
007:         * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
008:         * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
009:         * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
010:         * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
011:         * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
012:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
013:         * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
014:         * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
015:         * REPAIR OR CORRECTION.
016:
017:         * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
018:         * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
019:         * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
020:         * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
021:         * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
022:         * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
023:         * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
024:         * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
025:         * SUCH DAMAGES.
026:         **/package javax.management;
027:
028:        import java.io.Serializable;
029:        import java.util.Vector;
030:
031:        /**
032:         * Provides an implementation of the {@link javax.management.NotificationFilter}
033:         * interface. The filtering is performed on the notification type attribute.
034:         * <P>
035:         * This class 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
040:         * notification types enabled by the filter. The notification will be sent to
041:         * the listener 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
052:         * the type of which equals/starts with "my_example.my_type".
053:         *
054:         * @see javax.management.NotificationBroadcaster#addNotificationListener
055:         */
056:        public class NotificationFilterSupport implements  NotificationFilter,
057:                Serializable {
058:            /**
059:             * Vector that contains the enabled notification types.
060:             * The default value is an empty vector.
061:             */
062:            protected Vector enabledTypes = null;
063:
064:            /**
065:             * Creates a NotificationFilterSupport
066:             * Default constructor
067:             */
068:            public NotificationFilterSupport() {
069:                enabledTypes = new Vector();
070:            }
071:
072:            /**
073:             * Invoked before sending the specified notification to the listener.
074:             * This filter compares the notification type with each enabled type.
075:             * If the notification type matches one of the enabled type, the
076:             * notification has to be sent to the listener and this method returns true.
077:             *
078:             * @param notification The notification to be sent.
079:             *
080:             * @return True if the notification has to be sent to the listener, false otherwise.
081:             */
082:            public boolean isNotificationEnabled(Notification notification) {
083:                if (notification == null)
084:                    return false;
085:
086:                String type = notification.getType();
087:
088:                for (int i = 0; i < enabledTypes.size(); i++) {
089:                    String str = (String) enabledTypes.elementAt(i);
090:
091:                    if (type.toLowerCase().startsWith(str.toLowerCase()))
092:                        return true;
093:                }
094:
095:                return false;
096:            }
097:
098:            /**
099:             * Disables all the notification types.
100:             */
101:            public void disableAllTypes() {
102:                enabledTypes.removeAllElements();
103:            }
104:
105:            /**
106:             * Disables all the notifications whose type matches the specified prefix
107:             * to be sent to the listener. If the specified prefix is not in the list
108:             * of enabled notification types, this method has no effect.
109:             *
110:             * @param prefix The prefix.
111:             */
112:            public void disableType(String prefix) {
113:                if (prefix == null)
114:                    return;
115:
116:                for (int i = 0; i < enabledTypes.size(); i++) {
117:                    String str = (String) enabledTypes.elementAt(i);
118:
119:                    if (str.toLowerCase().startsWith(prefix.toLowerCase()))
120:                        enabledTypes.removeElementAt(i);
121:                }
122:            }
123:
124:            /**
125:             * Enables all the notifications whose type matches the specified prefix
126:             * to be sent to the listener. If the specified prefix is already in the
127:             * list of enabled notification types, this method has no effect.
128:             *
129:             * @param prefix The prefix.
130:             *
131:             * @throws IllegalArgumentException The prefix parameter is null.
132:             */
133:            public void enableType(String prefix)
134:                    throws IllegalArgumentException {
135:                if (prefix == null)
136:                    throw new IllegalArgumentException(prefix);
137:
138:                boolean flag = false;
139:
140:                for (int i = 0; i < enabledTypes.size(); i++) {
141:                    String str = (String) enabledTypes.elementAt(i);
142:
143:                    if (prefix.toLowerCase().startsWith(str.toLowerCase()))
144:                        flag = true;
145:                    else if (str.toLowerCase().startsWith(prefix.toLowerCase()))
146:                        enabledTypes.removeElementAt(i);
147:                }
148:
149:                if (!flag)
150:                    enabledTypes.add(prefix);
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 Vector getEnabledTypes() {
159:                return enabledTypes;
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.