KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > deploytool > TearDownTool


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 Initial developer(s): Briclet Frederic
22 Contributor(s): ___________________________________________________.
23
24 ====================================================================*/

25
26 package org.objectweb.ccm.deploytool;
27 /**
28  * TearDownTool allow to tear down an assembly from a console or
29  * from java code.
30  *
31  * @author <a HREF="mailto:frederic.briclet@lifl.fr">Briclet Frederic</a>
32  *
33  * @version 0.1
34  */

35 public class TearDownTool {
36     // ==================================================================
37
//
38
// Internal state.
39
//
40
// ==================================================================
41
/*AssemblyName to tear_down */
42     private String JavaDoc assemblyName=null;
43     /*Ior file to use to stop a component*/
44     private String JavaDoc iorFile=null;
45     /*The file URL*/
46     private String JavaDoc fileURL=null;
47     // ==================================================================
48
//
49
// Internal methods.
50
//
51
// ==================================================================
52
private void
53     computeArgs(String JavaDoc args[])
54     {
55         for(int i=0;i<args.length;i++){
56             if(args[i].startsWith("-N-F"))
57                this.iorFile=args[i].substring(4);
58             else if(args[i].startsWith("-N-U")){
59                 this.fileURL=args[i].substring(4);
60             }
61             else if(args[i].startsWith("-N"))
62                 this.assemblyName=System.getProperty("Assemblies_ns_dir")+
63                                   args[i].substring(2);
64                }
65     }
66     
67     // ==================================================================
68
//
69
// Constructor.
70
//
71
// ==================================================================
72

73     /**
74      * Default constructor
75      * @param assemblyToTearDown the assembly name
76      */

77     public TearDownTool(String JavaDoc args[]){
78         try{
79             computeArgs(args);
80             tearDown();
81         }
82         catch(Exception JavaDoc e)
83             {
84                 /*System.err.println(e.getMessage());*/
85                 if(iorFile!=null||fileURL!=null){
86                 /* System.err.println("Cannot stop the component denote by the following path"+
87                                     iorFile);*/

88                 }
89                 else{
90                     System.err.println("Cannot tear_down the assembly "+assemblyName);
91                 }
92             }
93         
94         
95     }
96
97     // ==================================================================
98
//
99
// Public methods.
100
//
101
// ==================================================================
102
/**
103      * Method allowing to tear down an assembly
104      * @param assemblyToTearDown the assembly name
105      */

106     public void
107     tearDown()
108     throws Exception JavaDoc
109     {
110         
111         if(assemblyName!=null)//Stopping assembly case
112
{
113                 org.omg.CosNaming.NamingContextExt JavaDoc context=
114                     org.omg.CosNaming.NamingContextExtHelper
115                     .narrow(org.objectweb.openccm.corba.TheNameService
116                             .getNamingContext()
117                             .getNamingContext());
118                 
119                 org.omg.Components.Deployment.Assembly assemblyObject=
120                     org.omg.Components
121                     .Deployment.AssemblyHelper
122                     .narrow(context.resolve(context.to_name(assemblyName)));
123                 
124                 //TearDown the assembly
125
assemblyObject.tear_down();
126             }
127         else {//Stopping a classical component case
128
java.io.InputStream JavaDoc in ;
129             if(fileURL!=null)
130                 {
131                 //Create an url with the ior file
132
java.net.URL JavaDoc URL=new java.net.URL JavaDoc(fileURL);
133                 //create a stream
134
in=URL.openStream();
135                 }
136             else
137                 {
138                    in=new java.io.FileInputStream JavaDoc(iorFile);
139                 }
140             
141             byte [] tab=new byte[in.available()];
142             //read all the stream
143
in.read(tab);
144             //convert to string
145
String JavaDoc ior=new String JavaDoc(tab);
146             //retrieve the corba reference
147
org.omg.CORBA.Object JavaDoc obj=
148                 org.objectweb.openccm.corba.TheORBSingleton.getORB().
149                 string_to_object(ior.trim());
150             //retrieve a component
151
org.omg.Components.CCMObjectHelper.narrow(obj).remove();
152         }
153                 
154     }
155
156     public static void main(String JavaDoc args[]){
157         //Initialize the ORB
158
org.objectweb.openccm.corba.TheORB.initialize(args);
159         //create a new TearDownTool to realise the tear_down process
160
new TearDownTool(args);
161         
162         org.objectweb.openccm.corba.TheORB.destroy();
163     }
164     
165 }
166
Popular Tags