1 25 26 27 package org.objectweb.jonas_ejb.deployment.lib; 28 29 import java.io.File ; 30 import java.io.FileInputStream ; 31 import java.io.FileNotFoundException ; 32 import java.io.IOException ; 33 import java.io.InputStream ; 34 import java.io.InputStreamReader ; 35 import java.io.Reader ; 36 import java.net.MalformedURLException ; 37 import java.net.URL ; 38 import java.net.URLClassLoader ; 39 import java.util.Enumeration ; 40 import java.util.Hashtable ; 41 import java.util.List ; 42 import java.util.StringTokenizer ; 43 import java.util.Vector ; 44 import java.util.zip.ZipEntry ; 45 import java.util.zip.ZipFile ; 46 47 import org.objectweb.jonas_ejb.deployment.api.BeanDesc; 48 import org.objectweb.jonas_ejb.deployment.api.DeploymentDesc; 49 import org.objectweb.jonas_ejb.deployment.api.DeploymentDescEjb1_1; 50 import org.objectweb.jonas_ejb.deployment.api.DeploymentDescEjb2; 51 import org.objectweb.jonas_ejb.deployment.api.EntityDesc; 52 import org.objectweb.jonas_ejb.deployment.api.MessageDrivenDesc; 53 import org.objectweb.jonas_ejb.deployment.api.SessionDesc; 54 import org.objectweb.jonas_ejb.deployment.rules.EjbJarRuleSet; 55 import org.objectweb.jonas_ejb.deployment.rules.JonasEjbJarRuleSet; 56 import org.objectweb.jonas_ejb.deployment.xml.EjbJar; 57 import org.objectweb.jonas_ejb.deployment.xml.JonasEjbJar; 58 import org.objectweb.jonas_ejb.lib.BeanNaming; 59 60 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 61 import org.objectweb.jonas_lib.deployment.api.EjbLocalRefDesc; 62 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc; 63 import org.objectweb.jonas_lib.deployment.api.JndiEnvRefsGroup; 64 import org.objectweb.jonas_lib.deployment.api.MessageDestinationRefDesc; 65 import org.objectweb.jonas_lib.deployment.digester.JDigester; 66 import org.objectweb.jonas_lib.deployment.lib.AbsDeploymentDescManager; 67 import org.objectweb.jonas_lib.deployment.xml.JonasMessageDestination; 68 69 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc; 70 import org.objectweb.jonas_ws.deployment.api.PortComponentRefDesc; 71 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 72 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException; 73 import org.objectweb.jonas_ws.deployment.lib.WSDeploymentDescManager; 74 75 import org.objectweb.jonas.common.Log; 76 77 import org.objectweb.util.monolog.api.BasicLevel; 78 import org.objectweb.util.monolog.api.Logger; 79 80 92 public class EjbDeploymentDescManager extends AbsDeploymentDescManager { 93 94 97 public static final String EJB_JAR_FILE_NAME = "META-INF/ejb-jar.xml"; 98 99 102 public static final String JONAS_EJB_JAR_FILE_NAME = "META-INF/jonas-ejb-jar.xml"; 103 104 107 private static boolean parsingWithValidation = true; 108 109 112 private static EjbDeploymentDescManager unique; 113 114 115 118 private static JDigester ejbjarDigester = null; 119 120 123 private static JDigester jonasEjbjarDigester = null; 124 125 128 private static EjbJarRuleSet ejbjarRuleSet = new EjbJarRuleSet(); 129 130 133 private static JonasEjbJarRuleSet jonasEjbjarRuleSet = new JonasEjbJarRuleSet(); 134 135 136 139 private WSDeploymentDescManager wsDDManager = null; 140 141 145 private Hashtable urlJarBindings; 146 147 150 private Hashtable urlEarCLBindings; 151 152 155 private Hashtable urlEjbCLBindings; 156 157 160 private Hashtable urlAltDDBindings = null; 161 162 167 private Hashtable earCLEjbLinkJar; 168 169 172 private static Logger logger = Log.getLogger("org.objectweb.jonas_ejb.dd"); 173 174 177 private static Hashtable staticCache = new Hashtable (); 178 179 182 private static String xmlContent = ""; 183 184 187 private static String jonasXmlContent = ""; 188 189 192 private EjbDeploymentDescManager() { 193 urlJarBindings = new Hashtable (); 194 urlEarCLBindings = new Hashtable (); 195 urlEjbCLBindings = new Hashtable (); 196 earCLEjbLinkJar = new Hashtable (); 197 urlAltDDBindings = new Hashtable (); 198 } 199 200 204 public static EjbDeploymentDescManager getInstance() { 205 if (unique == null) { 206 unique = new EjbDeploymentDescManager(); 207 } 208 return unique; 209 } 210 211 220 public static DeploymentDesc getDeploymentDesc(String ejbjar, ClassLoader ejbLoader) 221 throws DeploymentDescException { 222 if (!staticCache.containsKey(ejbjar)) { 223 return getDeploymentDescriptor(ejbjar, ejbLoader, (String ) null); 224 } else { 225 return (DeploymentDesc) staticCache.get(ejbjar); 226 } 227 } 228 229 242 public synchronized DeploymentDesc getDeploymentDesc(URL url, 243 ClassLoader ejbLoader, 244 ClassLoader earLoader) 245 throws DeploymentDescException { 246 if (wsDDManager == null) { 248 wsDDManager = WSDeploymentDescManager.getInstance(); 249 } 250 251 if (earLoader != null) { 254 checkEjbLinkAvailable(earLoader, url); 255 } 256 257 DeploymentDesc dd = (DeploymentDesc) urlJarBindings.get(url.getFile()); 258 if (dd == null) { 259 dd = loadDeploymentDesc(url, ejbLoader, earLoader); 261 } 262 return dd; 263 } 264 265 274 private DeploymentDesc getDeploymentDesc(URL currentUrl, URL urlToLoad) 275 throws DeploymentDescException { 276 DeploymentDesc ejbLinkDD = (DeploymentDesc) urlJarBindings.get(urlToLoad.getFile()); 277 if (ejbLinkDD == null) { 278 String url = currentUrl.getFile(); 280 URLClassLoader earLoader = (URLClassLoader ) urlEarCLBindings.get(url); 281 if (new File (url).isFile()) { 282 if (!url.toLowerCase().endsWith(".jar")) { 283 String err = "File '" + url + "' is not a jar file"; 284 throw new DeploymentDescException(err); 285 } 286 } 287 288 if (earLoader != null) { 289 291 checkEjbLinkAvailable(earLoader, urlToLoad); 294 295 URLClassLoader loaderForCls = (URLClassLoader ) urlEjbCLBindings.get(url); 297 298 if (loaderForCls == null) { 300 loaderForCls = new URLClassLoader (new URL [] {urlToLoad}); 301 } 302 303 URLClassLoader loader = (URLClassLoader ) urlEarCLBindings.get(url); 305 ejbLinkDD = loadDeploymentDesc(urlToLoad, loaderForCls, loader); 306 } else { 307 if (!currentUrl.getFile().equals(urlToLoad)) { 309 String err = "In '" + url + "' ejb-link is not allowed outside the ejb-jar if you are not in an ear application."; 310 throw new DeploymentDescException(err); 311 } 312 } 314 } 315 return ejbLinkDD; 316 } 317 318 329 private DeploymentDesc loadDeploymentDesc(URL url, ClassLoader ejbLoader, ClassLoader earLoader) 330 throws DeploymentDescException { 331 String filename = url.getFile(); 333 File f = new File (filename); 334 if (!f.exists()) { 335 throw new DeploymentDescException(filename + " not found"); 336 } 337 338 DeploymentDesc dd = null; 340 if (f.isDirectory()) { 341 dd = getDeploymentDescriptor(filename + EJB_JAR_FILE_NAME, 342 BeanNaming.getJonasXmlName(filename + EJB_JAR_FILE_NAME), 343 ejbLoader, 344 f.getAbsolutePath()); 345 346 } else if (filename.toLowerCase().endsWith(".xml")) { 347 File parent = f.getParentFile(); 350 dd = getDeploymentDescriptor(filename, 351 BeanNaming.getJonasXmlName(filename), 352 ejbLoader, 353 parent.getAbsolutePath()); 354 } else { 355 String altname = null; 358 URL altDDUrl = (URL ) urlAltDDBindings.get(url.getFile()); 359 if (altDDUrl != null) { 360 altname = altDDUrl.getFile(); 361 } 362 dd = getDeploymentDescriptor(filename, ejbLoader, altname); 363 } 364 365 if (earLoader != null) { 367 urlEjbCLBindings.put(filename, ejbLoader); 368 urlEarCLBindings.put(filename, earLoader); 369 } 370 371 BeanDesc[] bd = dd.getBeanDesc(); 372 for (int j = 0; j < bd.length; j++) { 373 374 EjbRefDesc[] ejbRef = bd[j].getEjbRefDesc(); 376 for (int i = 0; i < ejbRef.length; i++) { 377 String jndiName = ejbRef[i].getJndiName(); 378 String ejbLink = ejbRef[i].getEjbLink(); 379 String ejbRefType = ejbRef[i].getEjbRefType(); 380 if (ejbLink != null && jndiName == null) { 381 String ejbName = getJndiName(url, ejbLink, earLoader, ejbRefType, dd, true); 382 ejbRef[i].setJndiName(ejbName); 383 } 384 } 385 386 EjbLocalRefDesc[] ejbLocalRef = bd[j].getEjbLocalRefDesc(); 388 for (int i = 0; i < ejbLocalRef.length; i++) { 389 String ejblink = ejbLocalRef[i].getEjbLink(); 390 if (ejblink == null) { 391 String err = "Ejb-link must be specified for ejb-local-ref " + ejbLocalRef[i].getEjbRefName(); 392 throw new DeploymentDescException(err); 393 } 394 String ejbRefType = ejbLocalRef[i].getEjbRefType(); 395 String ejbName = getJndiName(url, ejblink, earLoader, ejbRefType, dd, false); 396 ejbLocalRef[i].setJndiLocalName(ejbName); 397 } 398 399 ServiceRefDesc[] serviceRef = bd[j].getServiceRefDesc(); 401 402 for (int i = 0; i < serviceRef.length; i++) { 403 List pcRefs = serviceRef[i].getPortComponentRefs(); 404 405 for (int k = 0; k < pcRefs.size(); k++) { 406 PortComponentRefDesc pcr = (PortComponentRefDesc) pcRefs.get(k); 408 String pclink = pcr.getPortComponentLink(); 409 if (pclink != null) { 410 PortComponentDesc pcDesc = getPCDesc(url, pclink, ejbLoader, earLoader); 412 pcr.setPortComponentDesc(pcDesc); 413 } 414 } 415 } 416 417 MessageDestinationRefDesc[] mdRef = bd[j].getMessageDestinationRefDesc(); 419 for (int i = 0; i < mdRef.length; i++) { 420 String jndiName = mdRef[i].getJndiName(); 421 String mdLink = mdRef[i].getMessageDestinationLink(); 422 String mdType = mdRef[i].getMessageDestinationType(); 423 String mdUsage = mdRef[i].getMessageDestinationUsage(); 424 if (logger.isLoggable(BasicLevel.DEBUG)) { 425 logger.log(BasicLevel.DEBUG, "" + jndiName + " " + mdLink + " " + mdType + " " + mdUsage); 426 } 427 if (mdLink != null && jndiName == null) { 428 String mdName = getMDJndiName(url, mdLink, mdType, mdUsage, dd); 429 mdRef[i].setJndiName(mdName); 430 } 431 } 432 433 } 434 435 if (earLoader != null) { 437 urlJarBindings.put(filename, dd); 439 } 440 441 return dd; 442 } 443 444 445 461 private PortComponentDesc getPCDesc(URL ejbjarURL, 462 String pcLink, 463 ClassLoader moduleLoader, 464 ClassLoader earLoader) 465 throws WSDeploymentDescException { 466 467 return wsDDManager.getPortComponentDesc(ejbjarURL, pcLink, moduleLoader, earLoader); 469 } 470 471 472 487 public String getJndiName(URL currentFile, String ejbLink, ClassLoader earCl, String ejbType, 488 DeploymentDesc deploymentDesc, boolean isEjbRef) 489 throws DeploymentDescException { 490 String ejbJarLink = null; 494 String beanNameLink = null; 495 496 if (ejbLink.indexOf(LINK_SEPARATOR) == -1) { 498 BeanDesc bd = null; 499 if (earCl == null && deploymentDesc == null) { 501 throw new DeploymentDescException("Deployment desc for file ejb-jar '" + currentFile.getFile() + "' not found"); 502 } 503 if (deploymentDesc != null) { 505 bd = deploymentDesc.getBeanDesc(ejbLink); 506 } 507 String url = currentFile.getFile(); 508 URLClassLoader earClassLoader = null; 509 URLClassLoader ejbLoader = (URLClassLoader ) urlEjbCLBindings.get(url); 511 if (earCl != null) { 512 earClassLoader = (URLClassLoader ) earCl; 513 urlEarCLBindings.put(url, earCl); 515 } else { 516 earClassLoader = (URLClassLoader ) urlEarCLBindings.get(url); 517 } 518 519 if ((earClassLoader == null) && (bd == null)) { 521 String err = "Ejb-link " + ejbLink + " not found inside the file " + currentFile.getFile() + ". The bean doesn't exists."; 522 throw new DeploymentDescException(err); 523 } 524 525 if (bd == null) { 527 if (logger.isLoggable(BasicLevel.DEBUG)) { 528 logger.log(BasicLevel.DEBUG, "The bean '" + ejbLink + "' was not found in the current ejbjar, searching on all the ejbjars."); 529 } 530 Vector v = (Vector ) earCLEjbLinkJar.get(earClassLoader); 531 DeploymentDesc lookupDD = null; 532 String fileName = null; 533 URL urlRead = null; 534 String urlReadString = null; 535 boolean found = false; 536 BeanDesc bdtmp = null; 537 for (Enumeration e = v.elements(); e.hasMoreElements();) { 538 urlReadString = (String ) e.nextElement(); 539 File f = new File (urlReadString); 540 try { 541 urlRead = f.toURL(); 542 } catch (Exception ue) { 543 throw new DeploymentDescException("Cannot make an url with the argument'" + urlReadString + "'."); 544 } 545 if (ejbLoader == null) { 547 ejbLoader = (URLClassLoader ) urlEjbCLBindings.get(urlReadString); 548 } 549 if (ejbLoader == null) { 551 throw new DeploymentDescException("Error while resolving ejb-link. The ejb classloader is not found for url '" + urlReadString + "'."); 552 } 553 554 urlEjbCLBindings.put(urlReadString, ejbLoader); 556 557 fileName = urlRead.getFile(); 558 if (!fileName.equals(url)) { 560 if (f.isDirectory()) { 563 lookupDD = getDeploymentDescriptor(fileName + EJB_JAR_FILE_NAME, 564 BeanNaming.getJonasXmlName(fileName + EJB_JAR_FILE_NAME), 565 ejbLoader, 566 f.getAbsolutePath()); 567 } else if (fileName.toLowerCase().endsWith(".xml")) { 568 File parent = f.getParentFile().getParentFile(); 571 lookupDD = getDeploymentDescriptor(fileName, 572 BeanNaming.getJonasXmlName(fileName), 573 ejbLoader, 574 parent.getAbsolutePath()); 575 } else { 576 String altname = null; 579 URL altDDUrl = (URL ) urlAltDDBindings.get(url); 580 if (altDDUrl != null) { 581 altname = altDDUrl.getFile(); 582 } 583 lookupDD = getDeploymentDescriptor(fileName, 584 ejbLoader, 585 altname); 586 } 587 588 if (lookupDD != null) { 589 bdtmp = lookupDD.getBeanDesc(ejbLink); 590 if (bdtmp != null) { 591 if (logger.isLoggable(BasicLevel.DEBUG)) { 592 logger.log(BasicLevel.DEBUG, "Found a BeanDesc in the Deployment Desc." + urlRead); 593 } 594 if (found) { 596 String err = "There are more than one bean with the name '" + ejbLink + "' which were found in all the ejbjars of this EAR."; 597 throw new DeploymentDescException(err); 598 } else { 599 found = true; 600 bd = bdtmp; 601 } 602 } else { 603 if (logger.isLoggable(BasicLevel.DEBUG)) { 604 logger.log(BasicLevel.DEBUG, "No BeanDesc found in the Deployment Desc." + urlRead); 605 } 606 } 607 } 608 } 609 } 610 if (!found) { 611 String err = "No ejblink was found for '" + ejbLink + "' in all the ejbjars of this EAR."; 612 throw new DeploymentDescException(err); 613 } 614 } 615 616 if (logger.isLoggable(BasicLevel.DEBUG)) { 617 logger.log(BasicLevel.DEBUG, "BeanDesc found = " + bd.getEjbName()); 618 } 619 checkType(currentFile, ejbType, bd); 621 622 if (bd == null) { 623 String err = "Ejb-link " + ejbLink + " not found inside the file " + currentFile.getFile() + ". The bean doesn't exists."; 624 throw new DeploymentDescException(err); 625 } 626 627 String jndiname; 628 if (isEjbRef) { 629 jndiname = bd.getJndiName(); 630 } else { 631 jndiname = bd.getJndiLocalName(); 632 } 633 return jndiname; 634 } 635 636 if (earCl != null) { 637 String url = currentFile.getFile(); 638 urlEarCLBindings.put(url, earCl); 640 } 641 642 StringTokenizer st = new StringTokenizer (ejbLink, LINK_SEPARATOR); 644 645 if (st.countTokens() != 2 || ejbLink.startsWith(LINK_SEPARATOR) 648 || ejbLink.endsWith(LINK_SEPARATOR)) { 649 650 String err = "Ejb link " + ejbLink + " has a bad format. Correct format : filename.jar#beanName."; 651 throw new DeploymentDescException(err); 652 } 653 654 ejbJarLink = st.nextToken(); 656 beanNameLink = st.nextToken(); 657 658 if (!ejbJarLink.endsWith(".jar")) { 660 String err = "Ejbjar filename " + ejbJarLink + " from the ejb-link " + ejbLink + " has a bad format. Correct format : filename.jar"; 661 throw new DeploymentDescException(err); 662 } 663 664 665 URL ejbJarLinkUrl = null; 668 try { 669 ejbJarLinkUrl = new File (new File (currentFile.getFile()).getParent() + File.separator + ejbJarLink).getCanonicalFile().toURL(); 670 } catch (MalformedURLException mue) { 671 String err = "Error when creating an url for the ejb jar filename. Error :" + mue.getMessage(); 672 throw new DeploymentDescException(err); 673 } catch (IOException ioe) { 674 String err = "Error when creating/accessing a file. Error :" + ioe.getMessage(); 675 throw new DeploymentDescException(err); 676 } 677 678 BeanDesc bd = null; 680 if (currentFile.getPath().equalsIgnoreCase(ejbJarLinkUrl.getPath())) { 682 if (logger.isLoggable(BasicLevel.DEBUG)) { 683 logger.log(BasicLevel.DEBUG, "ejblink jar#bean reference our current file"); 684 } 685 686 if (deploymentDesc != null) { 688 bd = deploymentDesc.getBeanDesc(beanNameLink); 689 } else { 690 if (logger.isLoggable(BasicLevel.DEBUG)) { 691 logger.log(BasicLevel.DEBUG, "DD = null, cannot return bean in the current DD"); 692 } 693 } 694 695 } else { 696 698 DeploymentDesc dd = getDeploymentDesc(currentFile, ejbJarLinkUrl); 700 701 bd = dd.getBeanDesc(beanNameLink); 703 } 704 705 if (bd == null) { 706 String err = "Ejb-link " + ejbLink + " not found inside the file " + currentFile.getFile() + ". The bean doesn't exists"; 707 throw new DeploymentDescException(err); 708 } 709 710 checkType(currentFile, ejbType, bd); 712 713 String jndiname; 714 if (isEjbRef) { 715 jndiname = bd.getJndiName(); 716 } else { 717 jndiname = bd.getJndiLocalName(); 718 } 719 return jndiname; 720 } 721 722 736 private String getMDJndiName(URL ejbJar, String mdLink, String mdType, String mdUsage, 737 DeploymentDesc deploymentDesc) 738 throws DeploymentDescException { 739 740 if (logger.isLoggable(BasicLevel.DEBUG)) { 741 logger.log(BasicLevel.DEBUG, "" + ejbJar + " " + mdLink + " " + mdType + " " + mdUsage); 742 } 743 String ejbJarLink = null; 747 String destNameLink = null; 748 DeploymentDesc dd = deploymentDesc; 749 750 if (mdLink.indexOf(LINK_SEPARATOR) != -1) { 752 StringTokenizer st = new StringTokenizer (mdLink, LINK_SEPARATOR); 754 755 if (st.countTokens() != 2 || mdLink.startsWith(LINK_SEPARATOR) 758 || mdLink.endsWith(LINK_SEPARATOR)) { 759 760 String err = "Message-destination-link " + mdLink + " has a bad format. Correct format : filename.jar#messageDestinationName."; 761 throw new DeploymentDescException(err); 762 } 763 764 ejbJarLink = st.nextToken(); 766 destNameLink = st.nextToken(); 767 768 if (!ejbJarLink.endsWith(".jar")) { 770 String err = "Ejbjar filename " + ejbJarLink + " from the message-destination-link " + mdLink + " has a bad format. Correct format : filename.jar"; 771 throw new DeploymentDescException(err); 772 } 773 774 775 URL ejbJarLinkUrl = null; 778 try { 779 ejbJarLinkUrl = new File (new File (ejbJar.getFile()).getParent() + File.separator + ejbJarLink).getCanonicalFile().toURL(); 780 } catch (MalformedURLException mue) { 781 String err = "Error when creating an url for the ejb jar filename. Error :" + mue.getMessage(); 782 throw new DeploymentDescException(err); 783 } catch (IOException ioe) { 784 String err = "Error when creating/accessing a file. Error :" + ioe.getMessage(); 785 throw new DeploymentDescException(err); 786 } 787 788 if (!new File (ejbJarLinkUrl.getFile()).exists()) { 790 String err = "Cannot get the deployment descriptor for '" + ejbJarLinkUrl.getFile() + "'. The file doesn't exist."; 791 throw new DeploymentDescException(err); 792 } 793 794 dd = getDeploymentDesc(ejbJar, ejbJarLinkUrl); 797 } 798 799 if (dd == null) { 801 throw new DeploymentDescException("Deployment desc for file ejb-jar '" + ejbJar.getFile() + "' not found"); 802 } 803 804 boolean foundMd = dd.getMessageDestination(mdLink); 805 if (!foundMd) { 806 String err = "No message-destination was found for '" + mdLink + "' in the ejbjar specified."; 807 throw new DeploymentDescException(err); 808 } 809 810 JonasMessageDestination md = dd.getJonasMessageDestination(mdLink); 811 812 if (md == null) { 813 String err = "No jonas-message-destination was found for '" + mdLink + "' in the ejbjar specified."; 814 throw new DeploymentDescException(err); 815 } 816 817 if (logger.isLoggable(BasicLevel.DEBUG)) { 818 logger.log(BasicLevel.DEBUG, "Message-destination found = " + md.getJndiName()); 819 } 820 821 824 return md.getJndiName(); 825 826 } 827 828 834 private void checkEjbLinkAvailable(ClassLoader earClassLoader, 835 URL url) 836 throws DeploymentDescException { 837 838 Vector v = (Vector ) earCLEjbLinkJar.get(earClassLoader); 839 840 if (v != null) { 841 if (!v.contains(url.getFile())) { 842 String err = "The ejb-link or message-destination-link of '" + url.getFile() + "' must be done on an ejb-jar defined in the ear application (application.xml <module><ejb>###</ejb></module>)"; 843 throw new DeploymentDescException(err); 844 } 845 } else { 846 String err = "setAvailableEjbLinkJar was badly called."; 847 throw new DeploymentDescException(err); 848 } 849 } 850 851 859 public void setAvailableEjbJarsAndAltDDs(ClassLoader earClassLoader, 860 URL [] urls, 861 URL [] altDDs) { 862 Vector v = new Vector (); 863 for (int i = 0; i < urls.length; i++) { 864 v.addElement(urls[i].getFile()); 865 if (altDDs[i] != null) { 866 urlAltDDBindings.put(urls[i].getFile(), altDDs[i]); 867 } 868 } 869 earCLEjbLinkJar.put(earClassLoader, v); 870 } 871 872 878 public void removeCache(ClassLoader earClassLoader) { 879 Vector v = (Vector ) earCLEjbLinkJar.remove(earClassLoader); 880 if (v != null) { 881 for (int i = 0; i < v.size(); i++) { 882 String url = (String ) v.elementAt(i); 883 urlJarBindings.remove(url); 884 urlEarCLBindings.remove(url); 885 urlEjbCLBindings.remove(url); 886 urlAltDDBindings.remove(url); 887 } 888 } 889 890 if (earCLEjbLinkJar.size() != 0 891 || urlJarBindings.size() != 0 892 || urlEarCLBindings.size() != 0 893 || urlAltDDBindings.size() != 0 894 || urlEjbCLBindings.size() != 0) { 895 896 String buffer = earCLEjbLinkJar.size() + " "; 897 buffer += urlJarBindings.size() + " "; 898 buffer += urlEarCLBindings.size() + " "; 899 buffer += urlEjbCLBindings.size() + " "; 900 buffer += urlAltDDBindings.size(); 901 902 if (logger.isLoggable(BasicLevel.DEBUG)) { 903 logger.log(BasicLevel.DEBUG, buffer + " there are some elements in cache"); 904 } 905 } 906 } 907 908 913 public int getCacheSize() { 914 return earCLEjbLinkJar.size() + urlJarBindings.size() 915 + urlEarCLBindings.size() + urlEjbCLBindings.size() 916 + urlAltDDBindings.size(); 917 } 918 919 923 public String toString() { 924 return earCLEjbLinkJar.size() + " " + urlJarBindings.size() + " " 925 + urlEarCLBindings.size() + " " + urlEjbCLBindings.size() + " " 926 + urlAltDDBindings.size(); 927 } 928 929 940 public static DeploymentDesc getDeploymentDesc(String ejbJarXmlFileName, 941 String jonasEjbJarXmlFileName, 942 String jarFileName) 943 throws DeploymentDescException { 944 ClassLoader cl = DeploymentDesc.class.getClassLoader(); 946 if (cl == null) { 947 cl = Thread.currentThread().getContextClassLoader(); 948 } 949 return getDeploymentDescriptor(ejbJarXmlFileName, jonasEjbJarXmlFileName, cl, jarFileName); 950 } 951 952 963 private static DeploymentDesc getDeploymentDescriptor(String ejbJarXmlFileName, 964 String jonasEjbJarXmlFileName, 965 ClassLoader cl, 966 String moduleDirName) 967 throws DeploymentDescException { 968 969 InputStream is; 970 971 try { 973 is = new FileInputStream (ejbJarXmlFileName); 974 xmlContent = xmlContent(is); 976 is = new FileInputStream (ejbJarXmlFileName); 978 } catch (FileNotFoundException e) { 979 throw new DeploymentDescException(ejbJarXmlFileName + " file not found"); 980 } catch (IOException ioe) { 981 throw new DeploymentDescException("Cannot read the content of the xml file " + ejbJarXmlFileName); 982 } 983 EjbJar ejbJar = loadEjbJar(new InputStreamReader (is), ejbJarXmlFileName); 984 String dtdversion = ejbJar.getVersion(); 985 try { 986 is.close(); 987 } catch (IOException e) { 988 logger.log(BasicLevel.WARN, "Can't close '" + ejbJarXmlFileName + "'"); 989 } 990 991 try { 993 is = new FileInputStream (jonasEjbJarXmlFileName); 994 jonasXmlContent = xmlContent(is); 996 is = new FileInputStream (jonasEjbJarXmlFileName); 998 } catch (FileNotFoundException e) { 999 throw new DeploymentDescException(jonasEjbJarXmlFileName + " file not found"); 1000 } catch (IOException ioe) { 1001 throw new DeploymentDescException("Cannot read the content of the xml file " + ejbJarXmlFileName); 1002 } 1003 1004 JonasEjbJar jonasEjbJar = loadJonasEjbJar(new InputStreamReader (is), 1005 jonasEjbJarXmlFileName); 1006 try { 1007 is.close(); 1008 } catch (IOException e) { 1009 logger.log(BasicLevel.WARN, "Can't close '" + jonasEjbJarXmlFileName + "'"); 1010 } 1011 1012 DeploymentDesc descEjb = null; 1014 if (dtdversion.equals("1.1")) { 1015 descEjb = new DeploymentDescEjb1_1(cl, ejbJar, jonasEjbJar, logger, moduleDirName); 1016 } else { 1017 descEjb = new DeploymentDescEjb2(cl, ejbJar, jonasEjbJar, logger, moduleDirName); 1018 } 1019 descEjb.setXmlContent(xmlContent); 1020 descEjb.setJOnASXmlContent(jonasXmlContent); 1021 return descEjb; 1022 } 1023 1024 1025 1035 private static DeploymentDesc getDeploymentDescriptor(String ejbJarFileName, 1036 ClassLoader cl, 1037 String altWebXmlFilename) 1038 throws DeploymentDescException { 1039 1040 ZipFile zf = null; 1041 InputStream isDd = null; 1042 InputStream isJdd = null; 1043 EjbJar ejbJar; 1044 JonasEjbJar jonasEjbJar; 1045 1046 if ((altWebXmlFilename != null) && (!new File (altWebXmlFilename).exists())) { 1048 String err = "The file for the altdd tag for the EAR case '" + altWebXmlFilename + "' was not found."; 1049 throw new DeploymentDescException(err); 1050 } 1051 1052 try { 1054 zf = new ZipFile (ejbJarFileName); 1055 1056 if (altWebXmlFilename == null) { 1057 ZipEntry ejbEntry = zf.getEntry(EJB_JAR_FILE_NAME); 1059 if (ejbEntry == null) { 1060 throw new DeploymentDescException("The entry '" + EJB_JAR_FILE_NAME 1061 + "' was not found in the file '" + ejbJarFileName + "'."); 1062 } 1063 isDd = zf.getInputStream(ejbEntry); 1064 xmlContent = xmlContent(isDd); 1065 isDd = zf.getInputStream(zf.getEntry(EJB_JAR_FILE_NAME)); 1066 } else { 1067 isDd = new FileInputStream (altWebXmlFilename); 1069 xmlContent = xmlContent(isDd); 1070 isDd = new FileInputStream (altWebXmlFilename); 1071 } 1072 ZipEntry jEjbEntry = zf.getEntry(JONAS_EJB_JAR_FILE_NAME); 1073 if (jEjbEntry != null) { 1074 isJdd = zf.getInputStream(jEjbEntry); 1075 jonasXmlContent = xmlContent(isJdd); 1076 isJdd = zf.getInputStream(zf.getEntry(JONAS_EJB_JAR_FILE_NAME)); 1077 } else { 1078 logger.log(BasicLevel.WARN, "No entry '" + JONAS_EJB_JAR_FILE_NAME + "' was found in the file '" + ejbJarFileName + "'."); 1079 } 1080 } catch (Exception e) { 1081 if (zf != null) { 1082 try { 1083 zf.close(); 1084 } catch (IOException i) { 1085 logger.log(BasicLevel.WARN, "Can't close '" + ejbJarFileName + "'"); 1086 } 1087 } 1088 logger.log(BasicLevel.ERROR, "Cannot read the XML deployment descriptors for " + ejbJarFileName + ":", e); 1089 throw new DeploymentDescException("Cannot read the XML deployment descriptors for " + ejbJarFileName + ":" + e); 1090 } 1091 1092 ejbJar = loadEjbJar(new InputStreamReader (isDd), EJB_JAR_FILE_NAME); 1094 String dtdversion = ejbJar.getVersion(); 1095 try { 1096 isDd.close(); 1097 } catch (IOException e) { 1098 logger.log(BasicLevel.WARN, "Can't close META-INF/ejb-jar.xml in '" + ejbJarFileName + "'"); 1099 } 1100 1101 if (isJdd != null) { 1103 jonasEjbJar = loadJonasEjbJar(new InputStreamReader (isJdd), 1104 JONAS_EJB_JAR_FILE_NAME); 1105 try { 1106 isJdd.close(); 1107 } catch (IOException e) { 1108 logger.log(BasicLevel.WARN, "Can't close META-INF/jonas-ejb-jar.xml in '" + ejbJarFileName + "'"); 1109 } 1110 1111 } else { 1112 jonasEjbJar = new JonasEjbJar(); 1113 } 1114 1115 if (zf != null) { 1117 try { 1118 zf.close(); 1119 } catch (IOException e) { 1120 logger.log(BasicLevel.WARN, "Can't close '" + ejbJarFileName + "'"); 1121 } 1122 } 1123 1124 DeploymentDesc descEjb = null; 1126 if (dtdversion.equals("1.1")) { 1127 descEjb = new DeploymentDescEjb1_1(cl, ejbJar, jonasEjbJar, logger, ejbJarFileName); 1128 } else { 1129 descEjb = new DeploymentDescEjb2(cl, ejbJar, jonasEjbJar, logger, ejbJarFileName); 1130 } 1131 descEjb.setXmlContent(xmlContent); 1132 descEjb.setJOnASXmlContent(jonasXmlContent); 1133 return descEjb; 1134 } 1135 1136 1137 1145 public static EjbJar loadEjbJar(Reader reader, String name) 1146 throws DeploymentDescException { 1147 EjbJar ejbjar = new EjbJar(); 1148 1149 if (ejbjarDigester == null) { 1151 ejbjarDigester = new JDigester(ejbjarRuleSet, 1153 parsingWithValidation, 1154 true, 1155 new EjbjarDTDs(), 1156 new EjbjarSchemas()); 1157 } 1158 try { 1159 ejbjarDigester.parse(reader, name, ejbjar); 1160 } catch (DeploymentDescException e) { 1161 throw e; 1162 } finally { 1163 ejbjarDigester.push(null); 1164 } 1165 return ejbjar; 1166 } 1167 1168 1175 public static JonasEjbJar loadJonasEjbJar(Reader reader, 1176 String name) 1177 throws DeploymentDescException { 1178 JonasEjbJar jonasEjbjar = new JonasEjbJar(); 1179 if (jonasEjbjarDigester == null) { 1181 jonasEjbjarDigester = new JDigester(jonasEjbjarRuleSet, 1183 parsingWithValidation, 1184 true, 1185 new JonasEjbjarDTDs(), 1186 new JonasEjbjarSchemas()); 1187 } 1188 try { 1189 jonasEjbjarDigester.parse(reader , name, jonasEjbjar); 1190 } catch (DeploymentDescException e) { 1191 throw e; 1192 } finally { 1193 jonasEjbjarDigester.push(null); 1194 } 1195 return jonasEjbjar; 1196 } 1197 1198 1202 public static boolean getParsingWithValidation() { 1203 return parsingWithValidation; 1204 } 1205 1206 1210 public static void setParsingWithValidation(boolean validation) { 1211 EjbDeploymentDescManager.parsingWithValidation = validation; 1212 } 1213 1214 1218 public static String getXmlContent() { 1219 return xmlContent; 1220 } 1221 1222 1226 public static String getJOnASXmlContent() { 1227 return jonasXmlContent; 1228 } 1229 1230 1231 1238 protected void checkType(URL ejbJar, String ejbType, JndiEnvRefsGroup bd) throws DeploymentDescException { 1239 1240 if (bd instanceof SessionDesc) { 1241 if (!ejbType.equalsIgnoreCase("Session")) { 1242 String err = "Deployment desc '" + ejbJar.getFile() 1243 + "' has an incompatible ejb-ref-type: Required Session but found " + ejbType; 1244 throw new DeploymentDescException(err); 1245 } 1246 } else if (bd instanceof EntityDesc) { 1247 if (!ejbType.equalsIgnoreCase("Entity")) { 1248 String err = "Deployment desc '" + ejbJar.getFile() 1249 + "' has an incompatible ejb-ref-type: Required Entity but found " + ejbType; 1250 throw new DeploymentDescException(err); 1251 } 1252 } else { 1253 String err = "Deployment desc '" + ejbJar.getFile() + "' has a bad ejb-ref-type."; 1254 throw new DeploymentDescException(err); 1255 } 1256 } 1257 1258 1268 protected void checkTypeUsage(URL url, String mdType, String mdUsage, BeanDesc bd) throws DeploymentDescException { 1269 1270 if (bd instanceof MessageDrivenDesc) { 1271 MessageDrivenDesc mdd = (MessageDrivenDesc) bd; 1272 if (mdd.getDestinationType().equals("javax.jms.Topic")) { 1273 if (!mdType.equalsIgnoreCase("javax.jms.Topic")) { 1274 String err = "Deployment desc '" + url.getFile() 1275 + "' has an incompatible message-destination-type: Required javax.jms.Topic but found " 1276 + mdType; 1277 throw new DeploymentDescException(err); 1278 } 1279 } else if (mdd.getDestinationType().equals("javax.jms.Queue")) { 1280 if (!mdType.equalsIgnoreCase("javax.jms.Queue")) { 1281 String err = "Deployment desc '" + url.getFile() 1282 + "' has an incompatible message-destination-type: Required javax.jms.Queue but found " 1283 + mdType; 1284 throw new DeploymentDescException(err); 1285 } 1286 } 1287 } else { 1288 String err = "Deployment desc '" + url.getFile() + "' has a bad message-destination-ref-type."; 1289 throw new DeploymentDescException(err); 1290 } 1291 } 1292 1293 1298 public void addClassLoaderUrlMapping(ClassLoader ejbClassloader, URL [] urls) { 1299 for (int u = 0; u < urls.length; u++) { 1300 urlEjbCLBindings.put(urls[u].getPath(), ejbClassloader); 1301 } 1302 } 1303} 1304 | Popular Tags |