KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > AdminContextImpl


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 package com.sun.enterprise.admin.server.core;
24
25 import java.util.logging.Level JavaDoc;
26 import java.util.logging.Logger JavaDoc;
27
28 import java.net.URL JavaDoc;
29
30 import javax.management.MBeanServer JavaDoc;
31
32 import com.sun.enterprise.admin.AdminContext;
33 import com.sun.enterprise.admin.meta.MBeanRegistry;
34 import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
35 import com.sun.enterprise.admin.meta.AdminConfigEventListener;
36 import com.sun.enterprise.admin.util.proxy.Interceptor;
37 import com.sun.enterprise.config.ConfigContext;
38 import com.sun.enterprise.config.ConfigContextEventListener;
39 import com.sun.enterprise.config.ConfigException;
40 import com.sun.enterprise.config.ConfigContextFactory;
41 import com.sun.enterprise.config.ConfigException;
42 import com.sun.enterprise.server.ServerContextImpl;
43 import com.sun.enterprise.config.pluggable.ConfigEnvironment;
44 import com.sun.enterprise.config.pluggable.EnvironmentFactory;
45
46 /**
47  *
48  */

49 public class AdminContextImpl implements AdminContext {
50
51     private ServerContextImpl serverContext;
52     private ConfigContext runtimeConfigContext;
53     private ConfigContext adminConfigContext;
54     private MBeanServer JavaDoc mbeanServer;
55     private String JavaDoc domainName;
56     private String JavaDoc serverName;
57     private Logger JavaDoc adminLogger;
58     private Interceptor configInterceptor;
59     private URL JavaDoc adminMBeanRegistryURL;
60     private URL JavaDoc runtimeMBeanRegistryURL;
61     
62     private static final String JavaDoc ADMIN_DESCRIPTORS_FILENAME = "/admin-mbeans-descriptors.xml";
63     private static final String JavaDoc RUNTIME_DESCRIPTORS_FILENAME = "/runtime-mbeans-descriptors.xml";
64
65     /**
66      * Creates a new instance of AdminContextImpl
67      */

68     public AdminContextImpl() {
69         String JavaDoc loggerName = System.getProperty("com.sun.aas.admin.logger.name");
70         if (loggerName != null) {
71             adminLogger = Logger.getLogger(loggerName);
72         } else {
73             adminLogger = Logger.getAnonymousLogger();
74         }
75         //default PE settings
76
domainName = "com.sun.appserv";
77         //notify MBeanRegistryFactory
78
MBeanRegistryFactory.setAdminContext(this);
79     }
80
81     public AdminContextImpl(ServerContextImpl srvCtx) {
82         this();
83         setServerContext(srvCtx);
84     }
85
86
87     public void setServerContext(ServerContextImpl srvCtx) {
88         serverContext = srvCtx;
89         runtimeConfigContext = serverContext.getConfigContext();
90         String JavaDoc configFileName = serverContext.getServerConfigURL();
91         try {
92             adminConfigContext = ConfigContextFactory.createConfigContext(
93                     getAdminConfigEnvironment(configFileName));
94             // Registering the config validator
95
registerValidator();
96             registerConfigAdjustmentListener();
97              
98         } catch (RuntimeException JavaDoc ce) {
99             adminLogger.log(Level.SEVERE, "core.admin_config_read_error",
100                    ce.getMessage());
101             adminLogger.log(Level.WARNING, "core.admin_config_read_error_trace",
102                    ce);
103             throw ce;
104         }
105               
106         adminLogger.log(Level.FINEST, "core.log_config_id_runtime",
107                 new Long JavaDoc(runtimeConfigContext.hashCode()));
108         adminLogger.log(Level.FINEST, "core.log_config_is_admin",
109                 new Long JavaDoc(adminConfigContext.hashCode()));
110         serverName = serverContext.getInstanceName();
111     }
112
113     protected void registerConfigAdjustmentListener() {
114     
115         // Added mechanism to avoid unadjusted domain.xml.<->MBeans<->dotted_names
116
adminConfigContext.addConfigContextEventListener((ConfigContextEventListener)(new AdminConfigEventListener()));
117     }
118     protected void registerValidator() {
119     
120         // Added reflection mechanism to avoid compile time error
121
try {
122              Class JavaDoc cl = Class.forName("com.sun.enterprise.config.serverbeans.validation.DomainMgr");
123              adminConfigContext.addConfigContextEventListener((ConfigContextEventListener)cl.newInstance());
124         } catch (Exception JavaDoc ex) {
125              adminLogger.log(Level.WARNING, "core.admin_validator_not_registered", "Error registering validator, config validator will not be available");
126              adminLogger.log(Level.FINE, "core.admin_validator_register_error", ex.getMessage());
127         }
128     }
129
130     public ConfigContext getAdminConfigContext() {
131         return adminConfigContext;
132     }
133    
134     public String JavaDoc getDomainName() {
135         return domainName;
136     }
137
138     public MBeanServer JavaDoc getMBeanServer() {
139         return mbeanServer;
140     }
141
142     public ConfigContext getRuntimeConfigContext() {
143         return runtimeConfigContext;
144     }
145     
146     public String JavaDoc getServerName() {
147         return serverName;
148     }
149     
150     public URL JavaDoc getAdminMBeanRegistryURL() {
151         if(adminMBeanRegistryURL==null) {
152             try {
153                 //PE standard
154
adminMBeanRegistryURL = MBeanRegistry.class.getResource(ADMIN_DESCRIPTORS_FILENAME);
155             } catch (Throwable JavaDoc t) {
156                 adminLogger.log(Level.WARNING, "core.adminconfig_adminregistry_not_found",
157                        ADMIN_DESCRIPTORS_FILENAME);
158             }
159         }
160         return adminMBeanRegistryURL;
161     }
162     
163     public URL JavaDoc getRuntimeMBeanRegistryURL() {
164         if(runtimeMBeanRegistryURL==null) {
165             try {
166                 //PE standard
167
runtimeMBeanRegistryURL = MBeanRegistry.class.getResource(RUNTIME_DESCRIPTORS_FILENAME);
168             } catch (Throwable JavaDoc t) {
169                 adminLogger.log(Level.WARNING, "core.adminconfig_runtimeregistry_not_found",
170                        RUNTIME_DESCRIPTORS_FILENAME);
171             }
172         }
173         return runtimeMBeanRegistryURL;
174     }
175     
176     public void setAdminConfigContext(ConfigContext ctx) {
177     }
178     
179     public void setDomainName(String JavaDoc name) {
180 // domainName = name;
181
}
182     
183     public void setMBeanServer(MBeanServer JavaDoc mbs) {
184         mbeanServer = mbs;
185     }
186
187     public void setRuntimeConfigContext(ConfigContext ctx) {
188         if (serverContext != null) {
189             serverContext.setConfigContext(ctx);
190         }
191     }
192     
193     public void setServerName(String JavaDoc serverName) {
194     }
195
196     public void setAdminMBeanRegistryURL(URL JavaDoc url) {
197         adminMBeanRegistryURL = url;
198     }
199     
200     public void setRuntimeMBeanRegistryURL(URL JavaDoc url) {
201         runtimeMBeanRegistryURL = url;
202     }
203     
204     public Logger JavaDoc getAdminLogger() {
205         return adminLogger;
206     }
207
208     public void setAdminLogger(Logger JavaDoc logger) {
209         adminLogger = logger;
210     }
211
212     public Interceptor getMBeanServerInterceptor() {
213         if (configInterceptor == null) {
214             configInterceptor = new ConfigInterceptor(this);
215         }
216         return configInterceptor;
217     }
218
219     public void setMBeanServerInterceptor(Interceptor interceptor) {
220     }
221
222     private ConfigEnvironment getAdminConfigEnvironment(String JavaDoc configFileName) {
223         ConfigEnvironment ce = EnvironmentFactory.getEnvironmentFactory().
224                                 getConfigEnvironment();
225         ce.setUrl(configFileName);
226         ce.setReadOnly(false);
227         ce.setCachingEnabled(false);
228         ce.setRootClass("com.sun.enterprise.config.serverbeans.Domain");
229         ce.setHandler("com.sun.enterprise.config.serverbeans.ServerValidationHandler");
230         ce.getConfigBeanInterceptor().setResolvingPaths(false);
231         return ce;
232     }
233     public String JavaDoc getDottedNameMBeanImplClassName(){
234         return "com.sun.enterprise.admin.mbeans.DottedNameGetSetMBeanImpl";
235     }
236 }
237
Popular Tags