001: /**
002: * JOnAS : Java(TM) OpenSource Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: DummyApplication.java 6641 2005-04-25 16:14:13Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_lib.genbase.archive;
025:
026: import java.io.File;
027: import java.io.FileOutputStream;
028: import java.io.IOException;
029: import java.io.OutputStream;
030: import java.util.Vector;
031: import java.util.jar.Attributes;
032: import java.util.jar.Manifest;
033:
034: import org.objectweb.jonas_lib.files.FileUtils;
035: import org.objectweb.jonas_lib.files.FileUtilsException;
036: import org.objectweb.jonas_lib.genbase.GenBaseException;
037: import org.objectweb.jonas_lib.genbase.utils.TempRepository;
038: import org.objectweb.jonas_lib.genbase.utils.XMLUtils;
039:
040: /**
041: * DummyApplication is a wrapper for auto generated application archive.
042: *
043: * @author Guillaume Sauthier
044: */
045: public class DummyApplication extends Application {
046:
047: /** application filename */
048: private String name;
049:
050: /**
051: * Creates a new Application archive.
052: *
053: * @param name the file containing the application archive.
054: *
055: * @throws GenBaseException When Init fails
056: */
057: public DummyApplication(String name) throws GenBaseException {
058: super (createFileArchive());
059: this .name = name;
060: init();
061: }
062:
063: /**
064: * Create a new FileArchive
065: *
066: * @return a new Archive
067: *
068: * @throws GenBaseException When Archive creation fails.
069: */
070: private static Archive createFileArchive() throws GenBaseException {
071: TempRepository tr = TempRepository.getInstance();
072:
073: try {
074: File tmp = tr.createDir();
075: File meta = new File(tmp, "META-INF");
076: meta.mkdirs();
077:
078: File manifest = new File(meta, "MANIFEST.MF");
079:
080: Manifest mf = new Manifest();
081: mf.getMainAttributes().putValue(
082: Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
083:
084: OutputStream os = new FileOutputStream(manifest);
085: mf.write(os);
086: os.close();
087:
088: String jonasRoot = System.getProperty("install.root");
089: File appTemplate = new File(new File(jonasRoot),
090: "templates" + File.separator + "wsgen"
091: + File.separator + "application.xml");
092: FileUtils.copyFile(appTemplate, meta);
093:
094: return new FileArchive(tmp);
095: } catch (IOException ioe) {
096: throw new GenBaseException(ioe);
097: } catch (FileUtilsException fue) {
098: throw new GenBaseException(fue);
099: }
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());
111: setWebapps(new Vector());
112: setClients(new Vector());
113:
114: loadDescriptors();
115:
116: XMLUtils.cleanDummyApplication(getApp());
117:
118: }
119:
120: /**
121: * @return Returns the DummyApplication filename.
122: */
123: public String getName() {
124: return name;
125: }
126:
127: }
|