KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > genbase > modifier > ArchiveModifier


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2003-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: ArchiveModifier.java,v 1.2 2005/04/28 16:53:00 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_lib.genbase.modifier;
27
28 import java.io.File JavaDoc;
29
30 import org.objectweb.jonas_lib.genbase.GenBaseException;
31 import org.objectweb.jonas_lib.genbase.archive.Archive;
32 import org.objectweb.jonas_lib.genbase.archive.FileArchive;
33 import org.objectweb.jonas_lib.genbase.archive.J2EEArchive;
34 import org.objectweb.jonas_lib.genbase.archive.JarArchive;
35 import org.objectweb.jonas_lib.genbase.generator.Config;
36 import org.objectweb.jonas_lib.genbase.utils.ArchiveStorer;
37 import org.objectweb.jonas_lib.genbase.utils.DirStorer;
38 import org.objectweb.jonas_lib.genbase.utils.JarStorer;
39
40 import org.objectweb.jonas.common.Log;
41
42 import org.objectweb.util.monolog.api.BasicLevel;
43 import org.objectweb.util.monolog.api.Logger;
44
45 /**
46  * Modify a J2EEArchive
47  * @author Guillaume Sauthier
48  */

49 public abstract class ArchiveModifier {
50
51     /**
52      * J2EEArchive to be modified
53      */

54     private J2EEArchive archive;
55
56     /** logger */
57     private static Logger logger = Log.getLogger(Log.JONAS_GENBASE_PREFIX);
58
59     /**
60      * Creates a new ArchiveModifier object.
61      * @param archive rchive to be modified
62      */

63     public ArchiveModifier(J2EEArchive archive) {
64         this.archive = archive;
65     }
66
67     /**
68      * Modify the current archive and return a modified archive.
69      * @return a modified archive.
70      * @throws GenBaseException When Archive modification fails
71      */

72     public abstract Archive modify() throws GenBaseException;
73
74     /**
75      * Save the curernt archive usin given configuration and given out filename.
76      * @param config configuration to use
77      * @param outname filename
78      * @param archive archive to be saved
79      * @return the save Archive
80      * @throws GenBaseException is save fails.
81      */

82     protected static Archive save(Config config, String JavaDoc outname, J2EEArchive archive) throws GenBaseException {
83         ArchiveStorer storer = null;
84         File JavaDoc endfile = new File JavaDoc(config.getOut(), outname);
85         Archive out = null;
86
87         if (config.getSaveMode() == Config.PACKED) {
88             if (logger.isLoggable(BasicLevel.DEBUG)) {
89                 logger.log(BasicLevel.DEBUG, "Saving '" + endfile + "' in packed form...");
90             }
91             storer = new JarStorer(archive, endfile);
92             storer.store();
93             out = new JarArchive(endfile);
94         } else {
95             if (logger.isLoggable(BasicLevel.DEBUG)) {
96                 logger.log(BasicLevel.DEBUG, "Saving '" + endfile + "' in unpacked form...");
97             }
98             storer = new DirStorer(archive, endfile);
99             storer.store();
100             out = new FileArchive(endfile);
101         }
102
103         return out;
104
105     }
106
107     /**
108      * Save the current archive using given configuration and given out filename.
109      * @param config configuration to use
110      * @param outname filename
111      * @return the save Archive
112      * @throws GenBaseException is save fails.
113      */

114     protected Archive save(Config config, String JavaDoc outname) throws GenBaseException {
115         return save(config, outname, archive);
116     }
117
118     /**
119      * @return the logger.
120      */

121     public static Logger getLogger() {
122         return logger;
123     }
124 }
Popular Tags