Source Code Cross Referenced for MBeanUtils.java in  » ESB » open-esb » com » sun » jbi » util » jmx » 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 » ESB » open esb » com.sun.jbi.util.jmx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)MBeanUtils.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.util.jmx;
030:
031:        import com.sun.jbi.util.LocalStringKeys;
032:        import com.sun.jbi.util.StringTranslator;
033:
034:        import javax.management.MBeanServer;
035:        import javax.management.ObjectName;
036:        import javax.management.StandardMBean;
037:
038:        /**
039:         * Helper class for frequently used MBean housekeeping. This is a static
040:         * class that must have a reference to the MBean server currently being used.
041:         * Early in the initialization of the JBI framework, the MBean server reference
042:         * is set by the framework, before any other JBI services are initialized. This
043:         * ensures that the MBean server reference will always be available. While not
044:         * an ideal design, in the context of the JBI runtime, this is a workable
045:         * solution and prevents every caller from having to have a reference to the
046:         * MBean server.
047:         *
048:         * @author Sun Microsystems, Inc.
049:         */
050:        public class MBeanUtils {
051:            /**
052:             * Local handle to MBean Server.
053:             */
054:            private static MBeanServer sMBeanServer;
055:
056:            /**
057:             * Local handle to StringTranslator.
058:             */
059:            private static StringTranslator sTranslator;
060:
061:            /**
062:             * Initialize the static data. This method is called by the framework
063:             * during initialization so that all other code can use the other methods
064:             * in the class at any time. This is also used by the ProxyBinding as it
065:             * has its own classloader so it needs to initialize the same static data.
066:             * @param server The MBean Server reference to be used.
067:             */
068:            public static void init(MBeanServer server) {
069:                if (null == server) {
070:                    throw new java.lang.IllegalArgumentException(sTranslator
071:                            .getString(LocalStringKeys.NULL_ARGUMENT, "server"));
072:                }
073:
074:                sMBeanServer = server;
075:                sTranslator = new StringTranslator("com.sun.jbi.util", null);
076:            }
077:
078:            /**
079:             * Create and register a standard MBean with the main MBean Server.
080:             * @param interfaceClass the MBean interface implemented by the instance.
081:             * @param instance the MBean implementation instance.
082:             * @param mbeanName the JMX ObjectName for the MBean.
083:             * @param replace indicates whether an existing registration should be
084:             * replaced or cause an error. If true, an existing registration should be
085:             * replaced; if false, an existing registration should cause an error.
086:             * @throws javax.jbi.JBIException If the MBean creation or registration
087:             * fails.
088:             */
089:            public static void registerStandardMBean(Class interfaceClass,
090:                    Object instance, ObjectName mbeanName, boolean replace)
091:                    throws javax.jbi.JBIException {
092:                if (null == sMBeanServer) {
093:                    return;
094:                }
095:
096:                // Create a StandardMBean for the MBean instance.
097:
098:                StandardMBean mbean = null;
099:                try {
100:                    mbean = new StandardMBean(instance, interfaceClass);
101:                } catch (javax.management.NotCompliantMBeanException ncEx) {
102:                    throw new javax.jbi.JBIException(sTranslator.getString(
103:                            LocalStringKeys.MBEAN_CREATION_NOT_JMX_COMPLIANT,
104:                            mbeanName, instance.getClass().getName()));
105:                }
106:
107:                // If an existing registration should be replaced, remove any existing
108:                // registration first.
109:
110:                if (replace) {
111:                    if (sMBeanServer.isRegistered(mbeanName)) {
112:                        try {
113:                            sMBeanServer.unregisterMBean(mbeanName);
114:                        } catch (javax.management.InstanceNotFoundException infEx) {
115:                            ; // Just ignore this error
116:                        } catch (javax.management.MBeanRegistrationException mbrEx) {
117:                            String msg = mbrEx.getMessage();
118:                            Throwable cause = mbrEx.getCause();
119:                            String causeName = cause.getClass().getName();
120:                            throw new javax.jbi.JBIException(
121:                                    sTranslator
122:                                            .getString(
123:                                                    LocalStringKeys.MBEAN_UNREGISTRATION_EXCEPTION,
124:                                                    mbeanName, causeName,
125:                                                    null == msg ? "" : msg),
126:                                    mbrEx);
127:                        }
128:                    }
129:                }
130:
131:                // Register the MBean.
132:
133:                try {
134:                    sMBeanServer.registerMBean(mbean, mbeanName);
135:                } catch (javax.management.InstanceAlreadyExistsException iaeEx) {
136:                    throw new javax.jbi.JBIException(sTranslator
137:                            .getString(
138:                                    LocalStringKeys.MBEAN_ALREADY_REGISTERED,
139:                                    mbeanName));
140:                } catch (javax.management.MBeanRegistrationException mbrEx) {
141:                    String msg = mbrEx.getMessage();
142:                    Throwable cause = mbrEx.getCause();
143:                    String causeName = cause.getClass().getName();
144:                    throw new javax.jbi.JBIException(sTranslator.getString(
145:                            LocalStringKeys.MBEAN_REGISTRATION_EXCEPTION,
146:                            mbeanName, causeName, null == msg ? "" : msg),
147:                            mbrEx);
148:                } catch (javax.management.NotCompliantMBeanException ncEx) {
149:                    throw new javax.jbi.JBIException(
150:                            sTranslator
151:                                    .getString(
152:                                            LocalStringKeys.MBEAN_REGISTRATION_NOT_JMX_COMPLIANT,
153:                                            mbeanName, instance.getClass()
154:                                                    .getName()));
155:                }
156:            }
157:
158:            /**
159:             * Unregister an MBean from the MBean server.
160:             * @param mbeanName the JMX ObjectName for the MBean.
161:             * @throws javax.jbi.JBIException if the unregistration fails.
162:             */
163:            public static void unregisterMBean(ObjectName mbeanName)
164:                    throws javax.jbi.JBIException {
165:                if (null == sMBeanServer) {
166:                    return;
167:                }
168:
169:                // Unregister the MBean
170:
171:                try {
172:                    sMBeanServer.unregisterMBean(mbeanName);
173:                } catch (javax.management.InstanceNotFoundException infEx) {
174:                    ; // Just ignore this error
175:                } catch (javax.management.MBeanRegistrationException mbrEx) {
176:                    String msg = mbrEx.getMessage();
177:                    Throwable cause = mbrEx.getCause();
178:                    String causeName = cause.getClass().getName();
179:                    throw new javax.jbi.JBIException(sTranslator.getString(
180:                            LocalStringKeys.MBEAN_UNREGISTRATION_EXCEPTION,
181:                            mbeanName, causeName, null == msg ? "" : msg),
182:                            mbrEx);
183:                }
184:            }
185:
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.