KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > meta > MBeanRegistryFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * $Id: MBeanRegistryFactory.java,v 1.3 2005/12/25 03:47:38 tcfujii Exp $
26  * @author: alexkrav
27  *
28  * $Log: MBeanRegistryFactory.java,v $
29  * Revision 1.3 2005/12/25 03:47:38 tcfujii
30  * Updated copyright text and year.
31  *
32  * Revision 1.2 2005/06/27 21:19:44 tcfujii
33  * Issue number: CDDL header updates.
34  *
35  * Revision 1.1.1.1 2005/05/27 22:52:02 dpatil
36  * GlassFish first drop
37  *
38  * Revision 1.10 2004/11/14 07:04:21 tcfujii
39  * Updated copyright text and/or year.
40  *
41  * Revision 1.9 2004/05/22 00:35:07 kravtch
42  * "system-properties" backend support is added
43  * Reviewer: Sridatta
44  * Tests passed: QLT/CTS PE
45  *
46  * Revision 1.8 2004/03/02 18:26:33 kravtch
47  * MBean's Descriptor field ElementChangeEvent support added (Constant, get method).
48  * MBeanRegistryFactory.setAdminMBeanRegistry() added for tester
49  *
50  * Revision 1.7 2004/02/20 03:56:14 qouyang
51  *
52  *
53  * First pass at code merge.
54  *
55  * Details for the merge will be published at:
56  * http://javaweb.sfbay.sun.com/~qouyang/workspace/PE8FCSMerge/02202004/
57  *
58  * Revision 1.6.4.1 2004/02/02 07:25:19 tcfujii
59  * Copyright updates notices; reviewer: Tony Ng
60  *
61  * Revision 1.6 2003/09/04 05:53:49 kravtch
62  * bugs #4896268 and #4913653
63  * Reviewer: Sridatta
64  * -AuthRealmMbean's getFielRealm is chaged from creating of the new FileRealm object to gettting it from security pool - Realm.getInstance(name) with casting result to FileRealm.
65  * This approach will work only for PE because DAS and instance have the same auth-realms.
66  * -AdminContext expanded by two new methods getAdminMBeanResourcUrl() and getRuntimeMBeanResourcUrl() which used by MBeanRegistryFactory for initialization admin and runtime registries. So, they are become pluggable.
67  * -AdminContext also notifies MBeanRegistryFactory during its construction. So, AdminContext become "visible" to admin-core/admin classes.
68  * -Hardcoded output changed to appropriate logger calls.
69  *
70  * Revision 1.5 2003/07/29 18:59:35 kravtch
71  * MBeanRegistryEntry:
72  * - support for toFormatString();
73  * - instantiateMBean() method modified to instantiate runtime MBeans as well;
74  * MBeanRegistryFactory:
75  * - fixed bug in getRuntimeRegistry();
76  * MBeanNamingInfo:
77  * - less strict requirements for parm_list_array size in constructor (can be more then needed);
78  * BaseRuntimeMBean:
79  * - exception ClassCastException("Managed resource is not a Jsr77ModelBean") handling;
80  * ManagedJsr77MdlBean:
81  * - call managed bean bug fixed ( getDeclaredMethod()->getMethod())
82  * admin/dtds/runtime-mbeans-descriptors.xml - modified to represent new runtime mbeans;
83  *
84  * Revision 1.4 2003/07/18 20:14:44 kravtch
85  * 1. ALL config mbeans are now covered by descriptors.xml
86  * 2. new infrastructure for runtime mbeans is added
87  * 3. generic constructors added to jsr77Mdl beans (String[])
88  * 4. new test cases are added to admintest
89  * 5. MBeanRegistryFactory has now different methods to obtain admin/runtime registries
90  * 6. runtime-descriptors xml-file is added to build
91  *
92  * Revision 1.3 2003/06/25 20:03:40 kravtch
93  * 1. java file headers modified
94  * 2. properties handling api is added
95  * 3. fixed bug for xpathes containing special symbols;
96  * 4. new testcases added for jdbc-resource
97  * 5. introspector modified by not including base classes operations;
98  *
99  *
100 */

