KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > packaging > ComponentPackager


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Contreras
23 Contributor(s): ___________________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.packaging;
28
29 // Package dependencies
30
import org.objectweb.util.browser.api.MenuItem;
31 import org.objectweb.util.browser.api.MenuItemTreeView;
32 import org.objectweb.openccm.descriptor.softpkg.gui.SoftpkgZipper;
33
34 /**
35  * This is the action class for building an archive for a package
36  *
37  */

38 public class ComponentPackager
39   implements MenuItem
40 {
41     // ==================================================================
42
//
43
// Internal state.
44
//
45
// ==================================================================
46

47     // ==================================================================
48
//
49
// Constructors.
50
//
51
// ==================================================================
52

53     // ==================================================================
54
//
55
// Private methods.
56
//
57
// ==================================================================
58

59
60     // ==================================================================
61
//
62
// public methods.
63
//
64
// ==================================================================
65

66     /**
67      * Status of the menu item
68      *
69      * @param treeView to obtain the activated node
70      */

71     public int
72     getStatus(org.objectweb.util.browser.api.TreeView treeView)
73     {
74         return org.objectweb.util.browser.api.MenuItem.ENABLED_STATUS;
75     }
76
77     /**
78      * The action method taking an event as parameter
79      */

80     public void actionPerformed(MenuItemTreeView e)
81     throws Exception JavaDoc
82     {
83         String JavaDoc action = e.getActionEvent().getActionCommand();
84
85         // gets the calling instance
86
org.objectweb.apollon.framework.Bean zeus_instance
87             = (org.objectweb.apollon.framework.Bean)
88                 e.getSelectedObject();
89
90         // gets the calling entry
91
org.objectweb.util.browser.api.Entry entry
92          = e.getSelectedEntry();
93
94         // gets the file name for the component descriptor
95
// it is registered as an absolute path in the GUI for this entry
96
String JavaDoc descriptor_filename
97          = CCMSplitPane.get_file_by_id(
98             (String JavaDoc) entry.getName()
99             );
100
101         // calls the ZIP maker method
102
make_zip (zeus_instance, descriptor_filename);
103     }
104     
105     /**
106      * A method to build ZIP archives
107      * called from menu action, or from the static call
108      *
109      * @param zeus_instance the META used as CSD descriptor
110      * @param descriptor_filename the name of the CSD file
111      */

112     public void
113     make_zip (
114         org.objectweb.apollon.framework.Bean zeus_instance,
115         String JavaDoc descriptor_filename
116         )
117     throws Exception JavaDoc
118     {
119         if (zeus_instance.idBean().equals("[Softpkg]"))
120         {
121             throw new Exception JavaDoc(
122                 "Undefined Soft Package NAME for "
123                 +descriptor_filename);
124         }
125         else
126         {
127             java.io.File JavaDoc zipfile
128              = new java.io.File JavaDoc(
129                 zeus_instance.idBean()
130                 +".car"
131                 );
132
133             System.err.println("Starting Component ARchive creation...");
134
135             // creates a new zip factory for this package
136
ZipFactory zip_factory
137             = new ZipFactory();
138
139             zip_factory.setZipName(zipfile.getAbsolutePath());
140
141             // gets the descriptor file for the described Component
142
java.io.File JavaDoc original_descriptor_file
143              = new java.io.File JavaDoc(
144                 descriptor_filename
145                 );
146             // creating the file to be zipped
147
java.io.File JavaDoc temp_descriptor_file
148              = new java.io.File JavaDoc(
149                 "META-INF"
150                 +System.getProperty("file.separator")
151                 +original_descriptor_file.getName()
152                 );
153
154             try
155             {
156                 // marshaling the temporary descriptor
157
zeus_instance.marshalBean(temp_descriptor_file);
158             } catch (Exception JavaDoc except) {
159                 except.printStackTrace();
160             }
161
162             // adds the descriptor to the zip archive
163
zip_factory
164                 .addFileToZip(
165                     temp_descriptor_file.getPath()
166                     );
167
168             // launches the ZIP extensions in the SOFTPKG framework
169
SoftpkgZipper zipper
170             = (SoftpkgZipper) zeus_instance
171                 .getExtensionManager()
172                 .getExtensionByName("gui.Zipper")
173                 .getInstance();
174             zipper.zipCall(
175                 (org.objectweb.openccm.descriptor
176                 .softpkg.beans.SoftpkgBean)
177                     zeus_instance
178                 , zip_factory);
179
180             // builds the archive after file retrieving
181
try
182             {
183                 zip_factory.buildZip();
184                 System.err.println("End of the CAR creation, writing file:");
185                 System.err.println(zipfile.getAbsolutePath());
186             } catch (Exception JavaDoc exc) {
187                 System.err.println("Package could not be built. See following stacktrace");
188                 exc.printStackTrace();
189             }
190         }
191     }
192 }
193
Popular Tags