KickJava   Java API By Example, From Geeks To Geeks.

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


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: DummyWebApp.java,v 1.3 2005/07/18 23:53:30 mwringe 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.jar.Attributes JavaDoc;
33 import java.util.jar.Manifest JavaDoc;
34
35 import org.objectweb.jonas_lib.files.FileUtils;
36 import org.objectweb.jonas_lib.files.FileUtilsException;
37 import org.objectweb.jonas_lib.genbase.GenBaseException;
38 import org.objectweb.jonas_lib.genbase.utils.TempRepository;
39
40
41 /**
42  * DummyWebApp is a wrapper for auto generated webapp archive.
43  *
44  * @author Guillaume Sauthier
45  */

46 public class DummyWebApp extends WebApp {
47
48     /** webapp name */
49     private String JavaDoc name;
50
51     /**
52      * Creates a new DummyWebApp archive.
53      *
54      * @param app the file containing the webapp archive.
55      * @param name webapp filename
56      *
57      * @throws GenBaseException when archive creation fails.
58      */

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

71     private static Archive createFileArchive() throws GenBaseException {
72         TempRepository tr = TempRepository.getInstance();
73
74         try {
75             File JavaDoc tmp = tr.createDir();
76             File JavaDoc meta = new File JavaDoc(tmp, "META-INF");
77             meta.mkdirs();
78
79             File JavaDoc web = new File JavaDoc(tmp, "WEB-INF");
80             web.mkdirs();
81
82             File JavaDoc manifest = new File JavaDoc(meta, "MANIFEST.MF");
83
84             Manifest JavaDoc mf = new Manifest JavaDoc();
85             mf.getMainAttributes().putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
86
87             OutputStream JavaDoc os = new FileOutputStream JavaDoc(manifest);
88             mf.write(os);
89             os.close();
90
91             String JavaDoc jonasRoot = System.getProperty("install.root");
92             File JavaDoc webTemplate = new File JavaDoc(new File JavaDoc(jonasRoot), "templates" + File.separator + "wsgen" + File.separator
93                     + "web.xml");
94             FileUtils.copyFile(webTemplate, web);
95
96             //Load context.xml, used by Tomcat to determine security realm to use (if any)
97
File JavaDoc contextTemplate = new File JavaDoc(new File JavaDoc(jonasRoot), "templates"
98                   + File.separator + "wsgen" + File.separator + "context.xml");
99             FileUtils.copyFile(contextTemplate, meta);
100
101             //Load web-jetty.xml, used by Jetty to determine security realm to use (if any)
102
File JavaDoc webjettyTemplate = new File JavaDoc(new File JavaDoc(jonasRoot), "templates"
103                   + File.separator + "wsgen" + File.separator + "web-jetty.xml");
104             FileUtils.copyFile(webjettyTemplate, web);
105
106             return new FileArchive(tmp);
107         } catch (IOException JavaDoc ioe) {
108             throw new GenBaseException(ioe);
109         } catch (FileUtilsException fue) {
110             throw new GenBaseException(fue);
111         }
112     }
113
114     /**
115      * @return Returns the DummyApplication filename.
116      */

117     public String JavaDoc getName() {
118         return name;
119     }
120
121 }
Popular Tags