1 26 27 28 29 package org.objectweb.openccm.OpenCCM_DCI.cif; 30 31 import java.net.URL ; 33 34 import org.objectweb.openccm.OpenCCM_DCI.*; 35 import org.objectweb.openccm.Deployment.AssemblyBase; 36 import org.objectweb.openccm.Deployment.AssemblyConfigurator; 37 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.root.*; 38 import org.objectweb.openccm.descriptor.componentassembly.beans.*; 39 import org.objectweb.openccm.descriptor.*; 40 import org.omg.Components.Deployment.Assembly; 41 42 53 public class AssemblySegImpl 54 extends org.objectweb.openccm.OpenCCM_DCI. 55 AssemblyManagerSessionComposition.AssemblySeg 56 implements AssemblyConfigurator 57 { 58 59 private String xmlFilePath; 66 67 private org.objectweb.util.cmdline.api.Console console; 69 private AssemblyBase etat; 71 72 private AssemblyManager am; 74 75 private java.util.zip.ZipFile zipFile; 76 private java.io.File tmpZipFile; 77 private java.io.InputStreamReader reader; 78 private ComponentassemblyBean assemblyObject; 80 public ComponentassemblyDeployerHandler 91 configure(ComponentassemblyDeployerHandler context){ 92 context.connectHomefinder( get_context().get_connection_home_finder()) ; 93 context.connectHomeregistration(get_context().get_connection_home_registration()); 94 context.connectNamingcontext(get_context().get_connection_naming_service()); 95 context.connectDciinfo(get_context().get_connection_dci_information()); 96 context.connectAssemblyManager(am); 97 context.connectZipEntryRetriever(new ZipEntryRetriever(zipFile)); 98 return context; 99 } 100 101 public Assembly getAssembly(){ 102 return 103 ((org.objectweb.openccm 104 .OpenCCM_DCI.AssemblyManagerCCM)get_context()) 105 .provide_assembly(); 106 } 107 108 public void removeAssembly(){ 109 110 } 111 112 public void 113 deleteTemporaryFile() 114 { 115 116 try{ 117 reader.close(); 118 zipFile.close(); 119 }catch(Exception e) 120 { 121 } 124 125 if(!tmpZipFile.delete()) 126 tmpZipFile.deleteOnExit(); 127 128 } 129 130 public ComponentassemblyBean getComponentassemblyTree() 131 { 132 try{ 133 org.omg.CORBA.ORB orb 135 = org.objectweb.openccm.corba.TheORB.getORB(); 136 138 org.objectweb.openccm.Components.Runtime.init (orb); 140 142 java.io.InputStreamReader reader ; 143 144 java.net.URL url= new URL (xmlFilePath); 145 tmpZipFile =java.io.File.createTempFile(System.currentTimeMillis()+"","aar"); 146 java.io.FileOutputStream fos= new java.io.FileOutputStream (tmpZipFile); 147 148 149 java.io.InputStream bis=url.openStream(); 150 151 byte [] byteArray= new byte[32000]; 152 int readed=readed=bis.read(byteArray,0,32000); 153 154 System.err.print("Downloading "+xmlFilePath+" ["); 155 while(readed>0) 156 { 157 fos.write(byteArray,0,readed); 158 readed=bis.read(byteArray,0,32000); 159 System.err.print("*"); 160 } 161 System.err.println("]"); 162 fos.flush(); 163 fos.close(); 164 165 zipFile= 166 new java.util.zip.ZipFile (tmpZipFile); 167 168 169 170 for(java.util.Enumeration entries=zipFile.entries();entries.hasMoreElements();) 171 { 172 173 java.util.zip.ZipEntry ze=(java.util.zip.ZipEntry )entries.nextElement(); 174 if(ze.getName().endsWith(".cad")) 176 { 177 System.err.println("AssemblyManager>>File ["+ze.getName()+"] is used for deployment"); 178 reader=new java.io.InputStreamReader 179 (zipFile.getInputStream(ze)); 180 181 assemblyObject= org.objectweb.openccm.descriptor 182 .componentassembly.beans.ComponentassemblyBeanImpl 183 .unmarshalBean(reader,true); 184 return assemblyObject; 185 } 186 } 187 } 188 catch(Exception e){ 189 e.printStackTrace(); 190 } 191 return assemblyObject; 192 } 193 194 200 201 204 public void 205 setupXMLFilePath(String xmlFilePath) 206 { 207 this.xmlFilePath=xmlFilePath; 208 etat=new AssemblyBase(this); 209 } 210 211 public void 212 setupAssemblyManager(org.objectweb.openccm.OpenCCM_DCI.AssemblyManager am) 213 { 214 this.am=am; 215 } 216 217 public void registerAssembly(){ 218 etat.registerAssembly(); 219 } 220 221 public void unregisterAssembly(){ 222 try{ 223 zipFile.close(); 224 tmpZipFile.delete(); 225 } 226 catch(Exception e) 227 { 228 e.printStackTrace(); 229 } 231 232 etat.unregisterAssembly(); 233 } 234 235 241 242 public void 243 build() 244 throws org.omg.Components.CreateFailure 245 { 246 etat.build(); 247 } 248 249 public void 250 tear_down() 251 throws org.omg.Components.RemoveFailure 252 { 253 etat.tear_down(); 254 } 255 256 257 public org.omg.Components.Deployment.AssemblyState 258 get_state() 259 { 260 return etat.get_state(); 261 } 262 263 public String 264 getName() 265 { 266 try{ 267 return assemblyObject.getId(); 268 } 269 catch(Exception e){ 270 e.printStackTrace(); 271 return "AssemblyManager"; 272 } 273 } 274 275 } 276 | Popular Tags |