1 26 27 package org.objectweb.openccm.Deployment; 28 29 40 41 public class ComponentInstallationImpl 42 extends org.omg.Components.Deployment.ComponentInstallationPOA 43 { 44 50 53 protected org.objectweb.ccm.util.Table implementations_; 54 55 58 protected java.io.File path_; 59 60 66 72 public 73 ComponentInstallationImpl(String path) 74 { 75 implementations_ = new org.objectweb.ccm.util.Table(); 76 path_ = new java.io.File (path); 77 if(!path_.exists()) 80 path_.mkdirs(); 81 } 82 83 89 95 101 115 public void 116 install(String implUUID, 117 String component_loc) 118 throws org.omg.Components.Deployment.InvalidLocation, 119 org.omg.Components.Deployment.InstallationFailure 120 { 121 123 if(implementations_.contains(implUUID)) 125 return ; 126 127 java.io.InputStream bis = null; 128 java.io.OutputStream bos = null; 129 java.net.URL url = null; 130 String filename; 131 134 try{ 135 filename=(new java.net.URL (component_loc)).getFile(); 136 filename=filename.substring(filename.lastIndexOf("/")); 137 } 138 catch(Exception e0){ 139 throw new org.omg.Components.Deployment.InstallationFailure(); 141 } 142 java.io.File output = new java.io.File (path_, filename); 143 try 144 { 145 path_.mkdirs(); 146 bos = new java.io.FileOutputStream (output); 147 } 148 catch (java.io.FileNotFoundException e) 149 { 150 throw new org.omg.Components.Deployment.InvalidLocation(); 151 } 152 catch (java.io.IOException e1) 153 { 154 throw new org.omg.Components.Deployment.InstallationFailure(); 158 } 159 160 try 161 { 162 url = new java.net.URL (component_loc); 163 bis = (java.io.InputStream ) url.openStream(); 164 } 165 catch (java.net.MalformedURLException e) 166 { 167 throw new org.omg.Components.Deployment.InvalidLocation (); 168 } 169 catch (java.io.FileNotFoundException e) 170 { 171 throw new org.omg.Components.Deployment.InvalidLocation(); 172 } 173 catch (java.io.IOException e) 174 { 175 throw new org.omg.Components.Deployment.InstallationFailure(); 179 } 180 181 try 183 { 184 int length; 185 byte b[] = new byte[2048]; 186 while (true) 187 { 188 length = bis.read(b, 0, 2048); 189 if (length == -1) 190 break; 191 bos.write(b, 0, length); 192 } 193 bis.close(); 194 bos.close(); 195 } 196 catch (java.io.IOException e) 197 { 198 throw new org.omg.Components.Deployment.InstallationFailure(); 202 } 203 204 try{ 206 implementations_.put(implUUID, output.toURL().toString()); 207 } 208 catch(Exception ei) 209 { 210 System.err.println("Problem occurs during the adding of the URL"); 211 throw new org.omg.Components.Deployment.InstallationFailure(); 212 } 213 223 } 224 225 239 public void 240 replace(String implUUID, 241 String component_loc) 242 throws org.omg.Components.Deployment.InvalidLocation, 243 org.omg.Components.Deployment.InstallationFailure 244 { 245 install(implUUID, component_loc); 246 } 247 248 261 public void 262 remove(String implUUID) 263 throws org.omg.Components.Deployment.UnknownImplId, 264 org.omg.Components.RemoveFailure 265 { 266 Object o = implementations_.remove(implUUID); 268 269 if(o == null) 271 { 272 throw new org.omg.Components.Deployment.UnknownImplId(); 273 } 274 275 } 277 278 291 public String 292 get_implementation(String implUUID) 293 throws org.omg.Components.Deployment.UnknownImplId, 294 org.omg.Components.Deployment.InstallationFailure 295 { 296 String impl = (String )implementations_.get(implUUID); 298 299 if(impl == null) 301 { 302 throw new org.omg.Components.Deployment.UnknownImplId(); 303 } 304 305 return impl; 307 } 308 } 309 310 311 312 | Popular Tags |