KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > spi > DeploymentManagerImpl


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.deployment.spi;
23
24 import java.io.File JavaDoc;
25 import java.io.FileInputStream JavaDoc;
26 import java.io.FileNotFoundException JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.net.URI JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Arrays JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.HashSet JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.List JavaDoc;
38 import java.util.Locale JavaDoc;
39 import java.util.Set JavaDoc;
40 import java.util.jar.JarEntry JavaDoc;
41 import java.util.jar.JarInputStream JavaDoc;
42 import java.util.jar.JarOutputStream JavaDoc;
43 import java.util.jar.Manifest JavaDoc;
44
45 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
46 import javax.enterprise.deploy.shared.ActionType JavaDoc;
47 import javax.enterprise.deploy.shared.CommandType JavaDoc;
48 import javax.enterprise.deploy.shared.DConfigBeanVersionType JavaDoc;
49 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
50 import javax.enterprise.deploy.shared.StateType JavaDoc;
51 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
52 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
53 import javax.enterprise.deploy.spi.Target JavaDoc;
54 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
55 import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException JavaDoc;
56 import javax.enterprise.deploy.spi.exceptions.InvalidModuleException JavaDoc;
57 import javax.enterprise.deploy.spi.exceptions.TargetException JavaDoc;
58 import javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc;
59 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
60
61 import org.dom4j.Document;
62 import org.dom4j.io.SAXReader;
63 import org.jboss.deployment.spi.configurations.WarConfiguration;
64 import org.jboss.deployment.spi.status.DeploymentStatusImpl;
65 import org.jboss.deployment.spi.status.ProgressObjectImpl;
66 import org.jboss.logging.Logger;
67 import org.jboss.util.xml.JBossEntityResolver;
68
69 /**
70  * The DeploymentManager object provides the core set of functions a J2EE
71  * platform must provide for J2EE application deployment. It provides server
72  * related information, such as, a list of deployment targets, and vendor unique
73  * runtime configuration information.
74  * @author thomas.diesler@jboss.org
75  * @version $Revision: 46437 $
76  */

