KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > ManagerFactory


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  * ManagerFactory.java
26  *
27  * Created on March 28, 2003, 2:20 PM
28  */

29
30 package com.sun.enterprise.server;
31
32 import com.sun.enterprise.config.ConfigException;
33 import com.sun.enterprise.instance.InstanceFactory;
34 import com.sun.enterprise.instance.InstanceEnvironment;
35 import com.sun.enterprise.instance.AppsManager;
36 import com.sun.enterprise.instance.EjbModulesManager;
37 import com.sun.enterprise.instance.WebModulesManager;
38 import com.sun.enterprise.instance.ConnectorModulesManager;
39 import com.sun.enterprise.instance.AppclientModulesManager;
40 import com.sun.appserv.server.util.PreprocessorUtil;
41
42 import java.util.logging.Level JavaDoc;
43 import java.util.logging.Logger JavaDoc;
44 import com.sun.logging.LogDomains;
45
46
47
48 /**
49  *
50  * @author Sandhya E
51  */

52 public class ManagerFactory {
53     
54     /** J2EE Application Manager*/
55     private static ApplicationManager applicationManager;
56     /** Stand alone Connector module manager*/
57     private static StandAloneConnectorModulesManager saConnectorManager;
58     /** Stand alone Web module manager*/
59     private static DummyWebModuleManager saWebManager;
60     /** Stand alone Ejb module manager*/
61     private static StandAloneEJBModulesManager saEJBManager;
62     /** Stand alone Application Client module manager*/
63     private static StandAloneAppClientModulesManager saACManager;
64     /** Instance environment of current server context */
65     private static InstanceEnvironment iEnv;
66     /** shared class loader of current server context */
67     private static ClassLoader JavaDoc sharedCL;
68     
69     /** logger to log core messages */
70     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER);
71     
72     /**
73      * This method gets the Application Manager for this server context
74      * @return ApplicationManager
75      */

76     public static ApplicationManager getApplicationManager() throws ConfigException{
77         if(applicationManager == null) {
78             AppsManager appsManager =
79             InstanceFactory.createAppsManager(getInstanceEnvironment(), false);
80             try {
81                 if (appsManager.isByteCodePreprocessingEnabled()){
82                     // Initialize the preprocessor. If for some reason there's a
83
// problem, the preprocessor will be disabled before we attempt
84
// to use it.
85
PreprocessorUtil.init
86                     (appsManager.getBytecodeProcessorClassNames());
87                 }
88             } catch (ConfigException confEx) {
89                 _logger.log(Level.WARNING,
90                             "bytecodepreprocessor.config_ex",
91                             confEx);
92                 _logger.log(Level.WARNING,
93                             "bytecodepreprocessor.disabled");
94             }
95             
96             // manager for the j2ee applications
97
applicationManager = new ApplicationManager(appsManager,getSharedClassLoader());
98         }
99         return applicationManager;
100     }
101     
102     /**
103      * This method returns the stand alone connector module manager
104      * @return StandAloneConnectorModulesManager
105      */

106     public static StandAloneConnectorModulesManager getSAConnectorModulesManager() throws ConfigException {
107         if(saConnectorManager == null) {
108             // config manager for stand alone connector modules
109
ConnectorModulesManager connModuleManager =
110             InstanceFactory.createConnectorModuleManager(getInstanceEnvironment(), false);
111             
112             // manager for stand alone connector modules
113
saConnectorManager = new StandAloneConnectorModulesManager(
114                                                connModuleManager, getSharedClassLoader());
115         }
116         return saConnectorManager;
117     }
118     
119     /**
120      * This method returns the *dummy* stand alone web modules manager. The returned manager
121      * does not anything but sending an event to ondemand initialization framework.
122      * @return StandAloneWebModulesManager
123      **/

124     public static DummyWebModuleManager getSAWebModulesManager() throws ConfigException {
125         if(saWebManager == null) {
126             // config manager for stand alone web modules
127
WebModulesManager webModuleManager = new WebModulesManager(getInstanceEnvironment());
128             saWebManager = new WebModuleDeployEventListener(webModuleManager, getSharedClassLoader());
129         }
130
131         return saWebManager;
132     }
133     
134     /**
135      * This method returns the stand alone web modules manager
136      * @return StandAloneEjbModulesManager
137      */

138     public static StandAloneEJBModulesManager getSAEJBModulesManager() throws ConfigException {
139         if(saEJBManager == null) {
140             // config manager for stand alone ejb modules
141
EjbModulesManager ejbModuleManager =
142             InstanceFactory.createEjbModuleManager(getInstanceEnvironment(), false);
143             
144             // manager for stand alone ejb modules
145
saEJBManager = new StandAloneEJBModulesManager(ejbModuleManager, getSharedClassLoader());
146         }
147         return saEJBManager;
148     }
149
150     /**
151      * This method returns the stand alone application client module manager
152      * @return StandAloneAppClientModulesManager
153      */

154     public static StandAloneAppClientModulesManager getSAACModulesManager()
155     throws ConfigException {
156
157         if(saACManager == null) {
158
159             // config manager for stand alone application client modules
160
AppclientModulesManager acModuleManager =
161         InstanceFactory.createAppclientModulesManager(getInstanceEnvironment());
162             
163             // manager for stand alone application client modules
164
saACManager = new StandAloneAppClientModulesManager(
165                     acModuleManager, getSharedClassLoader());
166         }
167         return saACManager;
168     }
169     
170     /**
171      * Returns the instance environment of this server's runtime
172      * @return InstanceEnvironment
173      */

174     private static InstanceEnvironment getInstanceEnvironment() {
175         if(iEnv == null) {
176             ServerContext sc = ApplicationServer.getServerContext();
177             iEnv = sc.getInstanceEnvironment();
178         }
179         return iEnv;
180     }
181     
182     /**
183      * Returns the shared class loader
184      * @return ClassLoader
185      **/

186     private static ClassLoader JavaDoc getSharedClassLoader() {
187         if(sharedCL == null) {
188             ServerContext sc = ApplicationServer.getServerContext();
189             sharedCL = sc.getSharedClassLoader();
190         }
191         return sharedCL;
192     }
193     
194         
195 }
196
Popular Tags