KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > ear > EarServiceImpl


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EarServiceImpl.java,v 1.63 2005/07/27 11:14:43 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.ear;
27
28 import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.net.MalformedURLException JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.net.URLClassLoader JavaDoc;
33 import java.security.Policy JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Date JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.HashSet JavaDoc;
38 import java.util.Hashtable JavaDoc;
39 import java.util.Iterator JavaDoc;
40 import java.util.LinkedList JavaDoc;
41 import java.util.List JavaDoc;
42 import java.util.Map JavaDoc;
43 import java.util.Set JavaDoc;
44 import java.util.StringTokenizer JavaDoc;
45 import java.util.Vector JavaDoc;
46
47 import javax.management.InstanceAlreadyExistsException JavaDoc;
48 import javax.management.MBeanRegistrationException JavaDoc;
49 import javax.management.MBeanServer JavaDoc;
50 import javax.management.NotCompliantMBeanException JavaDoc;
51 import javax.management.ObjectName JavaDoc;
52 import javax.management.modelmbean.ModelMBean JavaDoc;
53 import javax.naming.Context JavaDoc;
54 import javax.naming.NamingException JavaDoc;
55 import javax.security.jacc.PolicyConfiguration JavaDoc;
56 import javax.security.jacc.PolicyConfigurationFactory JavaDoc;
57 import javax.security.jacc.PolicyContextException JavaDoc;
58
59 import org.apache.commons.modeler.ManagedBean;
60 import org.apache.commons.modeler.Registry;
61 import org.objectweb.jonas.client.AppClientModule;
62 import org.objectweb.jonas.common.JModule;
63 import org.objectweb.jonas.common.JProp;
64 import org.objectweb.jonas.common.Log;
65 import org.objectweb.jonas.container.EJBService;
66 import org.objectweb.jonas.container.EJBServiceImpl;
67 import org.objectweb.jonas.ear.lib.EarClassPathManager;
68 import org.objectweb.jonas.ear.lib.EarClassPathManagerException;
69 import org.objectweb.jonas.ear.lib.JarList;
70 import org.objectweb.jonas.ear.lib.JarListException;
71 import org.objectweb.jonas.jmx.J2eeObjectName;
72 import org.objectweb.jonas.jmx.JmxService;
73 import org.objectweb.jonas.jmx.JonasObjectName;
74 import org.objectweb.jonas.management.JonasMBeanTools;
75 import org.objectweb.jonas.naming.CompNamingContext;
76 import org.objectweb.jonas.resource.ResourceService;
77 import org.objectweb.jonas.resource.ResourceServiceException;
78 import org.objectweb.jonas.security.jacc.JPolicyUserRoleMapping;
79 import org.objectweb.jonas.server.JClassLoader;
80 import org.objectweb.jonas.server.LoaderManager;
81 import org.objectweb.jonas.service.AbsServiceImpl;
82 import org.objectweb.jonas.service.ServiceException;
83 import org.objectweb.jonas.service.ServiceManager;
84 import org.objectweb.jonas.web.JWebContainerService;
85 import org.objectweb.jonas.web.JWebContainerServiceException;
86 import org.objectweb.jonas.ws.AbsWebServicesServiceImpl;
87 import org.objectweb.jonas.ws.WSServiceException;
88 import org.objectweb.jonas.ws.WebServicesService;
89 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDesc;
90 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDescException;
91 import org.objectweb.jonas_client.deployment.lib.wrapper.ClientManagerWrapper;
92 import org.objectweb.jonas_ear.deployment.api.EarDeploymentDesc;
93 import org.objectweb.jonas_ear.deployment.api.EarDeploymentDescException;
94 import org.objectweb.jonas_ear.deployment.lib.wrapper.EarManagerWrapper;
95 import org.objectweb.jonas_ear.deployment.xml.Web;
96
97 import org.objectweb.jonas_ejb.deployment.lib.wrapper.EjbManagerWrapper;
98 import org.objectweb.jonas_lib.deployment.work.CleanerException;
99 import org.objectweb.jonas_lib.deployment.work.DeployerLog;
100 import org.objectweb.jonas_lib.deployment.work.DeployerLogException;
101 import org.objectweb.jonas_lib.deployment.work.EarCleanTask;
102 import org.objectweb.jonas_lib.deployment.work.EarFileManager;
103 import org.objectweb.jonas_lib.deployment.work.FileManagerException;
104 import org.objectweb.jonas_lib.deployment.work.WorkCleaner;
105 import org.objectweb.jonas_lib.loader.ClientClassLoader;
106 import org.objectweb.jonas_lib.loader.EjbJarClassLoader;
107 import org.objectweb.jonas_web.deployment.lib.wrapper.WebManagerWrapper;
108 import org.objectweb.util.monolog.api.BasicLevel;
109 import org.objectweb.util.monolog.api.Logger;
110
111 /**
112  * JOnAS EAR Service Implementation class. This class provides an implementation
113  * of the ear service.
114  * @author Florent Benoit
115  * @author Ludovic Bert Contributor(s): Adriana Danes: highlight configuration
116  * properties Eric Hardesty: added ability to include rar files in an
117  * ear Michel-Ange Anton : new JSR77 MBean
118  */

