1 18 19 package org.apache.tools.ant.taskdefs.optional.ejb; 20 21 import java.io.BufferedReader ; 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.InputStreamReader ; 27 import java.util.ArrayList ; 28 import java.util.Date ; 29 import java.util.HashMap ; 30 import java.util.Hashtable ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Map ; 34 import java.util.Properties ; 35 import java.util.StringTokenizer ; 36 import javax.xml.parsers.SAXParser ; 37 import javax.xml.parsers.SAXParserFactory ; 38 import org.xml.sax.AttributeList ; 39 import org.xml.sax.HandlerBase ; 40 import org.xml.sax.InputSource ; 41 import org.xml.sax.SAXException ; 42 43 67 public class IPlanetEjbc { 68 69 private static final int MIN_NUM_ARGS = 2; 70 private static final int MAX_NUM_ARGS = 8; 71 private static final int NUM_CLASSES_WITH_IIOP = 15; 72 private static final int NUM_CLASSES_WITHOUT_IIOP = 9; 73 74 75 private static final String ENTITY_BEAN = "entity"; 76 private static final String STATELESS_SESSION = "stateless"; 77 private static final String STATEFUL_SESSION = "stateful"; 78 79 80 private File stdDescriptor; 81 private File iasDescriptor; 82 83 87 private File destDirectory; 88 89 90 private String classpath; 91 private String [] classpathElements; 92 93 94 private boolean retainSource = false; 95 private boolean debugOutput = false; 96 97 98 private File iasHomeDir; 99 100 101 private SAXParser parser; 102 private EjbcHandler handler = new EjbcHandler(); 103 104 111 private Hashtable ejbFiles = new Hashtable (); 112 113 114 private String displayName; 115 116 132 public IPlanetEjbc(File stdDescriptor, 133 File iasDescriptor, 134 File destDirectory, 135 String classpath, 136 SAXParser parser) { 137 this.stdDescriptor = stdDescriptor; 138 this.iasDescriptor = iasDescriptor; 139 this.destDirectory = destDirectory; 140 this.classpath = classpath; 141 this.parser = parser; 142 143 147 List elements = new ArrayList (); 148 if (classpath != null) { 149 StringTokenizer st = new StringTokenizer (classpath, 150 File.pathSeparator); 151 while (st.hasMoreTokens()) { 152 elements.add(st.nextToken()); 153 } 154 classpathElements 155 = (String []) elements.toArray(new String [elements.size()]); 156 } 157 } 158 159 167 public void setRetainSource(boolean retainSource) { 168 this.retainSource = retainSource; 169 } 170 171 177 public void setDebugOutput(boolean debugOutput) { 178 this.debugOutput = debugOutput; 179 } 180 181 190 public void registerDTD(String publicID, String location) { 191 handler.registerDTD(publicID, location); 192 } 193 194 201 public void setIasHomeDir(File iasHomeDir) { 202 this.iasHomeDir = iasHomeDir; 203 } 204 205 214 public Hashtable getEjbFiles() { 215 return ejbFiles; 216 } 217 218 223 public String getDisplayName() { 224 return displayName; 225 } 226 227 232 public String [] getCmpDescriptors() { 233 List returnList = new ArrayList (); 234 235 EjbInfo[] ejbs = handler.getEjbs(); 236 237 for (int i = 0; i < ejbs.length; i++) { 238 List descriptors = (List ) ejbs[i].getCmpDescriptors(); 239 returnList.addAll(descriptors); 240 } 241 242 return (String []) returnList.toArray(new String [returnList.size()]); 243 } 244 245 252 public static void main(String [] args) { 253 File stdDescriptor; 254 File iasDescriptor; 255 File destDirectory = null; 256 String classpath = null; 257 SAXParser parser = null; 258 boolean debug = false; 259 boolean retainSource = false; 260 IPlanetEjbc ejbc; 261 262 if ((args.length < MIN_NUM_ARGS) || (args.length > MAX_NUM_ARGS)) { 263 usage(); 264 return; 265 } 266 267 stdDescriptor = new File (args[args.length - 2]); 268 iasDescriptor = new File (args[args.length - 1]); 269 270 for (int i = 0; i < args.length - 2; i++) { 271 if (args[i].equals("-classpath")) { 272 classpath = args[++i]; 273 } else if (args[i].equals("-d")) { 274 destDirectory = new File (args[++i]); 275 } else if (args[i].equals("-debug")) { 276 debug = true; 277 } else if (args[i].equals("-keepsource")) { 278 retainSource = true; 279 } else { 280 usage(); 281 return; 282 } 283 } 284 285 286 if (classpath == null) { 287 Properties props = System.getProperties(); 288 classpath = props.getProperty("java.class.path"); 289 } 290 291 295 if (destDirectory == null) { 296 Properties props = System.getProperties(); 297 destDirectory = new File (props.getProperty("user.dir")); 298 } 299 300 301 SAXParserFactory parserFactory = SAXParserFactory.newInstance(); 302 parserFactory.setValidating(true); 303 try { 304 parser = parserFactory.newSAXParser(); 305 } catch (Exception e) { 306 System.out.println("An exception was generated while trying to "); 308 System.out.println("create a new SAXParser."); 309 e.printStackTrace(); 310 return; 311 } 312 313 314 ejbc = new IPlanetEjbc(stdDescriptor, iasDescriptor, destDirectory, 315 classpath, parser); 316 ejbc.setDebugOutput(debug); 317 ejbc.setRetainSource(retainSource); 318 319 320 try { 321 ejbc.execute(); 322 } catch (IOException e) { 323 System.out.println("An IOException has occurred while reading the " 324 + "XML descriptors (" + e.getMessage() + ")."); 325 return; 326 } catch (SAXException e) { 327 System.out.println("A SAXException has occurred while reading the " 328 + "XML descriptors (" + e.getMessage() + ")."); 329 return; 330 } catch (IPlanetEjbc.EjbcException e) { 331 System.out.println("An error has occurred while executing the ejbc " 332 + "utility (" + e.getMessage() + ")."); 333 return; 334 } 335 } 336 337 340 private static void usage() { 341 System.out.println("java org.apache.tools.ant.taskdefs.optional.ejb.IPlanetEjbc \\"); 342 System.out.println(" [OPTIONS] [EJB 1.1 descriptor] [iAS EJB descriptor]"); 343 System.out.println(""); 344 System.out.println("Where OPTIONS are:"); 345 System.out.println(" -debug -- for additional debugging output"); 346 System.out.println(" -keepsource -- to retain Java source files generated"); 347 System.out.println(" -classpath [classpath] -- classpath used for compilation"); 348 System.out.println(" -d [destination directory] -- directory for compiled classes"); 349 System.out.println(""); 350 System.out.println("If a classpath is not specified, the system classpath"); 351 System.out.println("will be used. If a destination directory is not specified,"); 352 System.out.println("the current working directory will be used (classes will"); 353 System.out.println("still be placed in subfolders which correspond to their"); 354 System.out.println("package name)."); 355 System.out.println(""); 356 System.out.println("The EJB home interface, remote interface, and implementation"); 357 System.out.println("class must be found in the destination directory. In"); 358 System.out.println("addition, the destination will look for the stubs and skeletons"); 359 System.out.println("in the destination directory to ensure they are up to date."); 360 } 361 362 374 public void execute() throws EjbcException, IOException , SAXException { 375 376 checkConfiguration(); 378 EjbInfo[] ejbs = getEjbs(); 380 for (int i = 0; i < ejbs.length; i++) { 381 log("EJBInfo..."); 382 log(ejbs[i].toString()); 383 } 384 385 for (int i = 0; i < ejbs.length; i++) { 386 EjbInfo ejb = ejbs[i]; 387 388 ejb.checkConfiguration(destDirectory); 390 if (ejb.mustBeRecompiled(destDirectory)) { 391 log(ejb.getName() + " must be recompiled using ejbc."); 392 393 String [] arguments = buildArgumentList(ejb); 394 callEjbc(arguments); 395 396 } else { 397 log(ejb.getName() + " is up to date."); 398 } 399 } 400 } 401 402 407 private void callEjbc(String [] arguments) { 408 409 410 StringBuffer args = new StringBuffer (); 411 for (int i = 0; i < arguments.length; i++) { 412 args.append(arguments[i]).append(" "); 413 } 414 415 416 String command; 417 if (iasHomeDir == null) { 418 command = ""; 419 } else { 420 command = iasHomeDir.toString() + File.separator + "bin" 421 + File.separator; 422 } 423 command += "ejbc "; 424 425 log(command + args); 426 427 432 try { 433 Process p = Runtime.getRuntime().exec(command + args); 434 RedirectOutput output = new RedirectOutput(p.getInputStream()); 435 RedirectOutput error = new RedirectOutput(p.getErrorStream()); 436 output.start(); 437 error.start(); 438 p.waitFor(); 439 p.destroy(); 440 } catch (IOException e) { 441 log("An IOException has occurred while trying to execute ejbc."); 442 e.printStackTrace(); 443 } catch (InterruptedException e) { 444 } 446 } 447 448 453 protected void checkConfiguration() throws EjbcException { 454 455 String msg = ""; 456 457 if (stdDescriptor == null) { 458 msg += "A standard XML descriptor file must be specified. "; 459 } 460 if (iasDescriptor == null) { 461 msg += "An iAS-specific XML descriptor file must be specified. "; 462 } 463 if (classpath == null) { 464 msg += "A classpath must be specified. "; 465 } 466 if (parser == null) { 467 msg += "An XML parser must be specified. "; 468 } 469 470 if (destDirectory == null) { 471 msg += "A destination directory must be specified. "; 472 } else if (!destDirectory.exists()) { 473 msg += "The destination directory specified does not exist. "; 474 } else if (!destDirectory.isDirectory()) { 475 msg += "The destination specified is not a directory. "; 476 } 477 478 if (msg.length() > 0) { 479 throw new EjbcException(msg); 480 } 481 } 482 483 494 private EjbInfo[] getEjbs() throws IOException , SAXException { 495 EjbInfo[] ejbs = null; 496 497 501 502 parser.parse(stdDescriptor, handler); 503 parser.parse(iasDescriptor, handler); 504 ejbs = handler.getEjbs(); 505 506 return ejbs; 507 } 508 509 517 private String [] buildArgumentList(EjbInfo ejb) { 518 519 List arguments = new ArrayList (); 520 521 522 523 if (debugOutput) { 524 arguments.add("-debug"); 525 } 526 527 528 if (ejb.getBeantype().equals(STATELESS_SESSION)) { 529 arguments.add("-sl"); 530 } else if (ejb.getBeantype().equals(STATEFUL_SESSION)) { 531 arguments.add("-sf"); 532 } 533 534 if (ejb.getIiop()) { 535 arguments.add("-iiop"); 536 } 537 538 if (ejb.getCmp()) { 539 arguments.add("-cmp"); 540 } 541 542 if (retainSource) { 543 arguments.add("-gs"); 544 } 545 546 if (ejb.getHasession()) { 547 arguments.add("-fo"); 548 } 549 550 551 552 arguments.add("-classpath"); 553 arguments.add(classpath); 554 555 arguments.add("-d"); 556 arguments.add(destDirectory.toString()); 557 558 arguments.add(ejb.getHome().getQualifiedClassName()); 559 arguments.add(ejb.getRemote().getQualifiedClassName()); 560 arguments.add(ejb.getImplementation().getQualifiedClassName()); 561 562 563 return (String []) arguments.toArray(new String [arguments.size()]); 564 } 565 566 572 private void log(String msg) { 573 if (debugOutput) { 574 System.out.println(msg); 575 } 576 } 577 578 579 580 581 582 587 public class EjbcException extends Exception { 588 589 594 public EjbcException(String msg) { 595 super(msg); 596 } 597 } 599 600 609 private class EjbcHandler extends HandlerBase { 610 611 private static final String PUBLICID_EJB11 = 612 "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"; 613 614 private static final String PUBLICID_IPLANET_EJB_60 = 615 "-//Sun Microsystems, Inc.//DTD iAS Enterprise JavaBeans 1.0//EN"; 616 617 private static final String DEFAULT_IAS60_EJB11_DTD_LOCATION = 618 "ejb-jar_1_1.dtd"; 619 620 private static final String DEFAULT_IAS60_DTD_LOCATION = 621 "IASEjb_jar_1_0.dtd"; 622 623 628 private Map resourceDtds = new HashMap (); 629 private Map fileDtds = new HashMap (); 630 631 private Map ejbs = new HashMap (); private EjbInfo currentEjb; private boolean iasDescriptor = false; 635 private String currentLoc = ""; private String currentText; private String ejbType; 639 644 public EjbcHandler() { 645 registerDTD(PUBLICID_EJB11, DEFAULT_IAS60_EJB11_DTD_LOCATION); 646 registerDTD(PUBLICID_IPLANET_EJB_60, DEFAULT_IAS60_DTD_LOCATION); 647 } 648 649 656 public EjbInfo[] getEjbs() { 657 return (EjbInfo[]) ejbs.values().toArray(new EjbInfo[ejbs.size()]); 658 } 659 660 666 public String getDisplayName() { 667 return displayName; 668 } 669 670 682 public void registerDTD(String publicID, String location) { 683 log("Registering: " + location); 684 if ((publicID == null) || (location == null)) { 685 return; 686 } 687 688 if (ClassLoader.getSystemResource(location) != null) { 689 log("Found resource: " + location); 690 resourceDtds.put(publicID, location); 691 } else { 692 File dtdFile = new File (location); 693 if (dtdFile.exists() && dtdFile.isFile()) { 694 log("Found file: " + location); 695 fileDtds.put(publicID, location); 696 } 697 } 698 } 699 700 710 public InputSource resolveEntity(String publicId, String systemId) 711 throws SAXException { 712 InputStream inputStream = null; 713 714 715 try { 716 717 718 719 String location = (String ) resourceDtds.get(publicId); 720 if (location != null) { 721 inputStream 722 = ClassLoader.getSystemResource(location).openStream(); 723 } else { 724 location = (String ) fileDtds.get(publicId); 725 if (location != null) { 726 inputStream = new FileInputStream (location); 727 } 728 } 729 } catch (IOException e) { 730 return super.resolveEntity(publicId, systemId); 731 } 732 733 if (inputStream == null) { 734 return super.resolveEntity(publicId, systemId); 735 } else { 736 return new InputSource (inputStream); 737 } 738 } 739 740 748 public void startElement(String name, AttributeList atts) 749 throws SAXException { 750 751 755 currentLoc += "\\" + name; 756 757 758 currentText = ""; 759 760 if (currentLoc.equals("\\ejb-jar")) { 761 iasDescriptor = false; 762 } else if (currentLoc.equals("\\ias-ejb-jar")) { 763 iasDescriptor = true; 764 } 765 766 if ((name.equals("session")) || (name.equals("entity"))) { 767 ejbType = name; 768 } 769 } 770 771 780 public void characters(char[] ch, int start, int len) 781 throws SAXException { 782 783 currentText += new String (ch).substring(start, start + len); 784 } 785 786 792 public void endElement(String name) throws SAXException { 793 794 800 if (iasDescriptor) { 801 iasCharacters(currentText); 802 } else { 803 stdCharacters(currentText); 804 } 805 806 810 811 int nameLength = name.length() + 1; int locLength = currentLoc.length(); 813 814 currentLoc = currentLoc.substring(0, locLength - nameLength); 815 } 816 817 825 private void stdCharacters(String value) { 826 827 if (currentLoc.equals("\\ejb-jar\\display-name")) { 828 displayName = value; 829 return; 830 } 831 832 String base = "\\ejb-jar\\enterprise-beans\\" + ejbType; 833 834 if (currentLoc.equals(base + "\\ejb-name")) { 835 currentEjb = (EjbInfo) ejbs.get(value); 836 if (currentEjb == null) { 837 currentEjb = new EjbInfo(value); 838 ejbs.put(value, currentEjb); 839 } 840 } else if (currentLoc.equals(base + "\\home")) { 841 currentEjb.setHome(value); 842 } else if (currentLoc.equals(base + "\\remote")) { 843 currentEjb.setRemote(value); 844 } else if (currentLoc.equals(base + "\\ejb-class")) { 845 currentEjb.setImplementation(value); 846 } else if (currentLoc.equals(base + "\\prim-key-class")) { 847 currentEjb.setPrimaryKey(value); 848 } else if (currentLoc.equals(base + "\\session-type")) { 849 currentEjb.setBeantype(value); 850 } else if (currentLoc.equals(base + "\\persistence-type")) { 851 currentEjb.setCmp(value); 852 } 853 } 854 855 865 private void iasCharacters(String value) { 866 String base = "\\ias-ejb-jar\\enterprise-beans\\" + ejbType; 867 868 if (currentLoc.equals(base + "\\ejb-name")) { 869 currentEjb = (EjbInfo) ejbs.get(value); 870 if (currentEjb == null) { 871 currentEjb = new EjbInfo(value); 872 ejbs.put(value, currentEjb); 873 } 874 } else if (currentLoc.equals(base + "\\iiop")) { 875 currentEjb.setIiop(value); 876 } else if (currentLoc.equals(base + "\\failover-required")) { 877 currentEjb.setHasession(value); 878 } else if (currentLoc.equals(base + "\\persistence-manager" 879 + "\\properties-file-location")) { 880 currentEjb.addCmpDescriptor(value); 881 } 882 } 883 } 885 886 890 private class EjbInfo { 891 private String name; private Classname home; private Classname remote; private Classname implementation; private Classname primaryKey; private String beantype = "entity"; private boolean cmp = false; private boolean iiop = false; private boolean hasession = false; private List cmpDescriptors = new ArrayList (); 902 907 public EjbInfo(String name) { 908 this.name = name; 909 } 910 911 918 public String getName() { 919 if (name == null) { 920 if (implementation == null) { 921 return "[unnamed]"; 922 } else { 923 return implementation.getClassName(); 924 } 925 } 926 return name; 927 } 928 929 936 937 public void setHome(String home) { 938 setHome(new Classname(home)); 939 } 940 941 public void setHome(Classname home) { 942 this.home = home; 943 } 944 945 public Classname getHome() { 946 return home; 947 } 948 949 public void setRemote(String remote) { 950 setRemote(new Classname(remote)); 951 } 952 953 public void setRemote(Classname remote) { 954 this.remote = remote; 955 } 956 957 public Classname getRemote() { 958 return remote; 959 } 960 961 public void setImplementation(String implementation) { 962 setImplementation(new Classname(implementation)); 963 } 964 965 public void setImplementation(Classname implementation) { 966 this.implementation = implementation; 967 } 968 969 public Classname getImplementation() { 970 return implementation; 971 } 972 973 public void setPrimaryKey(String primaryKey) { 974 setPrimaryKey(new Classname(primaryKey)); 975 } 976 977 public void setPrimaryKey(Classname primaryKey) { 978 this.primaryKey = primaryKey; 979 } 980 981 public Classname getPrimaryKey() { 982 return primaryKey; 983 } 984 985 public void setBeantype(String beantype) { 986 this.beantype = beantype.toLowerCase(); 987 } 988 989 public String getBeantype() { 990 return beantype; 991 } 992 993 public void setCmp(boolean cmp) { 994 this.cmp = cmp; 995 } 996 997 public void setCmp(String cmp) { 998 setCmp(cmp.equals("Container")); 999 } 1000 1001 public boolean getCmp() { 1002 return cmp; 1003 } 1004 1005 public void setIiop(boolean iiop) { 1006 this.iiop = iiop; 1007 } 1008 1009 public void setIiop(String iiop) { 1010 setIiop(iiop.equals("true")); 1011 } 1012 1013 public boolean getIiop() { 1014 return iiop; 1015 } 1016 1017 public void setHasession(boolean hasession) { 1018 this.hasession = hasession; 1019 } 1020 1021 public void setHasession(String hasession) { 1022 setHasession(hasession.equals("true")); 1023 } 1024 1025 public boolean getHasession() { 1026 return hasession; 1027 } 1028 1029 public void addCmpDescriptor(String descriptor) { 1030 cmpDescriptors.add(descriptor); 1031 } 1032 1033 public List getCmpDescriptors() { 1034 return cmpDescriptors; 1035 } 1036 1037 1046 private void checkConfiguration(File buildDir) throws EjbcException { 1047 1048 1049 if (home == null) { 1050 throw new EjbcException("A home interface was not found " 1051 + "for the " + name + " EJB."); 1052 } 1053 if (remote == null) { 1054 throw new EjbcException("A remote interface was not found " 1055 + "for the " + name + " EJB."); 1056 } 1057 if (implementation == null) { 1058 throw new EjbcException("An EJB implementation class was not " 1059 + "found for the " + name + " EJB."); 1060 } 1061 1062 if ((!beantype.equals(ENTITY_BEAN)) 1063 && (!beantype.equals(STATELESS_SESSION)) 1064 && (!beantype.equals(STATEFUL_SESSION))) { 1065 throw new EjbcException("The beantype found (" + beantype + ") " 1066 + "isn't valid in the " + name + " EJB."); 1067 } 1068 1069 if (cmp && (!beantype.equals(ENTITY_BEAN))) { 1070 System.out.println("CMP stubs and skeletons may not be generated" 1071 + " for a Session Bean -- the \"cmp\" attribute will be" 1072 + " ignoredfor the " + name + " EJB."); 1073 } 1074 1075 if (hasession && (!beantype.equals(STATEFUL_SESSION))) { 1076 System.out.println("Highly available stubs and skeletons may " 1077 + "only be generated for a Stateful Session Bean -- the " 1078 + "\"hasession\" attribute will be ignored for the " 1079 + name + " EJB."); 1080 } 1081 1082 1083 if (!remote.getClassFile(buildDir).exists()) { 1084 throw new EjbcException("The remote interface " 1085 + remote.getQualifiedClassName() + " could not be " 1086 + "found."); 1087 } 1088 if (!home.getClassFile(buildDir).exists()) { 1089 throw new EjbcException("The home interface " 1090 + home.getQualifiedClassName() + " could not be " 1091 + "found."); 1092 } 1093 if (!implementation.getClassFile(buildDir).exists()) { 1094 throw new EjbcException("The EJB implementation class " 1095 + implementation.getQualifiedClassName() + " could " 1096 + "not be found."); 1097 } 1098 } 1099 1100 1112 public boolean mustBeRecompiled(File destDir) { 1113 1114 long sourceModified = sourceClassesModified(destDir); 1115 1116 long destModified = destClassesModified(destDir); 1117 1118 return (destModified < sourceModified); 1119 } 1120 1121 1133 private long sourceClassesModified(File buildDir) { 1134 long latestModified; long modified; File remoteFile; File homeFile; File implFile; File pkFile; 1141 1142 remoteFile = remote.getClassFile(buildDir); 1143 modified = remoteFile.lastModified(); 1144 if (modified == -1) { 1145 System.out.println("The class " 1146 + remote.getQualifiedClassName() + " couldn't " 1147 + "be found on the classpath"); 1148 return -1; 1149 } 1150 latestModified = modified; 1151 1152 1153 homeFile = home.getClassFile(buildDir); 1154 modified = homeFile.lastModified(); 1155 if (modified == -1) { 1156 System.out.println("The class " 1157 + home.getQualifiedClassName() + " couldn't be " 1158 + "found on the classpath"); 1159 return -1; 1160 } 1161 latestModified = Math.max(latestModified, modified); 1162 1163 1164 if (primaryKey != null) { 1165 pkFile = primaryKey.getClassFile(buildDir); 1166 modified = pkFile.lastModified(); 1167 if (modified == -1) { 1168 System.out.println("The class " 1169 + primaryKey.getQualifiedClassName() + "couldn't be " 1170 + "found on the classpath"); 1171 return -1; 1172 } 1173 latestModified = Math.max(latestModified, modified); 1174 } else { 1175 pkFile = null; 1176 } 1177 1178 1187 implFile = implementation.getClassFile(buildDir); 1188 modified = implFile.lastModified(); 1189 if (modified == -1) { 1190 System.out.println("The class " 1191 + implementation.getQualifiedClassName() 1192 + " couldn't be found on the classpath"); 1193 return -1; 1194 } 1195 1196 String pathToFile = remote.getQualifiedClassName(); 1197 pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; 1198 ejbFiles.put(pathToFile, remoteFile); 1199 1200 pathToFile = home.getQualifiedClassName(); 1201 pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; 1202 ejbFiles.put(pathToFile, homeFile); 1203 1204 pathToFile = implementation.getQualifiedClassName(); 1205 pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; 1206 ejbFiles.put(pathToFile, implFile); 1207 1208 if (pkFile != null) { 1209 pathToFile = primaryKey.getQualifiedClassName(); 1210 pathToFile = pathToFile.replace('.', File.separatorChar) + ".class"; 1211 ejbFiles.put(pathToFile, pkFile); 1212 } 1213 1214 return latestModified; 1215 } 1216 1217 1231 private long destClassesModified(File destDir) { 1232 String [] classnames = classesToGenerate(); long destClassesModified = new Date ().getTime(); boolean allClassesFound = true; 1236 1240 for (int i = 0; i < classnames.length; i++) { 1241 1242 String pathToClass = 1243 classnames[i].replace('.', File.separatorChar) + ".class"; 1244 File classFile = new File (destDir, pathToClass); 1245 1246 1250 ejbFiles.put(pathToClass, classFile); 1251 1252 allClassesFound = allClassesFound && classFile.exists(); 1253 1254 if (allClassesFound) { 1255 long fileMod = classFile.lastModified(); 1256 1257 1258 destClassesModified = Math.min(destClassesModified, fileMod); 1259 } 1260 } 1261 1262 return (allClassesFound) ? destClassesModified : -1; 1263 } 1264 1265 1275 private String [] classesToGenerate() { 1276 String [] classnames = (iiop) 1277 ? new String [NUM_CLASSES_WITH_IIOP] 1278 : new String [NUM_CLASSES_WITHOUT_IIOP]; 1279 1280 final String remotePkg = remote.getPackageName() + "."; 1281 final String remoteClass = remote.getClassName(); 1282 final String homePkg = home.getPackageName() + "."; 1283 final String homeClass = home.getClassName(); 1284 final String implPkg = implementation.getPackageName() + "."; 1285 final String implFullClass = implementation.getQualifiedWithUnderscores(); 1286 int index = 0; 1287 1288 classnames[index++] = implPkg + "ejb_fac_" + implFullClass; 1289 classnames[index++] = implPkg + "ejb_home_" + implFullClass; 1290 classnames[index++] = implPkg + "ejb_skel_" + implFullClass; 1291 classnames[index++] = remotePkg + "ejb_kcp_skel_" + remoteClass; 1292 classnames[index++] = homePkg + "ejb_kcp_skel_" + homeClass; 1293 classnames[index++] = remotePkg + "ejb_kcp_stub_" + remoteClass; 1294 classnames[index++] = homePkg + "ejb_kcp_stub_" + homeClass; 1295 classnames[index++] = remotePkg + "ejb_stub_" + remoteClass; 1296 classnames[index++] = homePkg + "ejb_stub_" + homeClass; 1297 1298 if (!iiop) { 1299 return classnames; 1300 } 1301 1302 classnames[index++] = "org.omg.stub." + remotePkg + "_" 1303 + remoteClass + "_Stub"; 1304 classnames[index++] = "org.omg.stub." + homePkg + "_" 1305 + homeClass + "_Stub"; 1306 classnames[index++] = "org.omg.stub." + remotePkg 1307 + "_ejb_RmiCorbaBridge_" 1308 + remoteClass + "_Tie"; 1309 classnames[index++] = "org.omg.stub." + homePkg 1310 + "_ejb_RmiCorbaBridge_" 1311 + homeClass + "_Tie"; 1312 1313 classnames[index++] = remotePkg + "ejb_RmiCorbaBridge_" 1314 + remoteClass; 1315 classnames[index++] = homePkg + "ejb_RmiCorbaBridge_" + homeClass; 1316 1317 return classnames; 1318 } 1319 1320 1326 public String toString() { 1327 String s = "EJB name: " + name 1328 + "\n\r home: " + home 1329 + "\n\r remote: " + remote 1330 + "\n\r impl: " + implementation 1331 + "\n\r primaryKey: " + primaryKey 1332 + "\n\r beantype: " + beantype 1333 + "\n\r cmp: " + cmp 1334 + "\n\r iiop: " + iiop 1335 + "\n\r hasession: " + hasession; 1336 1337 Iterator i = cmpDescriptors.iterator(); 1338 while (i.hasNext()) { 1339 s += "\n\r CMP Descriptor: " + i.next(); 1340 } 1341 1342 return s; 1343 } 1344 1345 } 1347 1353 private static class Classname { 1354 private String qualifiedName; private String packageName; private String className; 1358 1365 public Classname(String qualifiedName) { 1366 if (qualifiedName == null) { 1367 return; 1368 } 1369 1370 this.qualifiedName = qualifiedName; 1371 1372 int index = qualifiedName.lastIndexOf('.'); 1373 if (index == -1) { 1374 className = qualifiedName; 1375 packageName = ""; 1376 } else { 1377 packageName = qualifiedName.substring(0, index); 1378 className = qualifiedName.substring(index + 1); 1379 } 1380 } 1381 1382 1387 public String getQualifiedClassName() { 1388 return qualifiedName; 1389 } 1390 1391 1396 public String getPackageName() { 1397 return packageName; 1398 } 1399 1400 1405 public String getClassName() { 1406 return className; 1407 } 1408 1409 1418 public String getQualifiedWithUnderscores() { 1419 return qualifiedName.replace('.', '_'); 1420 } 1421 1422 1430 public File getClassFile(File directory) { 1431 String pathToFile = qualifiedName.replace('.', File.separatorChar) 1432 + ".class"; 1433 return new File (directory, pathToFile); 1434 } 1435 1436 1442 public String toString() { 1443 return getQualifiedClassName(); 1444 } 1445 } 1447 1448 1454 private static class RedirectOutput extends Thread { 1455 1456 private InputStream stream; 1458 1465 public RedirectOutput(InputStream stream) { 1466 this.stream = stream; 1467 } 1468 1469 1473 public void run() { 1474 BufferedReader reader = new BufferedReader ( 1475 new InputStreamReader (stream)); 1476 String text; 1477 try { 1478 while ((text = reader.readLine()) != null) { 1479 System.out.println(text); 1480 } 1481 } catch (IOException e) { 1482 e.printStackTrace(); 1483 } finally { 1484 try { 1485 reader.close(); 1486 } catch (IOException e) { 1487 } 1489 } 1490 } 1491 } 1493} 1494 | Popular Tags |