77 public class DeploymentManagerImpl implements DeploymentManager JavaDoc
78 {
79    // deployment logging
80
private static final Logger log = Logger.getLogger(DeploymentManagerImpl.class);
81
82    /** The URI deployment factory recoginzes: http://org.jboss.deployment/jsr88 */
83    public static final String JavaDoc DEPLOYER_URI = "http://org.jboss.deployment/jsr88";
84
85    // available deployment targets
86
private Target JavaDoc[] targets;
87
88    // maps the DD to the archives
89
private HashMap JavaDoc mapDeploymentPlan;
90    private DeploymentMetaData metaData;
91
92    private List JavaDoc tmpFiles = new ArrayList JavaDoc();
93    private URI JavaDoc deployURI;
94    private boolean isConnected;
95
96    /**
97     * Create a deployment manager for the given URL and connected mode.
98     *
99     * @param deployURI
100     * @param isConnected
101     */

102    public DeploymentManagerImpl(URI JavaDoc deployURI, boolean isConnected)
103    {
104       this(deployURI, isConnected, null, null);
105    }
106
107    /**
108     * Create a deployment manager for the given URL and connected mode, username
109     * and password.
110     *
111     * @param deployURI
112     * @param isConnected
113     * @param username
114     * @param password
115     */

116    public DeploymentManagerImpl(URI JavaDoc deployURI, boolean isConnected, String JavaDoc username, String JavaDoc password)
117    {
118       this.deployURI = deployURI;
119       this.isConnected = isConnected;
120       this.targets = null;
121    }
122
123    /**
124     * Get the available targets. This is determined by parsing the deployURI.
125     * Currently there is only one target, either a JMXTarget that uses
126     * the RMIAdaptor based on the URI info, or a LocalhostTarget if the
127     * URI opaque.
128     *
129     * @return the available targets
130     * @throws IllegalStateException when the manager is disconnected
131     */

132    public Target JavaDoc[] getTargets()
133    {
134       if (isConnected == false)
135          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
136
137       if (targets == null)
138       {
139          if (deployURI.isOpaque())
140          {
141             log.debug("Opaque URI seen, defaulting to LocalhostTarget");
142             targets = new Target JavaDoc[] { new LocalhostTarget() };
143          }
144          else
145          {
146             log.debug("Non-Opaque URI seen, using to JMXTarget");
147             targets = new Target JavaDoc[] { new JMXTarget(deployURI) };
148          }
149       }
150       return targets;
151    }
152
153    /**
154     * Get the running modules
155     *
156     * @param moduleType the module type
157     * @param targets the targets
158     * @return the target modules
159     * @throws javax.enterprise.deploy.spi.exceptions.TargetException
160     * an invalid target
161     * @throws IllegalStateException when the manager is disconnected
162     */

163    public TargetModuleID JavaDoc[] getRunningModules(ModuleType JavaDoc moduleType, Target JavaDoc[] targets) throws TargetException JavaDoc
164    {
165       if (isConnected == false)
166          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
167
168       log.debug("getRunningModules [type=" + moduleType + ",targets=" + Arrays.asList(targets) + "]");
169
170       // get running modules
171
Set JavaDoc moduleSet = new HashSet JavaDoc();
172       TargetModuleID JavaDoc[] availableModules = getAvailableModules(moduleType, targets);
173       if (availableModules == null)
174       {
175          log.debug("No modules available");
176          return null;
177       }
178
179       for (int i = 0; i < availableModules.length; i++)
180       {
181          TargetModuleIDImpl moduleID = (TargetModuleIDImpl)availableModules[i];
182          if (moduleID.isRunning())
183          {
184             moduleSet.add(moduleID);
185          }
186       }
187       log.debug("Found [" + moduleSet.size() + "] running modules");
188
189       // convert set to array
190
TargetModuleID JavaDoc[] idarr = new TargetModuleID JavaDoc[moduleSet.size()];
191       moduleSet.toArray(idarr);
192       return idarr;
193    }
194
195    /**
196     * Get the non running modules
197     *
198     * @param moduleType the module type
199     * @param targets the targets
200     * @return the target modules
201     * @throws javax.enterprise.deploy.spi.exceptions.TargetException
202     * an invalid target
203     * @throws IllegalStateException when the manager is disconnected
204     */

205    public TargetModuleID JavaDoc[] getNonRunningModules(ModuleType JavaDoc moduleType, Target JavaDoc[] targets) throws TargetException JavaDoc
206    {
207       if (isConnected == false)
208          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
209
210       log.debug("getNonRunningModules [type=" + moduleType + ",targets=" + Arrays.asList(targets) + "]");
211
212       // get non running modules
213
Set JavaDoc moduleSet = new HashSet JavaDoc();
214       TargetModuleID JavaDoc[] availableModules = getAvailableModules(moduleType, targets);
215       if (availableModules == null)
216       {
217          log.debug("No modules available");
218          return null;
219       }
220       
221       for (int i = 0; i < availableModules.length; i++)
222       {
223          TargetModuleIDImpl moduleID = (TargetModuleIDImpl)availableModules[i];
224          if (moduleID.isRunning() == false)
225          {
226             moduleSet.add(moduleID);
227          }
228       }
229       log.debug("Found [" + moduleSet.size() + "] non running modules");
230
231       // convert set to array
232
TargetModuleID JavaDoc[] idarr = new TargetModuleID JavaDoc[moduleSet.size()];
233       moduleSet.toArray(idarr);
234       return idarr;
235    }
236
237    /**
238     * Retrieve the list of all J2EE application modules running or not running on the identified targets.
239     *
240     * @param moduleType the module type
241     * @param targets the targets
242     * @return the target modules
243     * @throws javax.enterprise.deploy.spi.exceptions.TargetException
244     * an invalid target
245     * @throws IllegalStateException when the manager is disconnected
246     */

247    public TargetModuleID JavaDoc[] getAvailableModules(ModuleType JavaDoc moduleType, Target JavaDoc[] targets) throws TargetException JavaDoc
248    {
249       if (isConnected == false)
250          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
251
252       log.debug("getAvailableModules [type=" + moduleType + ",targets=" + Arrays.asList(targets) + "]");
253
254       // get non running modules
255
List JavaDoc targetModules = new ArrayList JavaDoc();
256       for (int i = 0; i < targets.length; i++)
257       {
258          JBossTarget target = (JBossTarget)targets[i];
259          TargetModuleID JavaDoc[] tmids = target.getAvailableModules(moduleType);
260          targetModules.addAll(Arrays.asList(tmids));
261       }
262       log.debug("Found [" + targetModules.size() + "] available modules");
263
264       // convert set to array
265
if (targetModules.size() > 0)
266       {
267          TargetModuleID JavaDoc[] idarr = new TargetModuleID JavaDoc[targetModules.size()];
268          targetModules.toArray(idarr);
269          return idarr;
270       }
271
272       // according to the spec, we have to return null
273
return null;
274    }
275
276    /**
277     * Retrieve server specific configuration for a component
278     *
279     * @param obj the deployable component
280     * @return the configuration
281     * @throws javax.enterprise.deploy.spi.exceptions.InvalidModuleException
282     * when the module does not exist or is not supported
283     */

284    public DeploymentConfiguration JavaDoc createConfiguration(DeployableObject JavaDoc obj) throws InvalidModuleException JavaDoc
285    {
286       // do some stuff to figure out what kind of config to return.
287
if (obj.getType().equals(ModuleType.WAR))
288          return new WarConfiguration(obj);
289
290       throw new InvalidModuleException JavaDoc("CreateConfiguration: Module type not yet supported");
291    }
292
293    /**
294     * Validates the configuration, generates all container specific classes and moves the archive
295     * to the targets
296     *
297     * @param targets the targets
298     * @param moduleArchive the module archive
299     * @param deploymentPlan the runtime configuration
300     * @return the progress object
301     * @throws IllegalStateException when the manager is disconnected
302     */

303    public ProgressObject JavaDoc distribute(Target JavaDoc[] targets, File JavaDoc moduleArchive, File JavaDoc deploymentPlan)
304    {
305       if (isConnected == false)
306          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
307
308       InputStream JavaDoc isModuleArchive = null;
309       InputStream JavaDoc isDeploymentPlan = null;
310       try
311       {
312          isModuleArchive = new FileInputStream JavaDoc(moduleArchive);
313          isDeploymentPlan = new FileInputStream JavaDoc(deploymentPlan);
314          return distribute(targets, isModuleArchive, isDeploymentPlan);
315       }
316       catch (FileNotFoundException JavaDoc e)
317       {
318          String JavaDoc message = "Cannot find deployment file" + e.getMessage();
319          log.error(message, e);
320          DeploymentStatus JavaDoc status = new DeploymentStatusImpl(StateType.FAILED, CommandType.DISTRIBUTE, ActionType.EXECUTE, message);
321          return new ProgressObjectImpl(status, null);
322       }
323    }
324
325    /**
326     * Validates the configuration, generates all container specific classes and moves the archive
327     * to the targets
328     *
329     * @param targets the targets
330     * @param moduleArchive the module archive
331     * @param deploymentPlan the runtime configuration
332     * @return the progress object
333     * @throws IllegalStateException when the manager is disconnected
334     */

335    public ProgressObject JavaDoc distribute(Target JavaDoc[] targets, InputStream JavaDoc moduleArchive, InputStream JavaDoc deploymentPlan)
336    {
337       if (isConnected == false)
338          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
339
340       TargetModuleID JavaDoc[] targetModuleIDs = new TargetModuleID JavaDoc[targets.length];
341       try
342       {
343          // create for each entry in the deploymentPlan a temp file
344
mapDeploymentPlan = unpackDeploymentPlan(deploymentPlan);
345          initDeploymentMetaData();
346
347          // create the temp file that contains the deployment
348
TargetModuleInfo moduleInfo = createDeployment(moduleArchive, metaData.getDeploymentName());
349          URL JavaDoc deployment = moduleInfo.getModuleID();
350
351          // create the target module ids
352
for (int i = 0; i < targets.length; i++)
353          {
354             JBossTarget target = (JBossTarget)targets[i];
355             String JavaDoc moduleID = deployment.toExternalForm();
356             targetModuleIDs[i] = new TargetModuleIDImpl(target, moduleID, null, false, moduleInfo.getModuleType());
357          }
358
359          // delete all temp files, except the depoyment
360
for (int i = 0; i < tmpFiles.size(); i++)
361          {
362             File JavaDoc file = (File JavaDoc)tmpFiles.get(i);
363             if (file.equals(deployment) == false)
364                file.delete();
365          }
366       }
367       catch (IOException JavaDoc e)
368       {
369          String JavaDoc message = "Exception during deployment validation";
370          log.error(message, e);
371          DeploymentStatus JavaDoc status = new DeploymentStatusImpl(StateType.FAILED, CommandType.DISTRIBUTE, ActionType.EXECUTE, message);
372          return new ProgressObjectImpl(status, targetModuleIDs);
373       }
374
375       // start the deployment process
376
DeploymentStatus JavaDoc status = new DeploymentStatusImpl(StateType.RUNNING, CommandType.DISTRIBUTE, ActionType.EXECUTE, null);
377       ProgressObject JavaDoc progress = new ProgressObjectImpl(status, targetModuleIDs);
378
379       DeploymentWorker worker = new DeploymentWorker(progress);
380       worker.start();
381
382       return progress;
383    }
384
385    /**
386     * Initialize the deployment meta data
387     */

388    private void initDeploymentMetaData() throws IOException JavaDoc
389    {
390       File JavaDoc metaTmpFile = (File JavaDoc)mapDeploymentPlan.get(DeploymentMetaData.ENTRY_NAME);
391       if (metaTmpFile == null)
392          throw new IOException JavaDoc("Deployment plan does not contain an entry: " + DeploymentMetaData.ENTRY_NAME);
393
394       try
395       {
396          SAXReader reader = new SAXReader();
397          reader.setEntityResolver(new JBossEntityResolver());
398
399          Document metaDoc = reader.read(metaTmpFile);
400          metaData = new DeploymentMetaData(metaDoc);
401          log.debug(DeploymentMetaData.ENTRY_NAME + "\n" + metaData.toXMLString());
402       }
403       catch (Exception JavaDoc e)
404       {
405          log.error("Cannot obtain meta data: " + e);
406       }
407    }
408
409    /**
410     * Create the JBoss deployment, by enhancing the content of the module
411     * archive with the entries in the deployment plan.
412     */

413    private TargetModuleInfo createDeployment(InputStream JavaDoc moduleArchive, String JavaDoc moduleName) throws IOException JavaDoc
414    {
415       File JavaDoc tmpFile = File.createTempFile("jboss_deployment_", ".zip");
416       log.debug("temporary deployment file: " + tmpFile);
417
418       JarInputStream JavaDoc jis = new JarInputStream JavaDoc(moduleArchive);
419
420       // make sure we don't loose the manifest when creating a new JarOutputStream
421
JarOutputStream JavaDoc jos = null;
422       FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(tmpFile);
423       Manifest JavaDoc manifest = jis.getManifest();
424       if (manifest != null)
425          jos = new JarOutputStream JavaDoc(fos, manifest);
426       else jos = new JarOutputStream JavaDoc(fos);
427
428       // process all modules
429
TargetModuleInfo moduleInfo = new TargetModuleInfo();
430       ModuleType JavaDoc moduleType = null;
431       JarEntry JavaDoc entry = jis.getNextJarEntry();
432       while (entry != null)
433       {
434          String JavaDoc entryName = entry.getName();
435
436          // only process file entries
437
if (entryName.endsWith("/") == false)
438          {
439             if (entryName.endsWith("/application.xml"))
440             {
441                moduleType = ModuleType.EAR;
442             }
443             else if (entryName.endsWith("/application-client.xml"))
444             {
445                moduleType = ModuleType.CAR;
446             }
447             else if (entryName.endsWith("/ra.xml"))
448             {
449                moduleType = ModuleType.RAR;
450             }
451             else if (entryName.endsWith("/web.xml"))
452             {
453                moduleType = ModuleType.WAR;
454             }
455             else if (entryName.endsWith("/ejb-jar.xml"))
456             {
457                moduleType = ModuleType.EJB;
458             }
459
460             // process a sub module
461
if (entryName.endsWith(".jar") || entryName.endsWith(".war"))
462             {
463                File JavaDoc tmpSubModule = processSubModule(entryName, jis);
464                FileInputStream JavaDoc fis = new FileInputStream JavaDoc(tmpSubModule);
465                JarUtils.addJarEntry(jos, entryName, fis);
466                fis.close();
467             }
468             else
469             {
470                if (mapDeploymentPlan.get("!/" + entryName) == null)
471                   JarUtils.addJarEntry(jos, entryName, jis);
472                else log.debug("Skip entry found in deployment plan: " + entryName);
473             }
474          }
475
476          entry = jis.getNextJarEntry();
477       }
478
479       if (moduleType == null)
480       {
481          if (moduleName.endsWith(ModuleType.EAR.getModuleExtension()))
482             moduleType = ModuleType.EAR;
483          else
484             throw new RuntimeException JavaDoc("cannot obtain module type");
485       }
486
487       moduleInfo.setModuleType(moduleType);
488       // there may be top level deployment plan entries, add them
489
addDeploymentPlanEntry(jos, null);
490       jos.close();
491
492       // rename the deployment
493
String JavaDoc deploymentName = tmpFile.getParent() + File.separator + metaData.getDeploymentName();
494       File JavaDoc deployment = new File JavaDoc(deploymentName);
495       if (deployment.exists() && deployment.delete() == false)
496          throw new IOException JavaDoc("Cannot delete existing deployment: " + deployment);
497
498       tmpFile.renameTo(deployment);
499       moduleInfo.setModuleID(deployment.toURL());
500       return moduleInfo;
501    }
502
503    public ProgressObject JavaDoc redeploy(TargetModuleID JavaDoc[] targetModuleIDs, File JavaDoc file, File JavaDoc file1) throws UnsupportedOperationException JavaDoc, IllegalStateException JavaDoc
504    {
505       if (isConnected == false)
506          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
507
508       throw new UnsupportedOperationException JavaDoc("redeploy");
509    }
510
511    public ProgressObject JavaDoc redeploy(TargetModuleID JavaDoc[] targetModuleIDs, InputStream JavaDoc inputStream, InputStream JavaDoc inputStream1) throws UnsupportedOperationException JavaDoc,
512          IllegalStateException JavaDoc
513    {
514       if (isConnected == false)
515          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
516
517       throw new UnsupportedOperationException JavaDoc("redeploy");
518    }
519
520    /**
521     * Start the modules
522     *
523     * @param targetModuleIDs the list of modules
524     * @return the progress object
525     * @throws IllegalStateException when the manager is disconnected
526     */

527    public ProgressObject JavaDoc start(TargetModuleID JavaDoc[] targetModuleIDs)
528    {
529       if (isConnected == false)
530          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
531
532       log.debug("start " + Arrays.asList(targetModuleIDs));
533
534       // start the deployment process
535
DeploymentStatus JavaDoc status = new DeploymentStatusImpl(StateType.RUNNING, CommandType.START, ActionType.EXECUTE, null);
536       ProgressObject JavaDoc progress = new ProgressObjectImpl(status, targetModuleIDs);
537
538       DeploymentWorker worker = new DeploymentWorker(progress);
539       worker.start();
540
541       return progress;
542    }
543
544    /**
545     * Stop the modules
546     *
547     * @param targetModuleIDs the list of modules
548     * @return the progress object
549     * @throws IllegalStateException when the manager is disconnected
550     */

551    public ProgressObject JavaDoc stop(TargetModuleID JavaDoc[] targetModuleIDs)
552    {
553       if (isConnected == false)
554          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
555
556       log.debug("stop " + Arrays.asList(targetModuleIDs));
557
558       DeploymentStatus JavaDoc status = new DeploymentStatusImpl(StateType.RUNNING, CommandType.STOP, ActionType.EXECUTE, null);
559       ProgressObject JavaDoc progress = new ProgressObjectImpl(status, targetModuleIDs);
560
561       DeploymentWorker worker = new DeploymentWorker(progress);
562       worker.start();
563
564       return progress;
565    }
566
567    /**
568     * Removes the modules
569     *
570     * @param targetModuleIDs the list of modules
571     * @return the progress object
572     * @throws IllegalStateException when the manager is disconnected
573     */

574    public ProgressObject JavaDoc undeploy(TargetModuleID JavaDoc[] targetModuleIDs)
575    {
576       if (isConnected == false)
577          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
578
579       log.debug("undeploy " + Arrays.asList(targetModuleIDs));
580
581       // start the deployment process
582
DeploymentStatus JavaDoc status = new DeploymentStatusImpl(StateType.RUNNING, CommandType.UNDEPLOY, ActionType.EXECUTE, null);
583       ProgressObject JavaDoc progress = new ProgressObjectImpl(status, targetModuleIDs);
584
585       DeploymentWorker worker = new DeploymentWorker(progress);
586       worker.start();
587
588       return progress;
589    }
590
591    /**
592     * Is redeploy supported
593     *
594     * @return true when redeploy is supported, false otherwise
595     */

596    public boolean isRedeploySupported()
597    {
598       return false;
599    }
600
601    /**
602     * Redeploys the modules
603     *
604     * @param moduleIDList the list of modules
605     * @return the progress object
606     * @throws IllegalStateException when the manager is disconnected
607     * @throws UnsupportedOperationException when redeploy is not supported
608     */

609    public ProgressObject JavaDoc redeploy(TargetModuleID JavaDoc[] moduleIDList)
610    {
611       if (isConnected == false)
612          throw new IllegalStateException JavaDoc("DeploymentManager is not connected");
613
614       throw new UnsupportedOperationException JavaDoc("redeploy");
615    }
616
617    /**
618     * The release method is the mechanism by which the tool signals to the DeploymentManager that the tool does not need
619     * it to continue running connected to the platform. The tool may be signaling it wants to run in a
620     * disconnected mode or it is planning to shutdown.
621     * When release is called the DeploymentManager may close any J2EE resource connections it had for deployment
622     * configuration and perform other related resource cleanup.
623     * It should not accept any new operation requests (i.e., distribute, start stop, undeploy, redeploy.
624     * It should finish any operations that are currently in process.
625     * Each ProgressObject associated with a running operation should be marked as released (see the ProgressObject).
626     */

627    public void release()
628    {
629       isConnected = false;
630    }
631
632    /**
633     * Get the default locale
634     *
635     * @return the default locale
636     */

637    public Locale JavaDoc getDefaultLocale()
638    {
639       return Locale.getDefault();
640    }
641
642    /**
643     * Currently we only support the default locale
644     */

645    public Locale JavaDoc getCurrentLocale()
646    {
647       return Locale.getDefault();
648    }
649
650    /**
651     * Currently we only support the default locale
652     */

653    public void setLocale(Locale JavaDoc locale)
654    {
655       throw new UnsupportedOperationException JavaDoc("setLocale");
656    }
657
658    /**
659     * Currently we only support the default locale
660     */

661    public boolean isLocaleSupported(Locale JavaDoc locale)
662    {
663       return Locale.getDefault().equals(locale);
664    }
665
666    /**
667     * Currently we only support the default locale
668     *
669     * @return the supported locales
670     */

671    public Locale JavaDoc[] getSupportedLocales()
672    {
673       return new Locale JavaDoc[] { Locale.getDefault() };
674    }
675
676    /**
677     * Get the J2EE platform version
678     *
679     * @return the version
680     */

681    public DConfigBeanVersionType JavaDoc getDConfigBeanVersion()
682    {
683       return DConfigBeanVersionType.V1_4;
684    }
685
686    public void setDConfigBeanVersion(DConfigBeanVersionType JavaDoc dConfigBeanVersionType) throws DConfigBeanVersionUnsupportedException JavaDoc
687    {
688       throw new UnsupportedOperationException JavaDoc("setDConfigBeanVersion");
689    }
690
691    public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType JavaDoc dConfigBeanVersionType)
692    {
693       return dConfigBeanVersionType == DConfigBeanVersionType.V1_4;
694    }
695
696    /**
697     * Test whether the version is supported
698     *
699     * @param version the version
700     * @return true when supported, false otherwise
701     */

