KickJava   Java API By Example, From Geeks To Geeks.

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


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.componentassembly.gui.ComponentassemblyZipper;
33
34 /**
35  * This is the action class for building an archive for an assembly
36  *
37  */

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

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