Source Code Cross Referenced for MBeanServerNotificationFilter.java in  » JMX » mx4j » javax » management » relation » 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.relation 
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.relation;
008:
009:        import java.io.IOException;
010:        import java.io.ObjectInputStream;
011:        import java.io.ObjectOutputStream;
012:        import java.io.ObjectStreamField;
013:        import java.util.HashSet;
014:        import java.util.List;
015:        import java.util.Vector;
016:        import javax.management.MBeanServerNotification;
017:        import javax.management.Notification;
018:        import javax.management.NotificationFilterSupport;
019:        import javax.management.ObjectName;
020:
021:        /**
022:         * @version $Revision: 1.7 $
023:         */
024:        public class MBeanServerNotificationFilter extends
025:                NotificationFilterSupport {
026:            private static final long serialVersionUID = 2605900539589789736L;
027:            private static final String[] serialNames = { "selectedNames",
028:                    "deselectedNames" };
029:            private static final ObjectStreamField[] serialPersistentFields = {
030:                    new ObjectStreamField(serialNames[0], List.class),
031:                    new ObjectStreamField(serialNames[1], List.class) };
032:
033:            private HashSet m_disabledObjectNames;
034:            private HashSet m_enabledObjectNames;
035:
036:            public MBeanServerNotificationFilter() {
037:                enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
038:                enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
039:
040:                // By default all disabled
041:                disableAllObjectNames();
042:            }
043:
044:            public int hashCode() {
045:                int result = (m_disabledObjectNames != null ? m_disabledObjectNames
046:                        .hashCode()
047:                        : 0);
048:                result = 29
049:                        * result
050:                        + (m_enabledObjectNames != null ? m_enabledObjectNames
051:                                .hashCode() : 0);
052:                return result;
053:            }
054:
055:            public boolean equals(Object obj) {
056:                if (this  == obj)
057:                    return true;
058:                if (!(obj instanceof  MBeanServerNotificationFilter))
059:                    return false;
060:
061:                MBeanServerNotificationFilter other = (MBeanServerNotificationFilter) obj;
062:
063:                if (m_disabledObjectNames != null ? !m_disabledObjectNames
064:                        .equals(other.m_disabledObjectNames)
065:                        : other.m_disabledObjectNames != null)
066:                    return false;
067:                if (m_enabledObjectNames != null ? !m_enabledObjectNames
068:                        .equals(other.m_enabledObjectNames)
069:                        : other.m_enabledObjectNames != null)
070:                    return false;
071:
072:                return true;
073:            }
074:
075:            public void disableAllObjectNames() {
076:                // Clear the enabled ones, and...
077:                if (m_enabledObjectNames == null) {
078:                    m_enabledObjectNames = new HashSet();
079:                } else {
080:                    m_enabledObjectNames.clear();
081:                }
082:                // ...reset the disabled ones
083:                m_disabledObjectNames = null;
084:            }
085:
086:            public void enableAllObjectNames() {
087:                // Clear the disabled ones, and...
088:                if (m_disabledObjectNames == null) {
089:                    m_disabledObjectNames = new HashSet();
090:                } else {
091:                    m_disabledObjectNames.clear();
092:                }
093:                // ...reset the enabled ones
094:                m_enabledObjectNames = null;
095:            }
096:
097:            public void enableObjectName(ObjectName name)
098:                    throws IllegalArgumentException {
099:                if (name == null) {
100:                    throw new IllegalArgumentException(
101:                            "ObjectName cannot be null");
102:                }
103:
104:                // Remove from disabled if present
105:                if (m_disabledObjectNames != null
106:                        && m_disabledObjectNames.size() > 0) {
107:                    m_disabledObjectNames.remove(name);
108:                }
109:
110:                // If not enableAll, add it to the list
111:                if (m_enabledObjectNames != null) {
112:                    m_enabledObjectNames.add(name);
113:                }
114:            }
115:
116:            public void disableObjectName(ObjectName name)
117:                    throws IllegalArgumentException {
118:                if (name == null) {
119:                    throw new IllegalArgumentException(
120:                            "ObjectName cannot be null");
121:                }
122:
123:                // Remove from enabled if present
124:                if (m_enabledObjectNames != null
125:                        && m_enabledObjectNames.size() > 0) {
126:                    m_enabledObjectNames.remove(name);
127:                }
128:
129:                // If not disableAll, add it to the list
130:                if (m_disabledObjectNames != null) {
131:                    m_disabledObjectNames.add(name);
132:                }
133:            }
134:
135:            public Vector getEnabledObjectNames() {
136:                if (m_enabledObjectNames == null) {
137:                    return null;
138:                }
139:                Vector v = new Vector();
140:                v.addAll(m_enabledObjectNames);
141:                return v;
142:            }
143:
144:            public Vector getDisabledObjectNames() {
145:                if (m_disabledObjectNames == null) {
146:                    return null;
147:                }
148:                Vector v = new Vector();
149:                v.addAll(m_disabledObjectNames);
150:                return v;
151:            }
152:
153:            public boolean isNotificationEnabled(Notification notification) {
154:                boolean goOn = super .isNotificationEnabled(notification);
155:
156:                if (goOn) {
157:                    if (notification instanceof  MBeanServerNotification) {
158:                        MBeanServerNotification n = (MBeanServerNotification) notification;
159:                        ObjectName name = n.getMBeanName();
160:
161:                        if (m_enabledObjectNames == null) {
162:                            // All enabled, check the disabled ones
163:                            if (m_disabledObjectNames != null
164:                                    && m_disabledObjectNames.contains(name)) {
165:                                // All enabled apart this one
166:                                return false;
167:                            } else {
168:                                return true;
169:                            }
170:                        } else {
171:                            // Only some is enabled
172:                            if (m_enabledObjectNames.contains(name)) {
173:                                // This one is enabled
174:                                return true;
175:                            } else {
176:                                // This one is not enabled
177:                                return false;
178:                            }
179:                        }
180:                    }
181:                }
182:
183:                return false;
184:            }
185:
186:            private void readObject(ObjectInputStream in) throws IOException,
187:                    ClassNotFoundException {
188:                ObjectInputStream.GetField fields = in.readFields();
189:
190:                Vector vector = (Vector) fields.get(serialNames[0], null);
191:                if (fields.defaulted(serialNames[0])) {
192:                    throw new IOException(
193:                            "Serialized stream corrupted: expecting a non-null Vector");
194:                }
195:                if (vector != null) {
196:                    if (m_enabledObjectNames == null) {
197:                        m_enabledObjectNames = new HashSet();
198:                    }
199:                    m_enabledObjectNames.clear();
200:                    m_enabledObjectNames.addAll(vector);
201:                }
202:
203:                vector = (Vector) fields.get(serialNames[1], null);
204:                if (fields.defaulted(serialNames[1])) {
205:                    throw new IOException(
206:                            "Serialized stream corrupted: expecting a non-null Vector");
207:                }
208:                if (vector != null) {
209:                    if (m_disabledObjectNames == null) {
210:                        m_disabledObjectNames = new HashSet();
211:                    }
212:                    m_disabledObjectNames.clear();
213:                    m_disabledObjectNames.addAll(vector);
214:                }
215:            }
216:
217:            private void writeObject(ObjectOutputStream out) throws IOException {
218:                ObjectOutputStream.PutField fields = out.putFields();
219:
220:                Vector vector = getEnabledObjectNames();
221:                fields.put(serialNames[0], vector);
222:
223:                vector = getDisabledObjectNames();
224:                fields.put(serialNames[1], vector);
225:
226:                out.writeFields();
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.