702    public boolean isDConfigBeanVersionTypeSupported(DConfigBeanVersionType JavaDoc version)
703    {
704       return version == DConfigBeanVersionType.V1_4;
705    }
706
707    /**
708     * Set the J2EE version
709     *
710     * @param version the version
711     * @throws UnsupportedOperationException when the version is not supported
712     */

713    public void setDConfigBeanVersionType(DConfigBeanVersionType JavaDoc version)
714    {
715       throw new UnsupportedOperationException JavaDoc("setDConfigBeanVersionType");
716    }
717
718    /**
719     * Process a potential sub module, adding descriptors from the deployment plan
720     */

721    private File JavaDoc processSubModule(String JavaDoc entryName, JarInputStream JavaDoc jis) throws IOException JavaDoc
722    {
723       // first copy te entry as is to a temp file
724
File JavaDoc tmpModule = getTempFile(entryName);
725       tmpFiles.add(tmpModule);
726       FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(tmpModule);
727       JarUtils.copyStream(fos, jis);
728       fos.close();
729
730       // now open the copy we just made and copy again entry by entry
731
JarInputStream JavaDoc jisModule = new JarInputStream JavaDoc(new FileInputStream JavaDoc(tmpModule));
732       File JavaDoc tmpJBossModule = getTempFile("jboss_" + entryName);
733       tmpFiles.add(tmpJBossModule);
734       JarOutputStream JavaDoc jos = null;
735       fos = new FileOutputStream JavaDoc(tmpJBossModule);
736       Manifest JavaDoc manifest = jisModule.getManifest();
737       if (manifest != null)
738          jos = new JarOutputStream JavaDoc(fos, manifest);
739       else jos = new JarOutputStream JavaDoc(fos);
740
741       // now copy entry by entry
742
JarEntry JavaDoc entry = jisModule.getNextJarEntry();
743       while (entry != null)
744       {
745          String JavaDoc subEntryName = entry.getName();
746          if (mapDeploymentPlan.get(entryName + "!/" + subEntryName) == null)
747             JarUtils.addJarEntry(jos, subEntryName, jisModule);
748          else log.debug("Skip entry found in deployment plan: " + subEntryName);
749
750          entry = jisModule.getNextJarEntry();
751       }
752       jisModule.close();
753
754       addDeploymentPlanEntry(jos, entryName);
755
756       jos.close();
757
758       return tmpJBossModule;
759    }
760
761    /**
762     * Add an entry from the deployment plan, if found
763     * @param moduleName entries will be added for that module, null indicates top level
764     */

