KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.server;
26
27 // START OF IASRI 4666602
28
import com.sun.enterprise.config.serverbeans.*;
29 import com.sun.enterprise.config.ConfigException;
30 import com.sun.enterprise.instance.ConnectorModulesManager;
31 import com.sun.enterprise.Switch;
32 // START OF IASRI 4666602
33
import javax.resource.spi.ManagedConnectionFactory JavaDoc;
34 // END OF IASRI 4666602
35

36 //START OF 4666169
37
import java.util.logging.Level JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39 import com.sun.logging.LogDomains;
40 //END OF 4666169
41

42 import com.sun.enterprise.connectors.ConnectorRuntime;
43 import com.sun.enterprise.connectors.ConnectorRuntimeException;
44
45 //for jsr77
46
import javax.management.ObjectName JavaDoc;
47 import com.sun.enterprise.config.serverbeans.*;
48 import com.sun.enterprise.deployment.io.ApplicationDeploymentDescriptorFile;
49 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder;
50 import com.sun.enterprise.deployment.Application;
51 import com.sun.enterprise.deployment.Descriptor;
52 import com.sun.enterprise.deployment.ConnectorDescriptor;
53 import com.sun.enterprise.instance.InstanceEnvironment;
54 import com.sun.enterprise.deployment.archivist.ConnectorArchivist;
55 import java.io.IOException JavaDoc;
56 import org.xml.sax.SAXParseException JavaDoc;
57 import com.sun.enterprise.instance.InstanceEnvironment;
58 import com.sun.enterprise.deployment.node.J2EEDocumentBuilder;
59 import com.sun.enterprise.deployment.io.ConnectorDeploymentDescriptorFile;
60 import javax.management.MBeanException JavaDoc;
61 import com.sun.enterprise.Switch;
62 import com.sun.enterprise.server.event.ApplicationEvent;
63
64
65 /**
66  * Connector loader loads and unloads stand alone connector module.
67  *
68  * @author Orit Flint
69  * @since JDK1.4
70  */

71
72 class ConnectorModuleLoader extends AbstractLoader {
73
74    //START OF 4666169
75
static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.LOADER_LOGGER);
76    //END OF 4666169
77

78      private ConnectorDescriptor connectorDescriptor = null;
79
80     /**
81      * ConnectorModuleLoader loads one connector module.
82      *
83      * @param modID the name of the connector module
84      * @param parentClassLoader the parent class loader
85      * @param connModulesManager the connector module mgr for this VS
86      */

87     ConnectorModuleLoader(String JavaDoc modID, ClassLoader JavaDoc parentClassLoader,
88         ConnectorModulesManager connModulesManager) {
89
90             super(modID,parentClassLoader,connModulesManager);
91             // set connector descriptor for subsequent use
92
setConnectorDescriptor(modID);
93     }
94     
95     /**
96      * Loads stand alone connector module.
97      *
98      * @return true if the connector loaded properly
99      */

100     //START OF IASRI 4686190
101
boolean load() {
102         try{
103            ConnectorRuntime cr = ConnectorRuntime.getRuntime();
104            cr.initialize(ConnectorRuntime.SERVER);
105            cr.createActiveResourceAdapter(this.configManager.getLocation(this.id),this.id,this.cascade);
106            return true;
107         }catch(ConfigException e){
108             _logger.log(Level.WARNING,"loader.configexception",e);
109             return false;
110         }
111         catch(ConnectorRuntimeException ex) {
112             _logger.log(Level.WARNING,"Failed to load the rar",ex);
113
114             return false;
115
116         }
117     }
118
119     /**
120      * Loads stand alone connector module.
121      *
122      * @param jsr77 create jsr77 mBeans if true
123      * @return true if the connector loaded properly
124      */

125     boolean load(boolean jsr77) {
126     //Note: Application.isVirtual will be true for stand-alone module
127
notifyAppEvent(ApplicationEvent.BEFORE_APPLICATION_LOAD);
128
129         if (load()) {
130             try {
131                 createLeafMBeans();
132             } catch (MBeanException JavaDoc mbe) {
133                 _logger.log(Level.WARNING,"loader.exception",mbe);
134             }
135             return true;
136         }
137         return false;
138     }
139
140     
141     /**
142      * Unloads stand alone connector module.
143      *
144      * @return true if removed successful
145      */

146     boolean unload() {
147            ConnectorRuntime connectorRuntime = ConnectorRuntime.getRuntime();
148            try {
149                connectorRuntime.destroyActiveResourceAdapter(this.id,cascade);
150                configManager.unregisterDescriptor(id);
151            }
152            catch(ConnectorRuntimeException cre) {
153               return false;
154            }
155            return true;
156     }
157
158     /**
159      * Unloads stand alone connector module.
160      *
161      * @param jsr77 delete jsr77 mBeans if true
162      * @return true if removed successful
163      */

