KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > Deployment > AssemblyImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2002 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): Briclet Frederic
23 Contributor(s): ___________________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.Deployment;
28
29
30 import java.io.IOException;
31 import java.net.URL;
32
33 import org.objectweb.ccm.descriptor.componentassembly.beans.*;
34 //import org.objectweb.ccm.descriptor.componentassembly.ccm.*;
35
import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.root.*;
36 import org.objectweb.ccm.descriptor.*;
37 import org.omg.Components.Deployment.Assembly;
38 import org.omg.CosNaming.NamingContextExtHelper;
39
40 //import hfinder package for setting the deployTable
41

42 //import org.objectweb.openccm.Deployment.components.HFinder.*;
43
/**
44  * AssemblyImpl is the top level implementation of the
45  * assembly behaviour.
46  *
47  * @author <a HREF="mailto:frederic.briclet@lifl.fr">Briclet Frederic</a>
48  *
49  * @version 0.1
50  */

51 public class AssemblyImpl extends org.omg.Components.Deployment.AssemblyPOA
52                           implements AssemblyConfigurator{
53
54
55         
56     // ==================================================================
57
//
58
// Internal state.
59
//
60
// ==================================================================
61

62
63     // xml handler path
64
private URL xmlFilePath;
65
66     // Console for emittion of message
67
private org.objectweb.util.cmdline.api.Console console;
68
69     private java.util.zip.ZipFile zipFile;
70     
71     private java.io.File tmpZipFile;
72
73     // State of the assembly
74
//private org.omg.Components.Deployment.AssemblyOperations etat;
75
AssemblyBase etat ;
76     // ==================================================================
77
//
78
// Constructor
79
//
80
// ==================================================================
81

82     public
83     AssemblyImpl(URL xmlFilePath)
84     {
85         this.xmlFilePath=xmlFilePath;
86         etat=new AssemblyBase(this);
87     }
88
89     
90     public ComponentassemblyDeployerHandler
91     configure(ComponentassemblyDeployerHandler context)
92     {
93        try{
94          
95             /*Store reference on the name service*/
96             context.connectNamingcontext(NamingContextExtHelper.narrow(
97                                         org.objectweb.openccm.corba.TheNameService
98                                         .getNamingContext()
99                                         .getNamingContext()));
100
101             try{
102                   org.objectweb.openccm.OpenCCM_DCI.DCIManager
103                     DCI=
104                     org.objectweb.openccm.
105                     OpenCCM_DCI.DCIManagerHelper.
106                     narrow(org.objectweb.openccm.corba
107                            .TheORB.resolve_initial_reference("DCIManager"));
108                   
109                   context.connectHomefinder(DCI.provide_home_finder());
110                   context.connectHomeregistration(DCI.provide_home_registration());
111                   context.connectDciinfo(DCI.provide_dci_information());
112                   zipFile=new java.util.zip.ZipFile(xmlFilePath.getPath());
113                   context.connectZipEntryRetriever(new ZipEntryRetriever(zipFile));
114                   
115             }
116             catch(Exception e){
117                 e.printStackTrace();
118                 System.err.println
119                     ("CCM_deploy >> DCIManager not start, HomeFinder functionnalities disable !");
120                 System.err.println
121                     ("CCM_deploy >> To start DCIManager execute dci_start <dci_name> command");
122             }
123         }
124         catch(Exception e){
125             System.err.println("Problem occured during setting of the deployTable");
126         }
127         return context;
128     }
129  
130       public Assembly getAssembly(){
131           org.omg.CORBA.Object ref =
132                      this._this_object(org.objectweb.openccm.corba.TheORB.getORB());
133         
134           return org.omg.Components.Deployment.AssemblyHelper.narrow(ref);
135       }
136     
137       public void removeAssembly(){
138              
139       }
140     
141       public ComponentassemblyBean getComponentassemblyTree()
142       {
143           try{
144           // get the ORB
145
org.omg.CORBA.ORB orb
146              = org.objectweb.openccm.corba.TheORB.getORB();
147          //console.message("Got the ORB");
148

149          // inits OpenCCM runtime
150
org.objectweb.openccm.Components.Runtime.init (orb);
151          //console.message("OpenCCM runtime is ready");
152

153          java.io.InputStreamReader reader ;
154          
155          java.net.URL url=xmlFilePath; //new URL(xmlFilePath);
156
tmpZipFile =java.io.File.createTempFile(System.currentTimeMillis()+"","aar");
157           java.io.FileOutputStream fos= new java.io.FileOutputStream(tmpZipFile);
158
159     
160            java.io.InputStream bis=url.openStream();
161    
162            byte [] byteArray= new byte[32000];
163            int readed=bis.read(byteArray,0,32000);
164     
165            System.err.print("Downloading "+xmlFilePath+" [");
166            while(readed>0)
167                {
168                    fos.write(byteArray,0,readed);
169                    readed=bis.read(byteArray,0,32000);
170                    System.err.print("*");
171                }
172            System.err.println("]");
173            fos.flush();
174            fos.close();
175     
176            zipFile=
177                new java.util.zip.ZipFile(tmpZipFile);
178                                    
179        
180         
181          for(java.util.Enumeration enum=zipFile.entries();enum.hasMoreElements();)
182              {
183         
184                  java.util.zip.ZipEntry ze=(java.util.zip.ZipEntry)enum.nextElement();
185                  //System.out.println("Filename:"+ze.getName());
186
if(ze.getName().endsWith(".cad"))
187                      {
188                          reader=new java.io.InputStreamReader
189                              (zipFile.getInputStream(ze));
190                         
191                         return org.objectweb.ccm.descriptor
192                              .componentassembly.beans.ComponentassemblyBeanImpl
193                              .unmarshalBean(reader,true);
194                      }
195              }
196         }
197         catch(Exception e){
198                 e.printStackTrace();
199         }
200         return null;
201       }
202     
203    public void
204    deleteTemporaryFile()
205    {
206            try{
207                zipFile.close();
208               tmpZipFile.delete();
209            }
210            catch(Exception e)
211            {//Not a problem the temporaryfile will be removed by the OS
212
}
213
214    }
215       
216       
217       
218     /*Delegation operation to the state assembly*/
219     public void
220     build()
221     throws org.omg.Components.CreateFailure
222     {
223         etat.build();
224     }
225
226
227     public void
228     tear_down()
229     throws org.omg.Components.RemoveFailure
230     {
231         etat.tear_down();
232     }
233     
234
235
236     public org.omg.Components.Deployment.AssemblyState
237     get_state()
238     {
239         return etat.get_state();
240     }
241
242     public void registerAssembly(){
243         etat.registerAssembly();
244     }
245     
246     public void
247     unregisterAssembly()
248     {
249         try{
250             
251             etat.unregisterAssembly();
252         }
253         catch(Exception e){}
254
255     }
256 }
257
Popular Tags