KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > genbase > archive > DummyApplication


1 /**
2  * JOnAS : Java(TM) OpenSource Application Server
3  * Copyright (C) 1999-2004 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: DummyApplication.java,v 1.2 2005/04/25 16:14:13 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_lib.genbase.archive;
27
28 import java.io.File JavaDoc;
29 import java.io.FileOutputStream JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.OutputStream JavaDoc;
32 import java.util.Vector JavaDoc;
33 import java.util.jar.Attributes JavaDoc;
34 import java.util.jar.Manifest JavaDoc;
35
36 import org.objectweb.jonas_lib.files.FileUtils;
37 import org.objectweb.jonas_lib.files.FileUtilsException;
38 import org.objectweb.jonas_lib.genbase.GenBaseException;
39 import org.objectweb.jonas_lib.genbase.utils.TempRepository;
40 import org.objectweb.jonas_lib.genbase.utils.XMLUtils;
41
42 /**
43  * DummyApplication is a wrapper for auto generated application archive.
44  *
45  * @author Guillaume Sauthier
46  */

47 public class DummyApplication extends Application {
48
49     /** application filename */
50     private String JavaDoc name;
51
52     /**
53      * Creates a new Application archive.
54      *
55      * @param name the file containing the application archive.
56      *
57      * @throws GenBaseException When Init fails
58      */

59     public DummyApplication(String JavaDoc name) throws GenBaseException {
60         super(createFileArchive());
61         this.name = name;
62         init();
63     }
64
65     /**
66      * Create a new FileArchive
67      *
68      * @return a new Archive
69      *
70      * @throws GenBaseException When Archive creation fails.
71      */

72     private static Archive createFileArchive() throws GenBaseException {
73         TempRepository tr = TempRepository.getInstance();
74
75         try {
76             File JavaDoc tmp = tr.createDir();
77             File JavaDoc meta = new File JavaDoc(tmp, "META-INF");
78             meta.mkdirs();
79
80             File JavaDoc manifest = new File JavaDoc(meta, "MANIFEST.MF");
81
82             Manifest JavaDoc mf = new Manifest JavaDoc();
83             mf.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
84
85             OutputStream JavaDoc os = new FileOutputStream JavaDoc(manifest);
86             mf.write(os);
87             os.close();
88
89             String JavaDoc jonasRoot = System.getProperty("install.root");
90             File JavaDoc appTemplate = new File JavaDoc(new File JavaDoc(jonasRoot), "templates" + File.separator + "wsgen" + File.separator
91                     + "application.xml");
92             FileUtils.copyFile(appTemplate, meta);
93
94             return new FileArchive(tmp);
95         } catch (IOException JavaDoc ioe) {
96             throw new GenBaseException(ioe);
97         } catch (FileUtilsException fue) {
98             throw new GenBaseException(fue);
99         }
100     }
101
102     /**
103      * Initialize the DummyApplication. Creates modules lists. Overriddes
104      * Application.init() behavior
105      *
106      * @throws GenBaseException When Descriptor cannot be parsed.
107      */

108     protected void init() throws GenBaseException {
109         // remove dummy modules
110
setEjbjars(new Vector JavaDoc());
111         setWebapps(new Vector JavaDoc());
112         setClients(new Vector JavaDoc());
113
114         loadDescriptors();
115
116         XMLUtils.cleanDummyApplication(getApp());
117
118     }
119
120     /**
121      * @return Returns the DummyApplication filename.
122      */

123     public String JavaDoc getName() {
124         return name;
125     }
126
127 }
Popular Tags