119 public class EarServiceImpl extends AbsServiceImpl implements EarService, EarServiceImplMBean {
120
121     /**
122      * The name of the JONAS_BASE directory.
123      */

124     protected static final String JavaDoc JONAS_BASE = JProp.getJonasBase();
125
126     /**
127      * The name of the apps directory.
128      */

129     protected static final String JavaDoc APPS_DIR = JONAS_BASE + File.separator + "apps";
130
131     /**
132      * The name of the working directory.
133      */

134     protected static final String JavaDoc WORK_DIR = JProp.getWorkDir();
135
136     /**
137      * The name of the working apps directory.
138      */

139     protected static final String JavaDoc WORK_APPS_DIR = WORK_DIR + File.separator + "apps";
140
141     /**
142      * Property for ear to deploy at runtime
143      */

144     protected static final String JavaDoc DESCRIPTORS = "jonas.service.ear.descriptors";
145
146     /**
147      * Directories property for autoload
148      */

149     protected static final String JavaDoc AUTOLOADDIR = "jonas.service.ear.autoloaddir";
150
151     /**
152      * Property for parsing with validation or not
153      */

154     protected static final String JavaDoc PARSINGWITHVALIDATION = "jonas.service.ear.parsingwithvalidation";
155
156     /**
157      * Property for the class of the EAR service
158      */

159     protected static final String JavaDoc CLASS = "jonas.service.ear.class";
160
161     /**
162      * Logger for this service.
163      */

164     private static Logger logger = null;
165
166     /**
167      * Reference to the cleaner
168      */

169     private static WorkCleaner workCleaner = null;
170
171     /**
172      * Reference to a MBean server.
173      */

174     private MBeanServer JavaDoc mbeanServer = null;
175
176     /**
177      * List of the ear names to load when starting the EarService
178      */

179     private Vector JavaDoc earNames = new Vector JavaDoc();
180
181     /**
182      * Reference to the Ejb service.
183      */

184     private EJBService ejbService = null;
185
186     /**
187      * Reference to the WebContainer service.
188      */

189     private JWebContainerService webContainerService = null;
190
191     /**
192      * Reference to the WebServices service.
193      */

194     private WebServicesService wsService = null;
195
196     /**
197      * Reference to the Resource service.
198      */

199     private ResourceService resourceService = null;
200
201     /**
202      * List of loaded ear
203      */

204     private Hashtable JavaDoc ears = null;
205
206     /**
207      * List of autoloaded directories.
208      */

209     private ArrayList JavaDoc autoloadDirectories = new ArrayList JavaDoc();
210
211     /**
212      * Reference on the DeployerLog which is the class that manage the
213      * accesses to the log file (to remove the ear).
214      */

215     private DeployerLog earDeployerLog = null;
216
217     /**
218      * Application Classloader
219      */

220     private ClassLoader JavaDoc appsClassLoader;
221
222     /**
223      * Init the EAR service.
224      * @param ctx the configuration of the Ear service.
225      * @throws ServiceException if the initialization failed.
226      */

227     protected void doInit(Context JavaDoc ctx) throws ServiceException {
228
229         //we init the logger
230
logger = Log.getLogger(Log.JONAS_EAR_PREFIX);
231
232         // get apps ClassLoader
233
try {
234             LoaderManager lm = LoaderManager.getInstance();
235             appsClassLoader = lm.getAppsLoader();
236         } catch (Exception JavaDoc e) {
237             logger.log(BasicLevel.ERROR, "Cannot get the Applications ClassLoader from EAR Container Service: " + e);
238             throw new ServiceException("Cannot get the Applications ClassLoader from EAR Container Service", e);
239         }
240
241         ServiceManager sm = null;
242
243         try {
244             sm = ServiceManager.getInstance();
245         } catch (Exception JavaDoc e) {
246             String JavaDoc err = "Cannot get ServiceManager instance";
247             logger.log(BasicLevel.ERROR, err);
248             throw new ServiceException(err, e);
249         }
250
251         // Get the JMX Server via JMX Service
252
try {
253             mbeanServer = ((JmxService) sm.getJmxService()).getJmxServer();
254         } catch (ServiceException e) {
255             // the JMX service may not be started
256
mbeanServer = null;
257         }
258
259         // Get the EJB service
260
try {
261             ejbService = (EJBService) sm.getEjbService();
262         } catch (ServiceException e) {
263             //not started
264
ejbService = null;
265         }
266
267         // Get the Web Container service
268
try {
269             webContainerService = (JWebContainerService) sm.getWebContainerService();
270         } catch (ServiceException e) {
271             //not started
272
webContainerService = null;
273         }
274
275         // Get the WebServices service
276
try {
277             wsService = (WebServicesService) sm.getWebServicesService();
278         } catch (ServiceException e) {
279             //not started
280
wsService = null;
281         }
282
283         // Get the Resource service
284
try {
285             resourceService = (ResourceService) sm.getResourceService();
286         } catch (ServiceException e) {
287             //not started
288
resourceService = null;
289         }
290
291         // Set the XML parsing mode to no validation
292
String JavaDoc parsingMode = "false";
293         try {
294             parsingMode = (String JavaDoc) ctx.lookup(PARSINGWITHVALIDATION);
295         } catch (NamingException JavaDoc e) {
296             /*
297              * No problem if there is no value for 'parsingwithvalidation'
298              * (false by default)
299              */

300             if (logger.isLoggable(BasicLevel.DEBUG)) {
301                 logger.log(BasicLevel.DEBUG, "No XML parsing validation property, use default");
302             }
303         }
304         EarManagerWrapper.setParsingWithValidation("true".equalsIgnoreCase(parsingMode));
305         if ("false".equalsIgnoreCase(parsingMode)) {
306             if (logger.isLoggable(BasicLevel.DEBUG)) {
307                 logger.log(BasicLevel.DEBUG, "Ear XML parsing without validation");
308             }
309         } else {
310             if (logger.isLoggable(BasicLevel.DEBUG)) {
311                 logger.log(BasicLevel.DEBUG, "Ear XML parsing with validation");
312             }
313         }
314
315         // Init the ear names to be loaded when starting
316
String JavaDoc descsValue = null;
317         try {
318             descsValue = (String JavaDoc) ctx.lookup(DESCRIPTORS);
319         } catch (NamingException JavaDoc e) {
320             if (logger.isLoggable(BasicLevel.DEBUG)) {
321                 logger.log(BasicLevel.DEBUG, "No property DESCRIPTORS");
322             }
323             // No problem if there is no value for 'descriptors'
324
//(no ear to load)
325
}
326         if (descsValue != null) {
327             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(descsValue, ",");
328             while (st.hasMoreTokens()) {
329                 String JavaDoc fileName = st.nextToken().trim();
330                 earNames.add(fileName);
331             }
332         }
333
334         // Add the ears of the jonas.service.ear.autoloaddir property
335
String JavaDoc dirValue = null;
336         ArrayList JavaDoc autoDirs = new ArrayList JavaDoc();
337         try {
338             dirValue = (String JavaDoc) ctx.lookup(AUTOLOADDIR);
339         } catch (NamingException JavaDoc e) {
340             if (logger.isLoggable(BasicLevel.DEBUG)) {
341                 logger.log(BasicLevel.DEBUG, "No AUTOLOADDIR property");
342             }
343             // No problem if there is no value for 'autoloaddir'
344
//(no ear to load)
345
}
346         if (dirValue != null) {
347             StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(dirValue, ",");
348             while (st.hasMoreTokens()) {
349                 String JavaDoc dirName = st.nextToken().trim();
350                 addEars(dirName);
351                 autoDirs.add(dirName);
352             }
353         }
354         // Build autoload directories
355
File JavaDoc oFile;
356         Iterator JavaDoc it = autoDirs.iterator();
357         while (it.hasNext()) {
358             String JavaDoc dirName = (String JavaDoc) it.next();
359             try {
360                 oFile = new File JavaDoc(APPS_DIR, dirName);
361                 if (!oFile.exists()) {
362                     oFile = new File JavaDoc(dirName);
363                 }
364                 if (oFile.exists()) {
365                     autoloadDirectories.add(oFile.getCanonicalPath());
366                 }
367             } catch (Exception JavaDoc e) {
368                 String JavaDoc err = "Error when trying to verify Application EAR autoload directory : " + dirName;
369                 logger.log(BasicLevel.ERROR, err, e);
370             }
371         }
372
373         //create hashtable of the ears ( Url of an ear ---> Ear structure)
374
ears = new Hashtable JavaDoc();
375
376         // Init the rar deployment desc manager.
377
//rarDDManager = RarDeploymentDescManager.getInstance();
378
}
379
380     /**
381      * Stop the EAR service.
382      * @throws ServiceException if the stop failed.
383      */

384     protected void doStop() throws ServiceException {
385
386         //undeploy the loaded ears files
387
URL JavaDoc earFileName = null;
388         //For each ear file, we delegate the operation to the
389
//unDeployEar method
390
for (Enumeration JavaDoc earEntries = ears.keys(); earEntries.hasMoreElements();) {
391             earFileName = (URL JavaDoc) earEntries.nextElement();
392             //Try to undeploy the ear
393
try {
394                 Context JavaDoc ctx = new CompNamingContext(earFileName.getFile());
395                 ctx.rebind("filename", earFileName);
396                 unDeployEar(ctx);
397             } catch (Exception JavaDoc e) {
398                 //We don't stop the process of undeploying the ears.
399
//We only display an error in the logger.
400
String JavaDoc err = "Error when undeploying the ear :" + earFileName;
401                 logger.log(BasicLevel.ERROR, err, e);
402             }
403         }
404
405         if (mbeanServer != null) {
406             try {
407                 // unregister EarService MBean : EarServiceImplMBean
408
mbeanServer.unregisterMBean(JonasObjectName.earService());
409             } catch (Exception JavaDoc e) {
410                 logger.log(BasicLevel.ERROR, "Cannot stop the EarService", e);
411             }
412         }
413
414         //The service is stopped
415
if (logger.isLoggable(BasicLevel.DEBUG)) {
416             logger.log(BasicLevel.DEBUG, "EarService stopped");
417         }
418
419     }
420
421     /**
422      * Deploy an EAR file with sending JAR file to the EJB container and WAR
423      * file to the WEB container and RAR file to the resource service.
424      * @param ctx the context which contains the configuration in order to
425      * deploy an EAR.
426      * @return The ObjectName of the J2EE Application MBean associated to the
427      * deployed EAR the Application Container
428      * @throws EarServiceException if the deployment of the EAR failed.
429      */

430     public String JavaDoc deployEar(Context JavaDoc ctx) throws EarServiceException {
431
432         //We have one of the ejb or web services launched
433
if ((webContainerService == null) && (ejbService == null)) {
434             throw new EarServiceException(
435                     "The ear service requires that at least the service ejb or web is launched for deploying an ear file.");
436         }
437
438         //We get the fileName
439
// Get the file name and check if file exists
440
String JavaDoc fileName;
441         try {
442             fileName = (String JavaDoc) ctx.lookup("filename");
443         } catch (NamingException JavaDoc e) {
444             throw new EarServiceException("Error during performing lookup a fileName", e);
445         }
446
447         File JavaDoc f = null;
448         try {
449             //We search the file
450
f = new File JavaDoc(fileName).getCanonicalFile();
451
452             if (!f.exists()) {
453                 boolean found = false;
454                 String JavaDoc earFileName = null;
455                 if (fileName.toLowerCase().endsWith(".ear")) {
456                     // In case of the name is a ear file name, check also in
457
// the JONAS_BASE/apps directory
458
earFileName = APPS_DIR + File.separator + fileName;
459                     f = new File JavaDoc(earFileName).getCanonicalFile();
460                     found = f.exists();
461                 }
462                 if (found) {
463                     fileName = earFileName;
464                 } else {
465                     String JavaDoc err = "deployEar: The file " + fileName
466                             + " was not found neither in the current directory nor in the " + APPS_DIR + " directory";
467                     logger.log(BasicLevel.ERROR, err);
468                     throw new EarServiceException(err);
469                 }
470             }
471         } catch (IOException JavaDoc e) {
472             String JavaDoc err = "Error when trying to get the canonical file from " + fileName;
473             logger.log(BasicLevel.ERROR, err + " " + e.getMessage());
474             throw new EarServiceException(err, e);
475         }
476
477         //Make the url for the specified fileName and the earRootUrl
478
URL JavaDoc[] earUrl = new URL JavaDoc[1];
479         URL JavaDoc earRootUrl = null;
480
481         try {
482             earUrl[0] = f.toURL();
483             earRootUrl = (new File JavaDoc(WORK_APPS_DIR + File.separator + getJonasServerName())).toURL();
484         } catch (MalformedURLException JavaDoc e) {
485             String JavaDoc err = "Invalid ear file name '" + fileName;
486             logger.log(BasicLevel.ERROR, err + "': " + e.getMessage());
487             throw new EarServiceException(err, e);
488         }
489
490         //Check if the ear is already deployed or not
491
if (ears.get(earUrl[0]) != null) {
492             String JavaDoc err = "The ear file : " + f.getName() + " is already deployed ('" + earUrl[0].getFile()
493                     + "'). You must undeploy the application " + "before a new deployment.";
494             logger.log(BasicLevel.ERROR, err);
495             throw new EarServiceException(err);
496         }
497
498         //Create classLoader
499
//parent classloader is the current classloader
500
URLClassLoader JavaDoc loaderCls = new URLClassLoader JavaDoc(earUrl, appsClassLoader);
501
502         EarDeploymentDesc earDD = null;
503         if (logger.isLoggable(BasicLevel.DEBUG)) {
504             logger.log(BasicLevel.DEBUG, "Getting the deployment descriptor of the file" + f.getName());
505         }
506         try {
507             earDD = EarManagerWrapper.getDeploymentDesc(earUrl[0].getFile(), loaderCls);
508         } catch (EarDeploymentDescException e) {
509             String JavaDoc err = "Error in the Deployment descriptor '" + fileName + "': " + e;
510             logger.log(BasicLevel.ERROR, err);
511             throw new EarServiceException(err, e);
512         }
513
514         //We get the tags from the Deployment descriptor
515
Web[] webTags = earDD.getWebTags();
516         String JavaDoc[] ejbTags = earDD.getEjbTags();
517         String JavaDoc[] connectorTags = earDD.getConnectorTags();
518         String JavaDoc[] clientTags = earDD.getClientTags();
519         String JavaDoc[] altDDClients = earDD.getAltDDClients();
520         String JavaDoc[] altDDEjbs = earDD.getAltDDEjbs();
521         String JavaDoc[] altDDWebs = earDD.getAltDDWebs();
522         String JavaDoc[] altDDConnectors = earDD.getAltDDConnectors();
523         String JavaDoc[] securityRoles = earDD.getSecurityRolesNames();
524
525         //Check if all modules are inside the EAR file
526
//no relatives mode like ../../file1.jar
527

528         File JavaDoc fEar = new File JavaDoc(earUrl[0].getFile());
529         File JavaDoc tmpFile = null;
530
531         try {
532             File JavaDoc fCanonicEar = fEar.getCanonicalFile();
533             for (int i = 0; i < ejbTags.length; i++) {
534                 tmpFile = new File JavaDoc(fEar, ejbTags[i]);
535                 tmpFile = tmpFile.getCanonicalFile();
536                 if (!tmpFile.getPath().startsWith(fCanonicEar.getPath())) {
537                     String JavaDoc err = "Error : The ejb-jar file " + ejbTags[i] + " is not inside the ear file " + fEar;
538                     logger.log(BasicLevel.ERROR, err);
539                     throw new EarServiceException(err);
540                 }
541             }
542
543             for (int i = 0; i < webTags.length; i++) {
544                 tmpFile = new File JavaDoc(fEar, webTags[i].getWebUri());
545                 tmpFile = tmpFile.getCanonicalFile();
546                 if (!tmpFile.getPath().startsWith(fCanonicEar.getPath())) {
547                     String JavaDoc err = "Error : The war file " + webTags[i].getWebUri() + " is not inside the ear file "
548                             + fEar;
549                     logger.log(BasicLevel.ERROR, err);
550                     throw new EarServiceException(err);
551                 }
552             }
553
554             for (int i = 0; i < connectorTags.length; i++) {
555                 tmpFile = new File JavaDoc(fEar, connectorTags[i]);
556                 tmpFile = tmpFile.getCanonicalFile();
557                 if (!tmpFile.getPath().startsWith(fCanonicEar.getPath())) {
558                     String JavaDoc err = "Error : The rar file " + connectorTags[i] + " is not inside the ear file " + fEar;
559                     logger.log(BasicLevel.ERROR, err);
560                     throw new EarServiceException(err);
561                 }
562             }
563
564
565             for (int i = 0; i < clientTags.length; i++) {
566                 tmpFile = new File JavaDoc(fEar, clientTags[i]);
567                 tmpFile = tmpFile.getCanonicalFile();
568
569                 if (!tmpFile.getPath().startsWith(fCanonicEar.getPath())) {
570                     String JavaDoc err = "Error : The client jar file " + clientTags[i] + " is not inside the ear file " + fEar;
571                     throw new EarServiceException(err);
572                 }
573             }
574         } catch (IOException JavaDoc ioe) {
575             String JavaDoc err = "Error while trying to get the canonical file of " + tmpFile;
576             logger.log(BasicLevel.ERROR, err + " : " + ioe.getMessage());
577             throw new EarServiceException(err, ioe);
578         }
579
580         //Changing array into JarList
581
JarList ejbsList = new JarList(ejbTags);
582         JarList warsList = new JarList(webTags);
583         JarList connectorsList = new JarList(connectorTags);
584         JarList clientsList = new JarList(clientTags);
585
586         //Unpack the ear file and get the unpacked dir
587
URL JavaDoc dirUnpackURL = null;
588         try {
589             dirUnpackURL = EarFileManager.unpackEar(earUrl[0], earRootUrl);
590         } catch (FileManagerException e) {
591             String JavaDoc err = "Error while unpacking the file '" + earUrl[0] + "'";
592             logger.log(BasicLevel.ERROR, err + " : " + e.getMessage());
593             throw new EarServiceException(err, e);
594         }
595
596         //the file is unpacked. Log it only if the ear is a file and not a
597
// directory
598
if (new File JavaDoc(earUrl[0].getFile()).isFile()) {
599             try {
600                 earDeployerLog.addEntry(new File JavaDoc(earUrl[0].getFile()), new File JavaDoc(dirUnpackURL.getFile()));
601             } catch (DeployerLogException e) {
602                 String JavaDoc err = "Error while adding the " + earUrl[0] + " entry in the log file";
603                 logger.log(BasicLevel.ERROR, err + " : " + e.getMessage());
604                 throw new EarServiceException(err, e);
605             }
606         }
607
608         //We have successfully unpacked the ear file, now we analyze manifest
609
// Class-path:
610
EarClassPathManager earCPManager = null;
611         try {
612             earCPManager = new EarClassPathManager(ejbsList, warsList, dirUnpackURL);
613         } catch (EarClassPathManagerException e) {
614             String JavaDoc err = "Error while creating the Ear class path manager of the ear : '" + earUrl[0] + "'";
615             logger.log(BasicLevel.ERROR, err + " : " + e.getMessage());
616             throw new EarServiceException(err, e);
617         }
618
619         URL JavaDoc[] classpathURLs = null;
620         //Get the urls of the ear class path manager
621
try {
622             classpathURLs = earCPManager.getResolvedClassPath();
623         } catch (EarClassPathManagerException e) {
624             String JavaDoc err = "Error while trying to resolve the classpath of the ejbjars and wars of the ear : '"
625                     + earUrl[0] + "'";
626             logger.log(BasicLevel.ERROR, err + " : " + e.getMessage());
627             throw new EarServiceException(err, e);
628         }
629
630         /*
631          * We have the urls to load at our level We can now create our
632          * classLoader
633          */

634         if (logger.isLoggable(BasicLevel.DEBUG)) {
635             logger.log(BasicLevel.DEBUG, "Creating the EAR classLoader");
636         }
637         JClassLoader earClassLoader = new JClassLoader(earUrl[0].toExternalForm() , new URL JavaDoc[0], appsClassLoader);
638
639         //Extract the urls of the jarList
640
URL JavaDoc[] jarUrls = null;
641         URL JavaDoc[] warUrls = null;
642         URL JavaDoc[] connectorUrls = null;
643         URL JavaDoc[] clientUrls = null;
644         try {
645             jarUrls = ejbsList.getURLs(dirUnpackURL.toExternalForm());
646             warUrls = warsList.getURLs(dirUnpackURL.toExternalForm());
647             connectorUrls = connectorsList.getURLs(dirUnpackURL.toExternalForm());
648             clientUrls = clientsList.getURLs(dirUnpackURL.toExternalForm());
649         } catch (JarListException e) {
650             String JavaDoc err = "Error while geting the Urls from jarlist of the ear : '" + earUrl[0] + "'";
651             logger.log(BasicLevel.ERROR, err + " : " + e.getMessage());
652             throw new EarServiceException(err, e);
653         }
654
655         //Extract context roots for wars
656
//They are in webTags. Dump into warsContextRoots
657
String JavaDoc[] warsContextRoots = new String JavaDoc[webTags.length];
658         String JavaDoc ctxRoot = null;
659         for (int i = 0; i < webTags.length; i++) {
660             ctxRoot = webTags[i].getContextRoot();
661             if (ctxRoot != null) {
662                 warsContextRoots[i] = ctxRoot;
663             }
664         }
665
666         //Fill Alt-DD for Ejbs and Wars and Rars
667
String JavaDoc altdd = null;
668         File JavaDoc fAltDD = null;
669
670         //Transorm the array altDDWebs into an array with the absolute URL to
671
// the file
672
URL JavaDoc[] warsAltDDs = new URL JavaDoc[altDDWebs.length];
673         for (int i = 0; i < altDDWebs.length; i++) {
674             if (altDDWebs[i] != null) {
675                 altdd = altDDWebs[i];
676                 if (altdd != null) {
677                     try {
678                         fAltDD = new File JavaDoc(new URL JavaDoc(dirUnpackURL.toExternalForm() + File.separator + altdd).getFile());
679                         warsAltDDs[i] = fAltDD.getCanonicalFile().toURL();
680                     } catch (MalformedURLException JavaDoc e) {
681                         String JavaDoc err = "Can't build URL for alt-dd '" + altdd;
682                         logger.log(BasicLevel.ERROR, err + "': " + e.getMessage());
683