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


001:        /**
002:         * Copyright (C) The MX4J Contributors.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the MX4J License version 1.0.
006:         * See the terms of the MX4J License in the documentation provided with this software.
007:         */package javax.management;
008:
009:        import java.io.IOException;
010:        import java.io.ObjectInputStream;
011:        import java.io.ObjectOutputStream;
012:        import java.io.ObjectStreamField;
013:        import java.io.Serializable;
014:        import java.util.HashSet;
015:        import java.util.Iterator;
016:        import java.util.List;
017:        import java.util.Vector;
018:
019:        /**
020:         * Default implementation of a NotificationListener that filters out Notifications that
021:         * does not match the types enabled in this filter.
022:         *
023:         * @version $Revision: 1.11 $
024:         */
025:        // Change not needed, workaround to a TCK bug only to achieve TCK compliance
026:        // public class NotificationFilterSupport implements NotificationFilter
027:        public class NotificationFilterSupport implements  NotificationFilter,
028:                Serializable {
029:            private static final long serialVersionUID = 6579080007561786969L;
030:
031:            private static final String serialName = "enabledTypes";
032:            /**
033:             * @serialField enabledTypes List The list of notification types that this filter will not filter out
034:             */
035:            private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
036:                    serialName, List.class) };
037:
038:            private HashSet types = new HashSet();
039:
040:            public boolean equals(Object o) {
041:                if (this  == o)
042:                    return true;
043:                if (!(o instanceof  NotificationFilterSupport))
044:                    return false;
045:
046:                final NotificationFilterSupport support = (NotificationFilterSupport) o;
047:
048:                if (!types.equals(support.types))
049:                    return false;
050:
051:                return true;
052:            }
053:
054:            public int hashCode() {
055:                return types.hashCode();
056:            }
057:
058:            /**
059:             * Allows the given notification type to be received by listeners
060:             *
061:             * @param type The notification type to enable
062:             * @throws IllegalArgumentException If the notification type is null
063:             */
064:            public void enableType(String type) throws IllegalArgumentException {
065:                if (type == null)
066:                    throw new IllegalArgumentException("Null notification type");
067:                synchronized (types) {
068:                    types.add(type);
069:                }
070:            }
071:
072:            /**
073:             * Forbids all notification types to be received by listeners
074:             */
075:            public void disableAllTypes() {
076:                synchronized (types) {
077:                    types.clear();
078:                }
079:            }
080:
081:            /**
082:             * Forbids the gven notification type to be received by listeners
083:             *
084:             * @param type The notification type to disable
085:             */
086:            public void disableType(String type) {
087:                synchronized (types) {
088:                    types.remove(type);
089:                }
090:            }
091:
092:            /**
093:             * Returns the notification type that are not filtered out by this filter
094:             */
095:            public Vector getEnabledTypes() {
096:                Vector v = new Vector();
097:                synchronized (types) {
098:                    v.addAll(types);
099:                }
100:                return v;
101:            }
102:
103:            /**
104:             * Filters out notifications whose type is not enabled in this filter.
105:             *
106:             * @param notification The notification to filter
107:             * @return True if the notification should be delivered to the listener, false otherwise
108:             */
109:            public boolean isNotificationEnabled(Notification notification) {
110:                String type = notification.getType();
111:                if (type != null) {
112:                    for (Iterator i = getEnabledTypes().iterator(); i.hasNext();) {
113:                        String t = (String) i.next();
114:                        if (type.startsWith(t))
115:                            return true;
116:                    }
117:                }
118:                return false;
119:            }
120:
121:            private void readObject(ObjectInputStream in) throws IOException,
122:                    ClassNotFoundException {
123:                ObjectInputStream.GetField fields = in.readFields();
124:
125:                Vector vector = (Vector) fields.get(serialName, null);
126:                if (fields.defaulted(serialName)) {
127:                    throw new IOException(
128:                            "Serialized stream corrupted: expecting a non-null Vector");
129:                }
130:
131:                if (types == null)
132:                    types = new HashSet();
133:                types.clear();
134:                types.addAll(vector);
135:            }
136:
137:            private void writeObject(ObjectOutputStream out) throws IOException {
138:                ObjectOutputStream.PutField fields = out.putFields();
139:
140:                Vector vector = getEnabledTypes();
141:                fields.put(serialName, vector);
142:                out.writeFields();
143:            }
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.