164     boolean unload(boolean jsr77) {
165         if (unload()) {
166             try {
167                 deleteLeafMBeans();
168             } catch (MBeanException JavaDoc mbe) {
169                 _logger.log(Level.WARNING,"loader.exception",mbe);
170             }
171             return true;
172         }
173         return false;
174     }
175
176     /**
177      * Create connector descriptor and store in local variable
178      * for subsequent use by jsr77 and connector code.
179      */

180     private void setConnectorDescriptor(String JavaDoc modID) {
181         try {
182             // hack for setting stand-alone attribute
183
// this needs to be fixed in connectorArchivist
184
// remove this code once it is fixed in connectorArchivist
185
// hack-start
186
this.application = configManager.getDescriptor(modID, null, false);
187             connectorDescriptor = (ConnectorDescriptor) application.getStandaloneBundleDescriptor();
188             // hack-end
189
} catch(ConfigException ex) {
190             _logger.log(Level.WARNING,"Failed to get the module directory ");
191         }
192     }
193
194     /**
195      * Returns connector descriptor for this module
196      */

197     public ConnectorDescriptor getConnectorDescriptor() {
198         return connectorDescriptor;
199     }
200
201
202     /**
203      * Create jsr77 root mBean
204      */

205     void createRootMBean() throws MBeanException JavaDoc {
206
207     try {
208             Switch.getSwitch().getManagementObjectManager().createRARModuleMBean(
209         connectorDescriptor,
210                 this.configManager.getInstanceEnvironment().getName(),
211         this.configManager.getLocation(this.id));
212     } catch (Exception JavaDoc e) {
213         throw new MBeanException JavaDoc(e);
214     }
215     }
216
217
218     /**
219      * Delete jsr77 root mBean
220      */

221     void deleteRootMBean() throws MBeanException JavaDoc {
222
223         Switch.getSwitch().getManagementObjectManager().deleteRARModuleMBean(connectorDescriptor,
224             this.configManager.getInstanceEnvironment().getName());
225     }
226
227
228     /**
229      * Create jsr77 resource adapter mebans which are contained
230      * within this connector module
231      */

232     void createLeafMBeans() throws MBeanException JavaDoc {
233         Switch.getSwitch().getManagementObjectManager().createRARMBeans(connectorDescriptor,
234             this.configManager.getInstanceEnvironment().getName());
235     }
236
237     /**
238      * Create jsr77 resource adapter mebans which are contained
239      * within this connector module
240      */

241     void createLeafMBean(Descriptor descriptor) throws MBeanException JavaDoc {
242         ConnectorDescriptor cd = null;
243         try {
244             cd = (ConnectorDescriptor) descriptor;
245         } catch (Exception JavaDoc e) {
246             throw new MBeanException JavaDoc(e);
247         }
248         Switch.getSwitch().getManagementObjectManager().createRARMBean(cd,
249             this.configManager.getInstanceEnvironment().getName());
250     }
251
252     /**
253      * Delete jsr77 resource adapter mebans which are contained
254      * within this connector module
255      */

256     void deleteLeafMBeans() throws MBeanException JavaDoc {
257         Switch.getSwitch().getManagementObjectManager().deleteRARMBeans(connectorDescriptor,
258             this.configManager.getInstanceEnvironment().getName());
259     }
260
261     /**
262      * Delete jsr77 resource adapter mebans which are contained
263      * within this connector module
264      */

265     void deleteLeafMBean(Descriptor descriptor) throws MBeanException JavaDoc {
266         ConnectorDescriptor cd = null;
267         try {
268             cd = (ConnectorDescriptor) descriptor;
269         } catch (Exception JavaDoc e) {
270             throw new MBeanException JavaDoc(e);
271         }
272         Switch.getSwitch().getManagementObjectManager().deleteRARMBean(cd,
273             this.configManager.getInstanceEnvironment().getName());
274     }
275
276
277     /**
278      * Delete jsr77 mBeans for the module and its' components
279      */

280     void deleteLeafAndRootMBeans() throws MBeanException JavaDoc {
281         deleteLeafMBeans();
282         deleteRootMBean();
283     }
284
285
286     /**
287      * Set the state for the rootMBean
288      */

289     void setState(int state) throws MBeanException JavaDoc {
290
291         Switch.getSwitch().getManagementObjectManager().setRARModuleState(state, connectorDescriptor,
292             this.configManager.getInstanceEnvironment().getName());
293
294     }
295
296 }
297 // END OF IASRI 4666602
298
Popular Tags