1 19 package org.netbeans.modules.j2ee.websphere6; 20 21 import java.io.*; 22 import java.util.*; 23 import java.lang.reflect.*; 24 import java.util.jar.JarEntry ; 25 import java.util.jar.JarFile ; 26 import java.util.jar.JarInputStream ; 27 28 import javax.enterprise.deploy.model.*; 29 import javax.enterprise.deploy.model.exceptions.*; 30 import javax.enterprise.deploy.shared.*; 31 32 import org.openide.*; 33 import org.netbeans.modules.j2ee.deployment.devmodules.spi.*; 34 35 import org.netbeans.modules.j2ee.websphere6.util.WSDebug; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.FileUtil; 38 39 49 public class WSDeployableObject implements DeployableObject { 50 51 56 DeployableObject deployableObject; 57 58 62 J2eeModuleProvider provider; 63 64 67 Map ddBeanRoots = new HashMap(); 68 69 75 public WSDeployableObject(DeployableObject deployableObject) { 76 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "WSDeployableObject(" + deployableObject + ")"); 80 this.deployableObject = deployableObject; 82 83 try { 85 Method method = deployableObject.getClass(). 86 getMethod("getProvider", new Class [0]); this.provider = (J2eeModuleProvider) method. 88 invoke(deployableObject, new Object [0]); 89 } catch (IllegalAccessException e) { 90 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 91 } catch (NoSuchMethodException e) { 92 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 93 } catch (InvocationTargetException e) { 94 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 95 } 96 } 97 98 105 public DDBeanRoot findDDBeanRoot(DDBeanRoot bean) { 106 Collection values = ddBeanRoots.values(); 108 109 for (Iterator iterator = values.iterator(); iterator.hasNext();) { 112 WSDDBeanRoot wsBean = (WSDDBeanRoot) iterator.next(); 113 114 if (wsBean.getOrigin().equals(bean)) { 116 return wsBean; 117 } 118 } 119 120 return null; 122 } 123 124 128 public DDBeanRoot getDDBeanRoot(String str) throws FileNotFoundException, 129 DDBeanCreateException { 130 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getDDBeanRoot(" + str + ")"); 133 if (ddBeanRoots.get(str) == null) { 136 ddBeanRoots.put(str, new WSDDBeanRoot(deployableObject. 137 getDDBeanRoot(str), this)); 138 } 139 140 return (DDBeanRoot) ddBeanRoots.get(str); 142 } 143 144 148 public DDBeanRoot getDDBeanRoot() { 149 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getDDBeanRoot()"); 152 if (ddBeanRoots.get("") == null) { ddBeanRoots.put("", new WSDDBeanRoot(deployableObject. getDDBeanRoot(), this)); 158 } 159 160 return (DDBeanRoot) ddBeanRoots.get(""); } 163 164 168 public String [] getText(String str) { 169 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getText(" + str + ")"); 172 return deployableObject.getText(str); 173 } 174 175 179 public Class getClassFromScope(String str) { 180 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getClassFromScope(" + str + ")"); 184 return deployableObject.getClassFromScope(str); 185 } 186 187 191 public DDBean[] getChildBean(String str) { 192 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getChildBean(" + str + ")"); 195 return deployableObject.getChildBean(str); 196 } 197 198 202 public ModuleType getType() { 203 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getType()"); 206 return deployableObject.getType(); 207 } 208 209 213 public String getModuleDTDVersion() { 214 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getModuleDTDVersion()"); 217 return deployableObject.getDDBeanRoot().getDDBeanRootVersion(); 218 } 219 220 231 public Enumeration entries() { 232 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "entries()"); 235 return new WSEntries(provider).getEntries(); 237 } 238 239 247 public InputStream getEntry(String str) { 248 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getEntry(" + str + ")"); 251 InputStream in = new WSEntries(provider).getEntry(str); 253 254 return in; 256 } 257 258 265 public File getEntryFile(String str) { 266 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), "getEntryFile(" + str + ")"); 269 for (FileObject fo: provider.getSourceRoots()) { 271 File file = new File (FileUtil.toFile(fo), str); 272 273 if (file.exists()) { 274 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), " -- " + file); 277 return file; 278 } 279 } 280 281 if (WSDebug.isEnabled()) WSDebug.notify(getClass(), " -- null"); return null; 284 } 285 286 293 private static class WSEntries { 294 295 299 private J2eeModuleProvider provider; 300 301 307 public WSEntries (J2eeModuleProvider provider) { 308 this.provider = provider; 309 } 310 311 317 public InputStream getEntry(String entry) { 318 JarFile jar = null; 319 try { 320 File archive = FileUtil.toFile(provider.getJ2eeModule().getArchive()); 321 if (WSDebug.isEnabled()) 322 WSDebug.notify(WSEntries.class, archive.getPath()); 323 324 jar = new JarFile (archive); 325 326 return jar.getInputStream(jar.getEntry(entry)); 327 } catch (IOException e) { 328 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 329 } 330 340 return null; 341 } 342 343 349 public Enumeration getEntries() { 350 Vector entries = new Vector(); 351 352 JarFile jar = null; 353 try { 354 File archive = FileUtil.toFile(provider.getJ2eeModule().getArchive()); 355 356 if (WSDebug.isEnabled()) 357 WSDebug.notify(WSEntries.class, archive.getPath()); 358 359 jar = new JarFile (archive); 360 Enumeration<JarEntry > jarEntries = jar.entries(); 361 362 while (jarEntries.hasMoreElements()) { 363 String name = jarEntries.nextElement().getName(); 364 365 if (!name.endsWith("/")) { 366 if (WSDebug.isEnabled()) 367 WSDebug.notify(WSEntries.class, " -- " + name); 368 entries.add(name); 369 } 370 } 371 372 return entries.elements(); 373 } catch (Exception ex) { 374 WSDebug.notify(ex); 375 } finally { 376 if (jar != null) { 377 try { 378 jar.close(); 379 } catch (IOException e) { 380 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 381 } 382 } 383 } 384 385 return null; 386 } 387 } 388 } | Popular Tags |