KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > command > lib > IR3Destroy


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

26
27 package org.objectweb.openccm.command.lib;
28
29 // Package dependencies.
30
import org.objectweb.util.cmdline.lib.DefaultCommandLine;
31
32 /**
33  * Implementation of the ir3_destroy command.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  *
37  * @version 0.1
38  */

39
40 public class IR3Destroy
41      extends CommandOnIR3Base
42   implements org.objectweb.openccm.command.api.IR3Destroy
43 {
44     // ==================================================================
45
//
46
// Internal state.
47
//
48
// ==================================================================
49

50     // ==================================================================
51
//
52
// Constructor.
53
//
54
// ==================================================================
55

56     /** The default constructor. */
57     public
58     IR3Destroy()
59     {
60         // Calls the CommandOnIR3Base constructor with a command line.
61
super(new DefaultCommandLine("ir3_destroy",
62                                      "omg_idl_scoped_name",
63                                      "Destroy an object from the OpenCCM Interface Repository",
64                                      true));
65     }
66
67     // ==================================================================
68
//
69
// Internal methods.
70
//
71
// ==================================================================
72

73     // ==================================================================
74
//
75
// Public methods for org.objectweb.util.cmdline.api.Application
76
//
77
// ==================================================================
78

79     // ==================================================================
80
//
81
// Public methods for org.objectweb.openccm.command.api.Application
82
//
83
// ==================================================================
84

85     /**
86      * Runs the application.
87      *
88      * @param args The command line arguments.
89      *
90      * @return The status.
91      */

92     public int
93     run(java.lang.String JavaDoc[] args)
94     {
95         // Checks availability of the OpenCCM Interface Repository.
96
if(!checkComponentRepository())
97             return -1;
98
99         // Destroys the scoped name from the OpenCCM Interface Repository.
100
if(!destroy(args[0]))
101             return -1;
102
103         // All is OK.
104
return 0;
105     }
106
107     // ==================================================================
108
//
109
// Public methods for org.objectweb.openccm.command.api.CommandOnIR3
110
//
111
// ==================================================================
112

113     // ==================================================================
114
//
115
// Public methods for org.objectweb.openccm.command.api.IR3Destroy
116
//
117
// ==================================================================
118

119     /**
120      * Destroys a scoped name from the OpenCCM Interface Repository.
121      *
122      * @param scoped_name The scoped name to destroy.
123      *
124      * @return True if ok, else false.
125      */

126     public boolean
127     destroy(String JavaDoc scoped_name)
128     {
129         // Lookups the scoped name from the OpenCCM Interface Repository.
130
org.omg.CORBA.Contained JavaDoc contained = getComponentRepository().lookup(scoped_name);
131         if(contained == null)
132         {
133             getConsole().error(scoped_name + " not found in the OpenCCM Interface Repository!");
134             return false;
135         }
136  
137         // Destroys the scoped name from the OpenCCM Interface Repository.
138
try
139         {
140             contained.destroy();
141         }
142         catch(org.omg.CORBA.BAD_INV_ORDER JavaDoc sysExc)
143         {
144             switch(sysExc.minor)
145             {
146             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.Dependency:
147                 getConsole().error(scoped_name +
148                     " not destroyed because dependency exits in the OpenCCM Interface Repository preventing destruction!");
149                 return false;
150
151             case org.objectweb.openccm.ir3.SystemExceptionMinorValues.CanNotBeDestroyed:
152                 getConsole().error(scoped_name +
153                                    " not destroyed because indestructible object!");
154                 return false;
155             }
156         }
157
158         // All is OK.
159
getConsole().message(scoped_name + " destroyed successfully.");
160         return true;
161     }
162
163     // ==================================================================
164
//
165
// Static public methods.
166
//
167
// ==================================================================
168

169     /**
170      * The main bootstrap method.
171      *
172      * @param args The command line arguments.
173      */

174     public static void
175     main(String JavaDoc[] args)
176     {
177         IR3Destroy ir3destroy = new IR3Destroy();
178         ir3destroy.runMain(args);
179     }
180 }
181
Popular Tags