101
102 package com.sun.enterprise.admin.meta;
103
104 import java.io.InputStream JavaDoc;
105 import java.io.FileInputStream JavaDoc;
106 import java.io.PrintWriter JavaDoc;
107 import java.io.BufferedWriter JavaDoc;
108 import java.io.FileWriter JavaDoc;import java.net.URL JavaDoc;
109
110 import java.util.logging.Level JavaDoc;
111 import java.util.logging.Logger JavaDoc;
112 import com.sun.logging.LogDomains;
113
114 import com.sun.enterprise.admin.meta.naming.MBeansNaming;
115 import com.sun.enterprise.admin.AdminContext;
116 /**
117  * Provides naming support for Mbeans
118  */

119 public class MBeanRegistryFactory
120 {
121     private static MBeanRegistry adminRegistry = null;
122     private static MBeanRegistry runtimeRegistry = null;
123     private static AdminContext adminContext = null;
124
125     static protected Logger JavaDoc _sLogger = LogDomains.getLogger(LogDomains.ADMIN_LOGGER);
126     
127     static public void setAdminContext(AdminContext ctx)
128     {
129         adminContext = ctx;
130     }
131     
132     static public AdminContext getAdminContext()
133     {
134         return adminContext;
135     }
136     
137     static public void setAdminMBeanRegistry(MBeanRegistry registry)
138     { //for tester purposes
139
adminRegistry = registry;
140     }
141     
142     static public MBeanRegistry getAdminMBeanRegistry()
143     {
144         if(adminRegistry != null)
145             return adminRegistry;
146         try {
147             URL JavaDoc url = null;
148             if(adminContext!=null)
149                 url = adminContext.getAdminMBeanRegistryURL();
150             if(url==null)
151                url = MBeanRegistry.class.getResource("/admin-mbeans-descriptors.xml"); //standard for pe
152
InputStream JavaDoc stream = url.openStream();
153             adminRegistry = new MBeanRegistry();
154             adminRegistry.loadMBeanRegistry(stream);
155             stream.close();
156             //printMBeanREgistry
157
try {
158                 String JavaDoc fileName = System.getProperty("adminmbeanregistry.printfile");
159                 if(fileName!=null)
160                 {
161                     PrintWriter JavaDoc out = new PrintWriter JavaDoc(new BufferedWriter JavaDoc(new FileWriter JavaDoc(fileName)));
162                     out.println("MBean REGISTRY (in XPath value order)");
163                     adminRegistry.sortRegistryEntries(MBeanRegistry.SORT_BY_XPATH);
164                     out.print(adminRegistry.toFormatString());
165                     out.println("\n\n\nMBean REGISTRY (in Type value order)");
166                     adminRegistry.sortRegistryEntries(MBeanRegistry.SORT_BY_NAME);
167                     out.print(adminRegistry.toFormatString());
168                     out.close();
169                 }
170
171             }
172             catch (Throwable JavaDoc t)
173             {}
174              return adminRegistry;
175         } catch (Throwable JavaDoc t) {
176             _sLogger.log(Level.WARNING, "core.registryfactory_adminregistry_not_found",
177                        t);
178         }
179         return null;
180     }
181
182     static public MBeanRegistry getRuntimeMBeanRegistry()
183     {
184         if(runtimeRegistry != null)
185             return runtimeRegistry;
186         try {
187             URL JavaDoc url = null;
188             if(adminContext!=null)
189                 url = adminContext.getRuntimeMBeanRegistryURL();
190             if(url==null)
191                 url = MBeanRegistry.class.getResource("/runtime-mbeans-descriptors.xml"); //standard for pe
192
InputStream JavaDoc stream = url.openStream();
193             runtimeRegistry = new MBeanRegistry();
194             runtimeRegistry.loadMBeanRegistry(stream);
195             stream.close();
196             return runtimeRegistry;
197         } catch (Throwable JavaDoc t) {
198             _sLogger.log(Level.WARNING, "core.registryfactory_adminregistry_not_found",
199                        t);
200         }
201         return null;
202     }
203     //for testing purposes only
204
static public MBeanRegistry getMBeanRegistry(String JavaDoc fileName)
205     {
206         try {
207             FileInputStream JavaDoc stream = new FileInputStream JavaDoc(fileName);
208             MBeanRegistry myRegistry = new MBeanRegistry();
209             myRegistry.loadMBeanRegistry((InputStream JavaDoc)stream);
210             stream.close();
211             return myRegistry;
212         } catch (Throwable JavaDoc t) {
213             _sLogger.log(Level.WARNING, "core.registryfactory_registry_not_found",
214                        t);
215         }
216         return null;
217     }
218     
219 }
220
Popular Tags