KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > Deployment > CreateAssembly


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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.explorer.Deployment;
27
28 import java.net.URL JavaDoc;
29
30 import org.objectweb.openccm.explorer.menu.JFileChooserSingleton;
31 import org.objectweb.openccm.explorer.menu.OpenCCMBrowserConstants;
32 import org.objectweb.util.explorer.api.MenuItem;
33 import org.objectweb.util.explorer.api.MenuItemTreeView;
34 import org.objectweb.util.explorer.api.TreeView;
35 import org.objectweb.util.explorer.swing.gui.api.DialogAction;
36 import org.objectweb.util.explorer.swing.gui.api.DialogBox;
37 import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
38 import org.objectweb.util.explorer.swing.gui.lib.FileChooserBox;
39 import org.omg.Components.Deployment.AssemblyFactory;
40
41 /**
42  * The <b>create</b> operation creates an Assembly object on the host
43  * on which the AssemblyFactory is located. It takes a string denoting
44  * the location of an assembly. The URL can be found on the local file
45  * system or can be defined as a distant URL.
46  * (section 6.9.3 of the CORBA Components Model specification)
47  *
48  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
49  *
50  * @version 0.1
51  */

52 public class CreateAssembly
53   implements MenuItem, DialogAction {
54
55     //==================================================================
56
//
57
// Internal states.
58
//
59
//==================================================================
60

61     /** The fileChooserBox containing the URL of the archive. */
62     protected FileChooserBox archive_ = null;
63
64     /** The AssemblyFactory on which creates the Assembly. */
65     protected AssemblyFactory assemblyFactory_ = null;
66
67     //==================================================================
68
//
69
// No constructor.
70
//
71
//==================================================================
72

73     //==================================================================
74
//
75
// Internal methods.
76
//
77
//==================================================================
78

79     protected AssemblyFactory getAssemblyFactory(TreeView treeView){
80         return (AssemblyFactory)treeView.getSelectedObject();
81     }
82     
83     //==================================================================
84
//
85
// Public methods for MenuItem interface.
86
//
87
//==================================================================
88

89     public int getStatus(TreeView arg0){
90         return MenuItem.ENABLED_STATUS;
91     }
92
93     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc {
94         assemblyFactory_ = getAssemblyFactory(e);
95         
96         DialogBox dialog = new DefaultDialogBox("Create an assembly");
97         archive_ = new FileChooserBox("Archive",JFileChooserSingleton.getInstance(OpenCCMBrowserConstants.ASSEMBLY_ARCHIVE_FILE_CHOOSER),true,true);
98         dialog.addElementBox(archive_);
99         dialog.setValidateAction(this);
100         dialog.show();
101     }
102     
103     //==================================================================
104
//
105
// Public methods for DialogAction interface.
106
//
107
//==================================================================
108

109     /**
110      * Creates the Assembly corresponding to the param archive.
111      */

112     public void executeAction() throws Exception JavaDoc {
113         URL JavaDoc theURL = null;
114         if(archive_.getFile()!=null){
115             // The local file
116
// Start the HTTP Server
117
java.net.ServerSocket JavaDoc s = new java.net.ServerSocket JavaDoc(0);
118             (new Thread JavaDoc(new MicroServerHttp(s))).start();
119             theURL= new URL JavaDoc("http://" + java.net.InetAddress.getLocalHost().getHostAddress() + ':' + s.getLocalPort() + '/' + archive_.getFile().getAbsolutePath());
120         } else {
121             if(archive_.getURL()!=null){
122                 // A valid URL has been filled
123
theURL = archive_.getURL();
124             }
125         }
126         if(theURL!=null){
127             assemblyFactory_.create_assembly(theURL.toString());
128         }
129     }
130 }
Popular Tags