KickJava   Java API By Example, From Geeks To Geeks.

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


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: AbsApplicationModifier.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 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.jonas_lib.genbase.GenBaseException;
34 import org.objectweb.jonas_lib.genbase.archive.Application;
35 import org.objectweb.jonas_lib.genbase.archive.Archive;
36 import org.objectweb.jonas_lib.genbase.generator.Config;
37
38 import org.objectweb.util.monolog.api.BasicLevel;
39
40 /**
41  * Modify a given Application.
42  * @author Guillaume Sauthier
43  * @author Florent Benoit
44  */

45 public abstract class AbsApplicationModifier extends ArchiveModifier {
46
47     /**
48      * ejbjar modifiers
49      */

50     private List JavaDoc ejbModifiers = null;
51
52     /**
53      * web modifiers
54      */

55     private List JavaDoc webModifiers = null;
56
57     /**
58      * client modifiers
59      */

60     private List JavaDoc cltModifiers = null;
61
62     /**
63      * Wrapped application
64      */

65     private Application app = null;
66
67     /**
68      * Configuration used to save
69      */

70     private Config config = null;
71
72     /**
73      * Creates a new ApplicationModifier.
74      * @param archive the Application J2EE archive
75      * @param config the configuration object
76      */

77     public AbsApplicationModifier(Application archive, Config config) {
78         super(archive);
79         this.config = config;
80         app = archive;
81         initVectors();
82         init();
83     }
84
85     /**
86      * Init the vectors of modifiers
87      */

88     private void initVectors() {
89         // create lists
90
ejbModifiers = new Vector JavaDoc();
91         webModifiers = new Vector JavaDoc();
92         cltModifiers = new Vector JavaDoc();
93     }
94
95     /**
96      * initialize modifier
97      */

98     protected abstract void init();
99
100     /**
101      * Modify the current archive and return a modified archive.
102      * @return a modified archive.
103      * @throws GenBaseException When modifications fails
104      */

105     public Archive modify() throws GenBaseException {
106
107         getLogger().log(BasicLevel.INFO, "Processing Application " + app.getName());
108
109         /**
110          * Modify inner modules
111          */

112         for (Iterator JavaDoc i = webModifiers.iterator(); i.hasNext();) {
113             ArchiveModifier wm = (ArchiveModifier) i.next();
114             Archive a = wm.modify();
115             if (getLogger().isLoggable(BasicLevel.DEBUG)) {
116                 getLogger().log(BasicLevel.DEBUG, "Modifying WebApp '" + a.getName() + "'");
117             }
118             app.addFile(a.getRootFile());
119         }
120
121         for (Iterator JavaDoc i = cltModifiers.iterator(); i.hasNext();) {
122             ArchiveModifier cm = (ArchiveModifier) i.next();
123             Archive a = cm.modify();
124             if (getLogger().isLoggable(BasicLevel.DEBUG)) {
125                 getLogger().log(BasicLevel.DEBUG, "Modifying Client '" + a.getName() + "'");
126             }
127             app.addFile(a.getRootFile());
128         }
129
130         for (Iterator JavaDoc i = ejbModifiers.iterator(); i.hasNext();) {
131             ArchiveModifier em = (ArchiveModifier) i.next();
132             Archive a = em.modify();
133             if (getLogger().isLoggable(BasicLevel.DEBUG)) {
134                 getLogger().log(BasicLevel.DEBUG, "Modifying EjbJar '" + a.getName() + "'");
135             }
136             app.addFile(a.getRootFile());
137         }
138
139         return save(config, "apps" + File.separator + app.getName());
140
141     }
142
143     /**
144      * @return the cltModifiers.
145      */

146     protected List JavaDoc getCltModifiers() {
147         return cltModifiers;
148     }
149
150     /**
151      * @return the ejbModifiers.
152      */

153     protected List JavaDoc getEjbModifiers() {
154         return ejbModifiers;
155     }
156
157     /**
158      * @return the webModifiers.
159      */

160     protected List JavaDoc getWebModifiers() {
161         return webModifiers;
162     }
163     /**
164      * @return the application element.
165      */

166     protected Application getApplication() {
167         return app;
168     }
169 }
Popular Tags