765    private void addDeploymentPlanEntry(JarOutputStream JavaDoc jos, String JavaDoc moduleName) throws IOException JavaDoc
766    {
767       if (moduleName == null)
768          moduleName = "";
769
770       // ignore deployment plan entries that do not start like this
771
String JavaDoc moduleKey = moduleName + "!/";
772
773       Iterator JavaDoc it = mapDeploymentPlan.keySet().iterator();
774       while (it.hasNext())
775       {
776          String JavaDoc key = (String JavaDoc)it.next();
777          if (key.startsWith(moduleKey))
778          {
779             String JavaDoc dpName = key.substring(moduleKey.length());
780             log.debug("found deployment plan entry: " + dpName);
781
782             File JavaDoc dpFile = (File JavaDoc)mapDeploymentPlan.get(key);
783             FileInputStream JavaDoc dpin = new FileInputStream JavaDoc(dpFile);
784             JarUtils.addJarEntry(jos, dpName, dpin);
785             dpin.close();
786          }
787       }
788    }
789
790    /**
791     * Create a temp file for every entry in the deployment plan
792     */

793    private HashMap JavaDoc unpackDeploymentPlan(InputStream JavaDoc deploymentPlan) throws IOException JavaDoc
794    {
795       HashMap JavaDoc dpMap = new HashMap JavaDoc();
796
797       if (deploymentPlan == null)
798          return dpMap;
799
800       // process the deployment plan
801
try
802       {
803          JarInputStream JavaDoc jarDeploymentPlan = new JarInputStream JavaDoc(deploymentPlan);
804          JarEntry JavaDoc entry = jarDeploymentPlan.getNextJarEntry();
805          while (entry != null)
806          {
807             String JavaDoc entryName = entry.getName();
808             log.debug("unpack deployment plan entry: " + entryName);
809
810             File JavaDoc tempFile = getTempFile(entryName);
811             dpMap.put(entryName, tempFile);
812
813             FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(tempFile);
814             JarUtils.copyStream(out, jarDeploymentPlan);
815             out.close();
816
817             entry = jarDeploymentPlan.getNextJarEntry();
818          }
819       }
820       finally
821       {
822          deploymentPlan.close();
823       }
824
825       return dpMap;
826    }
827
828    /**
829     * Get a temp file for an jar entry name
830     */

831    private File JavaDoc getTempFile(String JavaDoc entryName) throws IOException JavaDoc
832    {
833       entryName = entryName.replace('/', '_');
834       int index = entryName.lastIndexOf(".");
835       String JavaDoc prefix = entryName.substring(0, index);
836       String JavaDoc suffix = entryName.substring(index);
837
838       File JavaDoc tempFile = File.createTempFile(prefix, suffix);
839       tmpFiles.add(tempFile);
840       return tempFile;
841    }
842
843    static private class TargetModuleInfo
844    {
845       URL JavaDoc moduleID = null;
846       ModuleType JavaDoc moduleType = null;
847
848       public URL JavaDoc getModuleID()
849       {
850          return moduleID;
851       }
852
853       public void setModuleID(URL JavaDoc url)
854       {
855          moduleID = url;
856       }
857
858       public ModuleType JavaDoc getModuleType()
859       {
860          return moduleType;
861       }
862
863       public void setModuleType(ModuleType JavaDoc type)
864       {
865          moduleType = type;
866       }
867    }
868 }
869
Popular Tags