KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.objectweb.openccm.descriptor.softpkg.beans.SoftpkgBean;
30 import org.objectweb.openccm.descriptor.softpkg.beans.SoftpkgBeanImpl;
31
32 /**
33  * This is the action class for opening a CSD from an assembly
34  *
35  */

36 public class ComponentfileEditActionListener
37   implements org.objectweb.util.browser.api.MenuItem
38 {
39     /**
40      * Status of the menu item
41      *
42      * @param treeView to obtain the activated node
43      */

44     public int
45     getStatus(org.objectweb.util.browser.api.TreeView treeView)
46     {
47         return org.objectweb.util.browser.api.MenuItem.ENABLED_STATUS;
48     }
49
50     public void
51     actionPerformed (org.objectweb.util.browser.api.MenuItemTreeView the_event)
52     {
53         // retrieve the XML element from which comes the call
54
org.objectweb.openccm.descriptor.componentassembly.beans.ComponentfileBean csd_file
55          = (org.objectweb.openccm.descriptor.componentassembly.beans.ComponentfileBean)
56            the_event.getSelectedObject();
57
58         // gets the calling tree
59
org.objectweb.util.browser.core.common.DynamicTree calling_tree
60          = (org.objectweb.util.browser.core.common.DynamicTree)
61            the_event.getTree();
62
63         //gets the frame
64
org.objectweb.apollon.gui.ApollonFrame calling_frame
65          = (org.objectweb.apollon.gui.ApollonFrame)
66             calling_tree.getRootPane().getParent();
67
68         // The found path for this component (CSD or CAR)
69
String JavaDoc softpkg_path = null;
70
71         // Handling of eventual CSD file pointed by a <fileinarchive>
72
if (csd_file.getFileinarchive() != null)
73         {
74             // in case the CSD is in a CAR file we open the CAR
75
if (csd_file.getFileinarchive().getLink() != null)
76             {
77                 // checks if the given href is relative
78
if( csd_file.getFileinarchive().getLink()
79                     .getHref().indexOf(":")==-1)
80                 {
81                     softpkg_path
82                      = csd_file.getFileinarchive().getLink()
83                          .getHref();
84                 }
85                 else
86                 {
87                     System.err.println(
88                         "*** remote files access not implemented");
89                 }
90             }
91             else
92             {
93                 // the CSD file is directly in the AAR archive
94
softpkg_path
95                  = csd_file.getFileinarchive().getName();
96             }
97         }
98         
99         if (csd_file.getLink() != null )
100         {
101             // checks if the given href is relative
102
if( csd_file.getLink().getHref().indexOf(":")==-1)
103             {
104                 softpkg_path
105                  = csd_file.getLink().getHref();
106             }
107             else
108             {
109                 System.err.println(
110                     "*** remote files access not implemented");
111             }
112         }
113
114         java.io.File JavaDoc softpkg = new java.io.File JavaDoc(softpkg_path);
115         // file is new
116
if ( softpkg!=null && !softpkg.exists())
117         {
118             SoftpkgBean softpkg_instance
119              = new SoftpkgBeanImpl();
120
121             softpkg_instance.setDocType("softpkg","-//OMG//DTD CORBA Software Descriptor 3.0//EN","http://openccm.objectweb.org/dtd/ccm/softpkg.dtd");
122
123             try {
124                 softpkg_instance.marshalBean(
125                     new java.io.File JavaDoc(softpkg_path)
126                     );
127             } catch (Exception JavaDoc exception) {
128                 exception.printStackTrace();
129             }
130         }
131         else
132         {
133             // file exists
134
}
135
136         FileOperations.open_file(
137             new java.io.File JavaDoc(softpkg_path)
138             , calling_frame
139             );
140     }
141 }
142
Popular Tags