Source Code Cross Referenced for ModelMBeanNotificationInfo.java in  » JMX » jfoxmx » javax » management » modelmbean » 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.modelmbean 
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.modelmbean;
009:
010:        import javax.management.RuntimeOperationsException;
011:        import javax.management.Descriptor;
012:        import javax.management.DescriptorAccess;
013:        import javax.management.MBeanNotificationInfo;
014:
015:        /**
016:         * The ModelMBeanNotificationInfo object describes a notification emitted by a ModelMBean.
017:         * It is a subclass of MBeanNotificationInfo with the addition of an associated Descriptor
018:         * and an implementation of the Descriptor interface.
019:         * <P>
020:         * <PRE>
021:         * The fields in the descriptor are defined, but not limited to, the following: <P>
022:         * name           : notification name <P>
023:         * descriptorType : must be "notification"   <P>
024:         * severity       : 1-5 where 1: fatal 2: severe 3: error 4: warn 5: info  <P>
025:         * messageID      : unique key for message text (to allow translation,analysis)  <P>
026:         * messageText    : text of notification   <P>
027:         * log            : T - log message F - do not log message   <P>
028:         * logfile        : string fully qualified file name appropriate for operating system<P>
029:         * visibility     : 1-4 where 1: always visible 4: rarely visible   <P>
030:         * presentationString : xml formatted string to allow presentation of data  <P>
031:         * </PRE>
032:         * The default descriptor contains the name, descriptorType, and severity=5 fields.
033:         *
034:         * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
035:         */
036:
037:        public class ModelMBeanNotificationInfo extends MBeanNotificationInfo
038:                implements  DescriptorAccess, Cloneable {
039:
040:            private Descriptor descriptor;
041:
042:            /**
043:             * Constructs a ModelMBeanNotificationInfo object with a default descxriptor.
044:             *
045:             * @param types The notification type string (in dot notation).
046:             * @param name The name of the Notification class.
047:             * @param description A human readable description of the Notification. Optional.
048:             * <P>
049:             * The descriptor must be set before this
050:             * ModelMBeanNotificationInfo instance can be used.
051:             */
052:            public ModelMBeanNotificationInfo(String[] types, String name,
053:                    String description) {
054:                super (types, name, description);
055:                descriptor = createDefaultDescriptor();
056:            }
057:
058:            /**
059:             * Constructs a ModelMBeanNotificationInfo object.
060:             *
061:             * @param types The notification type string (in dot notation).
062:             * @param name The name of the Notification class.
063:             * @param description A human readable description of the Notification. Optional.
064:             * @param descriptor An instance of Descriptor containing the appropriate metadata
065:             *                   for this instance of the MBeanNotificationInfo.If it is null or invalid then
066:             *					a default desriptor will be created.
067:             *
068:             */
069:            public ModelMBeanNotificationInfo(String[] types, String name,
070:                    String description, Descriptor descriptor) {
071:                super (types, name, description);
072:                setDescriptor(descriptor);
073:            }
074:
075:            /**
076:             * Constructs a new ModelMBeanNotificationInfo object from this ModelMBeanNotfication Object.
077:             *
078:             * @param notifInfo the ModelMBeanNotificationInfo to be duplicated
079:             *
080:             */
081:            public ModelMBeanNotificationInfo(
082:                    ModelMBeanNotificationInfo notifInfo) {
083:                super (notifInfo.getNotifTypes(), notifInfo.getName(), notifInfo
084:                        .getDescription());
085:                descriptor = notifInfo.getDescriptor();
086:            }
087:
088:            /**
089:             * Creates and returns a new ModelMBeanNotificationInfo which is a duplicate of this ModelMBeanNotificationInfo.
090:             *
091:             */
092:            public Object clone() {
093:                return new ModelMBeanNotificationInfo(this );
094:            }
095:
096:            /**
097:             * Returns a copy of the associated Descriptor for the ModelMBeanNotificationInfo
098:             *
099:             * @return Descriptor associated with the ModelMBeanNotificationInfo object.
100:             */
101:            public Descriptor getDescriptor() {
102:                return (Descriptor) descriptor.clone();
103:            }
104:
105:            /**
106:             * Sets associated Descriptor (full replace)  for the ModelMBeanNotificationInfo
107:             * If the new Descriptor is null, then the associated Descriptor reverts to
108:             * a default descriptor.  The Descriptor is validated before it is assigned.  If
109:             * the new Descriptor is invalid, then an IllegalArgumentException is thrown.
110:             *
111:             * @param descriptor - replaces the Descriptor associated with the
112:             * ModelMBeanNotification interface
113:             *
114:             */
115:            public void setDescriptor(Descriptor descriptor) {
116:                //    System.out.println("ModelMBeanNitificationInfo:50 " + descriptor +  descriptor.isValidDescriptor() + descriptor.getFieldValue(DescriptorConstants.NAME) + " " + getNameSpace());
117:                if (descriptor == null) {
118:                    this .descriptor = createDefaultDescriptor();
119:                } else if (isValidDescriptor(descriptor))
120:                    this .descriptor = (Descriptor) descriptor.clone();
121:                else
122:                    throw new RuntimeOperationsException(
123:                            new IllegalArgumentException(
124:                                    "Invalid descriptor passed in parameter"),
125:                            "Exception occured in ModelMBeanNotificationInfo setDescriptor");
126:            }
127:
128:            /**
129:             * Returns a human readable string containing ModelMBeanNotificationInfo
130:             *
131:             * @exception RuntimeOperationsException for illegal value for field URLName or field Values.
132:             *              If the descriptor string fails for any reason, this exception will be thrown.
133:             */
134:            public String toString() {
135:                String desc = "ModelMBeanNotificationInfo: " + getName()
136:                        + " ; Description: " + getDescription()
137:                        + " ; Descriptor: " + getDescriptor() + " ; Types: ";
138:                String[] types = getNotifTypes();
139:                for (int i = 0; i < types.length; i++)
140:                    desc += types[i] + ", ";
141:
142:                return desc;
143:            }
144:
145:            /**
146:             * Creates default descriptor for notification as follows:
147:             * descriptorType=notification,
148:             * name=this.getNameSpace(),displayname=this.getNameSpace(),log=F,severity=5,visibility=1
149:             */
150:            private Descriptor createDefaultDescriptor() {
151:                return new DescriptorSupport(
152:                        new String[] {
153:                                DescriptorConstants.DESCRIPTORTYPE + "="
154:                                        + DescriptorConstants.NOTIFICATION_TYPE,
155:                                DescriptorConstants.NAME + "=" + getName(),
156:                                DescriptorConstants.DISPLAYNAME + "="
157:                                        + getName(),
158:                                DescriptorConstants.NOTIFICATION_SEVERITY
159:                                        + "="
160:                                        + DescriptorConstants.NOTIFICATION_SEVERITY_WARN });
161:            }
162:
163:            /**
164:             * Tests that the descriptor is valid and adds appropriate default fields not already
165:             * specified. Field values must be correct for field names.
166:             * Descriptor must have the same name as the notification,the descriptorType field must be "notification",
167:             * The following fields will be defaulted if they are not already set:
168:             * displayName=this.getNameSpace(),displayname=this.getNameSpace(),log=F,severity=5,visibility=1
169:             */
170:            private boolean isValidDescriptor(Descriptor descriptor) {
171:                boolean isValid = true;
172:                if (descriptor == null) {
173:                    return false;
174:                }
175:                if (!descriptor.isValid()) {
176:                    isValid = false;
177:                } else {
178:                    if (!((String) descriptor
179:                            .getFieldValue(DescriptorConstants.NAME))
180:                            .equalsIgnoreCase(getName())) {
181:                        isValid = false;
182:                    }
183:                    if (!((String) descriptor
184:                            .getFieldValue(DescriptorConstants.DESCRIPTORTYPE))
185:                            .equalsIgnoreCase(DescriptorConstants.NOTIFICATION_TYPE)) {
186:                        isValid = false;
187:                    }
188:                    if (descriptor
189:                            .getFieldValue(DescriptorConstants.DISPLAYNAME) == null)
190:                        descriptor.setField(DescriptorConstants.DISPLAYNAME,
191:                                getName());
192:                    if (descriptor
193:                            .getFieldValue(DescriptorConstants.NOTIFICATION_SEVERITY) == null)
194:                        descriptor.setField(
195:                                DescriptorConstants.NOTIFICATION_SEVERITY,
196:                                "" + DescriptorConstants.NOTIFICATION_SEVERITY);
197:                }
198:                return isValid;
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.