1 28 29 30 package org.objectweb.ccm.runtime; 31 32 import org.objectweb.corba.runtime.*; 33 34 41 public class ExtComponentInstallationImpl 42 extends org.omg.CORBA.LocalObject 43 implements Servant, org.coach.ECM.ExtComponentInstallationOperations 44 { 45 static final private String _class_name = "ExtComponentInstallationImpl"; 47 48 static final private String _type_id = org.coach.ECM.ExtComponentInstallationHelper.id(); 50 51 private java.util.Hashtable _uuid2location; private String _zip_cache; 54 private int _archive_number; 55 private String _dtd_location; 56 57 private java.util.Hashtable _uuid2sarch; private java.util.Hashtable _uuid2carch; private POAService _poa_service; 61 private ORBService _orb_service; 62 63 protected 65 ExtComponentInstallationImpl() 66 { 67 _uuid2location = new java.util.Hashtable (); 69 _zip_cache = "."; 70 _archive_number = 0; 71 _dtd_location = "."; 72 73 _uuid2sarch = new java.util.Hashtable (); 75 _uuid2carch = new java.util.Hashtable (); 76 _poa_service = null; 77 _orb_service = null; 78 } 79 80 84 static public Servant 85 create_servant() 86 { 87 return new ExtComponentInstallationImpl(); 88 } 89 90 94 final public void 95 system_configuration_complete(SystemConfiguration cfg) 96 { 97 final String opname = "system_configuration_complete"; 98 String zc = System.getProperty("zip.cache"); 100 if (zc!=null) { 101 _zip_cache = zc; 102 } 103 104 String loc = System.getProperty("dtd.location"); 106 if (loc!=null) { 107 _dtd_location = loc; 108 } 109 110 ServantConfiguration scfg = (ServantConfiguration)cfg; 112 _poa_service = scfg.poa_service(); 113 _orb_service = scfg.orb_service(); 114 115 String auto = System.getProperty("archives.autoload"); 117 if (auto==null) { 118 return ; 119 } 120 121 java.util.Vector varchives = new java.util.Vector (); 123 int idx = auto.indexOf(','); 124 String pattern = ""; 125 while (idx!=-1) { 126 pattern = auto.substring(0, idx); 127 if (!pattern.equals("")) { 128 varchives.add(pattern); 129 } 130 131 auto = auto.substring(idx+1); 132 idx = auto.indexOf(','); 133 } 134 135 varchives.add(auto); 136 137 String [] archives = (String [])varchives.toArray(new String [0]); 139 for (int i=0;i<archives.length;i++) { 140 idx = archives[i].indexOf("="); 143 144 try { 145 String msg = "autoload: "+archives[i].substring(0, idx); 146 TheLogger.debug(_class_name, opname, msg); 147 msg = "location: "+archives[i].substring(idx+1); 148 TheLogger.debug(_class_name, opname, msg); 149 150 install(archives[i].substring(0, idx), archives[i].substring(idx+1)); 151 } catch(Exception ex) { 152 final String msg = "FAILED (UUID: "+archives[i].substring(0, idx)+")"; 153 TheLogger.error(_class_name, opname, msg, ex); 154 } 155 } 156 } 157 158 final public void 159 destroy() 160 { 161 } 163 164 168 final public String 169 type_id() 170 { 171 return _type_id; 172 } 173 174 final public org.omg.PortableServer.Servant 175 as_native_servant() 176 { 177 return new org.coach.ECM.ExtComponentInstallationPOATie(this); 178 } 179 180 184 final public org.coach.ECM.ServiceArchive 185 get_service_archive(String uuid) 186 { 187 final String opname = "get_service_archive"; 188 194 197 ServiceArchiveImpl sarch = (ServiceArchiveImpl)_uuid2sarch.get(uuid); 199 200 if (sarch==null) { 201 String archloc = (String )_uuid2location.get(uuid); 202 203 if (archloc==null) { 205 final String msg = "FAILED (unknown uuid: "+uuid+")"; 207 TheLogger.error(_class_name, opname, msg); 208 } 209 210 sarch = new ServiceArchiveImpl(_orb_service, _dtd_location, uuid, archloc); 211 sarch.system_configuration_complete(null); 212 213 _uuid2sarch.put(uuid, sarch); 215 216 _poa_service.activate_servant_with_id(sarch, uuid.getBytes()); 219 } 220 221 org.omg.CORBA.Object obj = _poa_service.create_ref_with_id(uuid.getBytes(), sarch.type_id()); 223 return org.coach.ECM.ServiceArchiveHelper.narrow(obj); 224 } 225 226 final public org.coach.ECM.ComponentArchive 227 get_component_archive(String uuid) 228 { 229 final String opname = "get_component_archive"; 230 236 239 ComponentArchiveImpl carch = (ComponentArchiveImpl)_uuid2carch.get(uuid); 241 242 if (carch==null) { 243 String archloc = (String )_uuid2location.get(uuid); 244 245 if (archloc==null) { 247 final String msg = "FAILED (unknown uuid: "+uuid+")"; 249 TheLogger.error(_class_name, opname, msg); 250 } 251 252 carch = new ComponentArchiveImpl(this, _orb_service, _dtd_location, uuid, archloc); 253 carch.system_configuration_complete(null); 254 255 _uuid2carch.put(uuid, carch); 257 258 _poa_service.activate_servant_with_id(carch, uuid.getBytes()); 261 } 262 263 org.omg.CORBA.Object obj = _poa_service.create_ref_with_id(uuid.getBytes(), carch.type_id()); 265 return org.coach.ECM.ComponentArchiveHelper.narrow(obj); 266 } 267 268 272 final public void 273 install(String uuid, String location) 274 throws org.omg.Components.Deployment.InvalidLocation, 275 org.omg.Components.Deployment.InstallationFailure 276 { 277 final String opname = "install"; 278 java.io.InputStream in = null; 280 try { 281 in = new java.io.FileInputStream (location); 282 } catch (java.io.FileNotFoundException ex) { 283 } 285 286 if (in==null) { 287 java.net.URL url = null; 289 try { 290 url = new java.net.URL (location); 291 in = url.openStream(); 292 } catch (Exception ex) { 293 } 295 } 296 297 if (in==null) { 298 final String msg = "FAILED (invalid format, rethrown)"; 299 TheLogger.debug(_class_name, opname, msg); 300 throw new org.omg.Components.Deployment.InvalidLocation(); 301 } 302 303 java.io.FileOutputStream out = null; 305 String fname = _zip_cache 306 + "/archive_" 307 + java.lang.Integer.toString(_archive_number) 308 + ".zip"; 309 310 try { 311 out = new java.io.FileOutputStream (fname); 312 } catch (java.io.FileNotFoundException ex) { 313 final String msg = "FAILED (file not found, rethrown)"; 314 TheLogger.debug(_class_name, opname, msg, ex); 315 throw new org.omg.Components.Deployment.InvalidLocation(); 316 } 317 318 int nread = 0; 319 byte[] buffer = new byte[2048]; 320 try { 321 while (nread!=-1) { 322 nread = in.read(buffer, 0, 2048); 323 if (nread!=-1) out.write(buffer, 0, nread); 324 } 325 326 in.close(); 327 out.close(); 328 } catch (java.io.IOException ex) { 329 final String msg = "FAILED (download aborted, rethrown)"; 330 TheLogger.debug(_class_name, opname, msg, ex); 331 throw new org.omg.Components.Deployment.InstallationFailure(); 332 } 333 334 _uuid2location.put(uuid, fname); 336 _archive_number++; 337 } 338 339 final public void 340 replace(String uuid, String location) 341 throws org.omg.Components.Deployment.InvalidLocation, 342 org.omg.Components.Deployment.InstallationFailure 343 { 344 final String opname = "replace"; 345 final String msg = "FAILED (not implemented, rethrown)"; 346 TheLogger.debug(_class_name, opname, msg); 347 348 throw new org.omg.CORBA.NO_IMPLEMENT (); 350 } 351 352 final public void 353 remove(String uuid) 354 throws org.omg.Components.Deployment.UnknownImplId, 355 org.omg.Components.RemoveFailure 356 { 357 final String opname = "remove"; 358 final String msg = "FAILED (not implemented, rethrown)"; 359 TheLogger.debug(_class_name, opname, msg); 360 361 throw new org.omg.CORBA.NO_IMPLEMENT (); 363 } 364 365 final public String 366 get_implementation(String uuid) 367 throws org.omg.Components.Deployment.UnknownImplId, 368 org.omg.Components.Deployment.InstallationFailure 369 { 370 final String opname = "get_implementation"; 371 final String msg = "FAILED (not implemented, rethrown)"; 372 TheLogger.debug(_class_name, opname, msg); 373 374 throw new org.omg.CORBA.NO_IMPLEMENT (); 376 } 377 } 378 | Popular Tags |