1 25 26 package org.objectweb.jonas_lib.genbase.archive; 27 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.net.URL ; 32 import java.util.Hashtable ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Vector ; 36 37 import javax.xml.parsers.ParserConfigurationException ; 38 39 import org.w3c.dom.Document ; 40 import org.xml.sax.SAXException ; 41 42 import org.objectweb.jonas_ejb.deployment.api.BeanDesc; 43 import org.objectweb.jonas_ejb.deployment.api.DeploymentDesc; 44 import org.objectweb.jonas_ejb.deployment.lib.EjbDeploymentDescManager; 45 46 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 47 import org.objectweb.jonas_lib.genbase.GenBaseException; 48 import org.objectweb.jonas_lib.genbase.utils.XMLUtils; 49 import org.objectweb.jonas_lib.loader.EjbJarClassLoader; 50 51 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDesc; 52 import org.objectweb.jonas_ws.deployment.lib.WSDeploymentDescManager; 53 54 import org.objectweb.util.monolog.api.BasicLevel; 55 56 61 public class EjbJar extends J2EEArchive implements WsEndpoint { 62 63 64 private Application app; 65 66 67 private WSDeploymentDesc wsDD = null; 68 69 70 private DeploymentDesc ejbDD = null; 71 72 73 private List ejbs; 74 75 76 private Map descriptors; 77 78 79 private Document jEjbJar; 80 81 82 private Document jWebservices = null; 83 84 93 public EjbJar(Archive archive) throws GenBaseException { 94 super(archive); 95 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 96 getLogger().log(BasicLevel.DEBUG, "Wrapping '" + archive.getName() + "' in EjbJar"); 97 } 98 init(); 99 } 100 101 112 public EjbJar(Archive archive, Application app) throws GenBaseException { 113 super(archive); 114 setApplication(app); 115 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 116 getLogger().log(BasicLevel.DEBUG, "Wrapping '" + archive.getName() + "' in EjbJar"); 117 } 118 init(); 119 } 120 121 128 private void init() throws GenBaseException { 129 loadDescriptors(); 130 } 131 132 133 137 public void initialize() throws GenBaseException { 138 139 try { 140 if (app == null) { 141 setModuleClassloader(new EjbJarClassLoader(new URL [] {getArchive() 143 .getRootFile().toURL()}, Thread.currentThread() 144 .getContextClassLoader())); 145 } else { 146 setModuleClassloader(app.getEJBClassLoader()); 148 } 149 } catch (IOException ioe) { 150 String err = getI18n().getMessage("EjbJar.init.loader", getArchive() 151 .getRootFile()); 152 throw new GenBaseException(err, ioe); 153 } 154 155 try { 156 ejbDD = EjbDeploymentDescManager.getDeploymentDesc(getRootFile() 157 .getAbsolutePath(), getModuleClassloader()); 158 } catch (DeploymentDescException dde) { 159 throw new GenBaseException(dde); 160 } 161 162 try { 163 wsDD = WSDeploymentDescManager.getDeploymentDesc(getRootFile() 164 .getAbsolutePath(), getModuleClassloader()); 165 } catch (DeploymentDescException dde) { 166 throw new GenBaseException(dde); 167 } 168 169 ejbs = new Vector (); 171 172 BeanDesc[] bd = ejbDD.getBeanDesc(); 173 174 for (int i = 0; i < bd.length; i++) { 175 ejbs.add(new Ejb(bd[i], XMLUtils.getBeanElement(jEjbJar 176 .getDocumentElement(), bd[i].getEjbName()))); 177 } 178 179 } 180 181 182 188 private void loadDescriptors() throws GenBaseException { 189 try { 190 191 jEjbJar = XMLUtils.newDocument(getJonasEjbJarInputStream(), "META-INF/jonas-ejb-jar.xml", isDTDsAllowed()); 192 193 InputStream isJws = getJonasWebservicesInputStream(); 194 if (isJws != null) { 195 jWebservices = XMLUtils.newDocument(isJws, 196 "META-INF/jonas-webservices.xml", isDTDsAllowed()); 197 } 198 199 } catch (SAXException saxe) { 200 String err = getI18n().getMessage("EjbJar.loadDescriptors.parseError"); 201 throw new GenBaseException(err, saxe); 202 } catch (ParserConfigurationException pce) { 203 String err = getI18n().getMessage("EjbJar.loadDescriptors.prepare"); 204 throw new GenBaseException(err, pce); 205 } catch (IOException ioe) { 206 String err = getI18n().getMessage("EjbJar.loadDescriptors.parseError"); 207 throw new GenBaseException(err, ioe); 208 } 209 210 descriptors = new Hashtable (); 211 descriptors.put("META-INF/jonas-ejb-jar.xml", jEjbJar); 212 } 213 214 219 public List getEjbs() { 220 return ejbs; 221 } 222 223 230 public List getServiceDescs() { 231 if (wsDD != null) { 232 return wsDD.getServiceDescs(); 233 } else { 234 return new Vector (); 235 } 236 } 237 238 244 public void addClasses(File classes) { 245 addDirectory(classes); 246 } 247 248 251 public String getWarName() { 252 if (wsDD != null) { 253 return wsDD.getWarFile(); 254 } else { 255 return null; 256 } 257 } 258 259 262 public String getContextRoot() { 263 String archiveName = this.getArchive().getName(); 265 String root = null; 266 if (archiveName.toLowerCase().endsWith(".jar")) { 267 root = archiveName.toLowerCase().substring(0, archiveName.length() - ".jar".length()); 268 } else { 269 root = archiveName; 270 } 271 if (wsDD != null) { 272 String croot = wsDD.getContextRoot(); 273 if (croot != null) { 274 root = croot; 275 } 276 } 277 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 278 getLogger().log(BasicLevel.DEBUG, "Computed context root : " + root); 279 } 280 return root; 281 } 282 283 289 public void setApplication(Application app) { 290 this.app = app; 291 } 292 293 298 public Application getApplication() { 299 return app; 300 } 301 302 308 public Map getDescriptors() { 309 return descriptors; 310 } 311 312 320 public boolean omit(String name) { 321 return (name.equals("META-INF/jonas-ejb-jar.xml") 322 || name.equals("META-INF\\jonas-ejb-jar.xml")); 323 } 324 325 330 public Document getJonasEjbJarDoc() { 331 return jEjbJar; 332 } 333 334 339 public Document getJonasWebservicesDoc() { 340 return jWebservices; 341 } 342 343 351 public InputStream getJonasEjbJarInputStream() throws IOException { 352 InputStream is = null; 353 354 if (isPacked()) { 355 is = getInputStream("META-INF/jonas-ejb-jar.xml"); 356 } else { 357 is = getInputStream("META-INF" + File.separator 358 + "jonas-ejb-jar.xml"); 359 } 360 if (is == null) { 361 throw new IOException ("Cannot read jonas specific DD for EJB as the entry is not present"); 362 } 363 return is; 364 } 365 366 372 public InputStream getJonasWebservicesInputStream() throws IOException { 373 InputStream is = null; 374 375 if (isPacked()) { 376 is = getInputStream("META-INF/jonas-webservices.xml"); 377 } else { 378 is = getInputStream("META-INF" + File.separator 379 + "jonas-webservices.xml"); 380 } 381 return is; 382 } 383 384 385 386 387 388 } 389 | Popular Tags |