1 5 package xdoclet.modules.ejb.home; 6 7 import java.text.MessageFormat ; 8 import java.util.*; 9 10 import org.apache.commons.logging.Log; 11 12 import xjavadoc.*; 13 14 import xdoclet.DocletContext; 15 import xdoclet.DocletTask; 16 import xdoclet.XDocletException; 17 import xdoclet.XDocletMessages; 18 import xdoclet.modules.ejb.EjbTagsHandler; 19 import xdoclet.modules.ejb.XDocletModulesEjbMessages; 20 import xdoclet.modules.ejb.entity.CmpTagsHandler; 21 import xdoclet.modules.ejb.entity.EntityTagsHandler; 22 import xdoclet.modules.ejb.entity.PkTagsHandler; 23 import xdoclet.modules.ejb.home.LocalHomeInterfaceSubTask; 24 import xdoclet.modules.ejb.intf.InterfaceTagsHandler; 25 import xdoclet.modules.ejb.session.SessionTagsHandler; 26 import xdoclet.util.DocletUtil; 27 import xdoclet.util.LogUtil; 28 import xdoclet.util.Translator; 29 import xdoclet.util.TypeConversionUtil; 30 31 37 public class HomeTagsHandler extends EjbTagsHandler 38 { 39 40 private String currentSignature; 41 42 private String currentExceptions; 43 44 private String currentPermission; 45 46 68 public static String getHomeInterface(String type, XClass clazz) throws XDocletException 69 { 70 Log log = LogUtil.getLog(HomeTagsHandler.class, "getHomeInterface"); 71 72 if (!"remote".equals(type) && !"local".equals(type)) { 74 throw new XDocletException(Translator.getString(XDocletModulesEjbMessages.class, XDocletModulesEjbMessages.METHOD_ONLY_TAKES_REMOTE_OR_LOCAL, new String []{"getHomeInterface", type})); 75 } 76 77 String fileName = clazz.getContainingPackage().getName(); 78 String name_pattern = null; 79 String package_pattern = null; 80 String home_interface = null; 81 82 home_interface = clazz.getDoc().getTagAttributeValue("ejb:home", type + "-class"); 83 if (log.isDebugEnabled()) { 84 log.debug(type + " home Interface for " + clazz.getQualifiedName() + " = " + home_interface); 85 } 86 87 if (home_interface != null) { 88 return home_interface; 89 } 90 91 name_pattern = clazz.getDoc().getTagAttributeValue("ejb:home", type + "-pattern"); 92 if (name_pattern == null) { 93 name_pattern = clazz.getDoc().getTagAttributeValue("ejb:home", "pattern"); 94 if (name_pattern == null) { 95 name_pattern = "remote".equals(type) ? getHomeClassPattern() : getLocalHomeClassPattern(); 96 } 97 } 98 99 package_pattern = clazz.getDoc().getTagAttributeValue("ejb:home", type + "-package"); 100 if (package_pattern == null) { 101 package_pattern = clazz.getDoc().getTagAttributeValue("ejb:home", "package"); 102 } 103 104 String ejb_name = null; 105 106 if (name_pattern.indexOf("{0}") != -1) { 107 ejb_name = MessageFormat.format(name_pattern, new Object []{getShortEjbNameFor(clazz)}); 108 } 109 else { 110 ejb_name = name_pattern; 111 } 112 113 String subtask_name = null; 114 115 if (type.equals("remote")) { 116 subtask_name = DocletTask.getSubTaskName(HomeInterfaceSubTask.class); 117 } 118 else { 119 subtask_name = DocletTask.getSubTaskName(LocalHomeInterfaceSubTask.class); 120 } 121 122 StringBuffer sb = new StringBuffer (choosePackage(fileName, package_pattern, subtask_name)); 124 125 if (sb.length() > 0) { 126 sb.append('.'); 127 } 128 sb.append(ejb_name); 129 130 return sb.toString(); 131 } 132 133 139 public static boolean isRemoveMethod(XMethod method) 140 { 141 return method.getName().equals("ejbRemove"); 142 } 143 144 150 public static boolean isCreateMethod(XMethod method) 151 { 152 return method.getDoc().hasTag("ejb.create-method"); 153 } 154 155 161 public static boolean isHomeMethod(XMethod method) 162 { 163 return method.getDoc().hasTag("ejb.home-method"); 164 } 165 166 173 public static String getCompNameFor(XClass clazz, String type) 174 { 175 String compName = getEjbNameFor(clazz).replace('.', '/'); 176 177 if (type.equals("local")) { 178 compName = compName + LOCAL_SUFFIX; 179 } 180 181 return compName; 182 } 183 184 190 public static boolean isFinderMethod(XMethod method) 191 { 192 return method.getName().startsWith("ejbFind"); 193 } 194 195 205 public static String getHomeDefinition(XClass clazz, XMethod method, String tagType, String type) 206 throws XDocletException 207 { 208 String methodName = method.getName().substring(3); 209 StringBuffer homeMethodName = new StringBuffer (); 210 211 if (tagType.equals("ejb:finder")) { 212 String ejbReturn = method.getReturnType().getType().getQualifiedName(); 213 214 if (ejbReturn.equals("java.util.Collection") || 215 ejbReturn.equals("java.util.Enumeration") || 216 ejbReturn.equals("java.util.Set")) { 217 homeMethodName.append(ejbReturn); 218 219 } 220 else { 221 homeMethodName.append(InterfaceTagsHandler.getComponentInterface(type, clazz)); 222 223 } 224 } 225 else if (tagType.equals("ejb:create-method")) { 226 homeMethodName.append(InterfaceTagsHandler.getComponentInterface(type, clazz)); 227 } 228 else if (tagType.equals("ejb:home-method")) { 229 methodName = methodName.substring(4); 230 homeMethodName.append(method.getReturnType().getType().getQualifiedName()); 231 } 232 homeMethodName.append(" "); 233 homeMethodName.append(methodName.substring(0, 1).toLowerCase()); 234 homeMethodName.append(methodName.substring(1)); 235 homeMethodName.append("("); 236 237 for (Iterator i = method.getParameters().iterator(); i.hasNext(); ) { 238 homeMethodName.append(i.next()); 239 if (i.hasNext()) 240 homeMethodName.append(" , "); 241 } 242 homeMethodName.append(")"); 243 return fullPackageChange(homeMethodName.toString()); 244 } 245 246 public static String getJndiNameOfTypeFor(String type, XClass clazz) 247 { 248 XTag bean_tag = clazz.getDoc().getTag("ejb:bean"); 249 String compName = getCompNameFor(clazz, type); 250 251 if (bean_tag != null) { 252 String jndiName = bean_tag.getAttributeValue("jndi-name"); 253 String localJndiName = bean_tag.getAttributeValue("local-jndi-name"); 254 255 if ("local".equals(type)) { 257 return localJndiName != null ? localJndiName : compName; 258 } 259 260 return jndiName != null ? jndiName : compName; 262 } 263 264 return compName; 266 } 267 268 274 public static String toHomeMethod(String methodName) 275 { 276 return Character.toLowerCase(methodName.charAt(7)) + methodName.substring(8); 278 } 279 280 286 public static String toCreateMethod(String methodName) 287 { 288 if (methodName.length() > 9) { 289 return "create" + Character.toUpperCase(methodName.charAt(9)) + methodName.substring(10); 291 } 292 else { 293 return "create"; 294 } 295 } 296 297 303 public static XMethod findFirstCreateMethodFor(XClass clazz) 304 { 305 Collection methods = clazz.getMethods(); 306 307 do { 308 for (Iterator j = methods.iterator(); j.hasNext(); ) { 309 XMethod method = (XMethod) j.next(); 310 311 if (HomeTagsHandler.isCreateMethod(method)) { 312 return method; 313 } 314 } 315 316 clazz = clazz.getSuperclass(); 317 } while (clazz != null); 318 319 return null; 320 } 321 322 328 public static String toFinderMethod(String methodName) 329 { 330 return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4); 332 } 333 334 340 public static String fullPackageChange(String s) 341 { 342 StringTokenizer st = new StringTokenizer(s, " "); 343 String sign = st.nextToken(); 344 StringBuffer ret = new StringBuffer (); 345 346 if (sign.equals("Collection")) { 347 ret.append("java.util.Collection"); 348 } 349 else if (sign.equals("Enumeration")) { 350 ret.append("java.util.Enumeration"); 351 } 352 else if (sign.equals("Set")) { 353 ret.append("java.util.Set"); 354 } 355 else { 356 ret.append(sign); 357 } 358 while (st.hasMoreTokens()) { 359 ret.append(" ").append(st.nextToken()); 360 } 361 return ret.toString(); 362 } 363 364 373 public static String finderSignatureFunger(String s, XClass clazz, String type) throws XDocletException 374 { 375 StringTokenizer st = new StringTokenizer(s, " "); 376 String sign = st.nextToken(); 377 StringBuffer ret = new StringBuffer (); 378 379 if (sign.equals("Collection") || sign.equals("java.util.Collection")) { 380 ret.append("java.util.Collection"); 381 } 382 else if (sign.equals("Enumeration") || sign.equals("java.util.Enumeration")) { 383 ret.append("java.util.Enumeration"); 384 } 385 else if (sign.equals("Set") || sign.equals("java.util.Set")) { 386 ret.append("java.util.Set"); 387 } 388 else { 389 ret.append(InterfaceTagsHandler.getComponentInterface(type, clazz)); 390 } 391 while (st.hasMoreTokens()) { 392 ret.append(" ").append(st.nextToken()); 393 } 394 return ret.toString(); 395 } 396 397 402 protected static String getLocalHomeClassPattern() 403 { 404 LocalHomeInterfaceSubTask localhomeintf_subtask = ((LocalHomeInterfaceSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(LocalHomeInterfaceSubTask.class))); 405 406 if (localhomeintf_subtask != null) { 407 return localhomeintf_subtask.getLocalHomeClassPattern(); 408 } 409 else { 410 return LocalHomeInterfaceSubTask.DEFAULT_LOCALHOMEINTERFACE_CLASS_PATTERN; 411 } 412 } 413 414 419 protected static String getHomeClassPattern() 420 { 421 HomeInterfaceSubTask homeintf_subtask = ((HomeInterfaceSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(HomeInterfaceSubTask.class))); 422 423 if (homeintf_subtask != null) { 424 return homeintf_subtask.getHomeClassPattern(); 425 } 426 else { 427 return HomeInterfaceSubTask.DEFAULT_HOMEINTERFACE_CLASS_PATTERN; 428 } 429 } 430 431 public void setCurrentPermission(String permission) 432 { 433 currentPermission = permission; 434 } 435 436 447 public String homeInterface(Properties attributes) throws XDocletException 448 { 449 String type = attributes.getProperty("type"); 450 451 type = type != null ? type : "remote"; 452 453 return getHomeInterface(type, getCurrentClass()); 454 } 455 456 468 public void ifIsCreateMethod(String template, Properties attributes) throws XDocletException 469 { 470 String superclasses_str = attributes.getProperty("superclasses"); 471 boolean superclasses = TypeConversionUtil.stringToBoolean(superclasses_str, true); 472 473 if (isCreateMethod(getCurrentMethod())) { 474 boolean currentMethodDoesntBelongToCurrentClass = !getCurrentMethod().getContainingClass().equals(getCurrentClass()); 475 boolean shouldTraverse = shouldTraverseSuperclassForDependentClass(getCurrentMethod().getContainingClass(), "ejb:home"); 476 477 if (superclasses == false && currentMethodDoesntBelongToCurrentClass == true && shouldTraverse == false) { 478 return; 479 } 480 481 generate(template); 482 } 483 } 484 485 493 public void ifDoesntHavePostCreateMethod(String template, Properties attributes) 494 throws XDocletException 495 { 496 XMethod currentMethod = getCurrentMethod(); 497 498 if (!isCreateMethod(currentMethod)) { 499 String msg = Translator.getString(XDocletModulesEjbMessages.class, 500 XDocletModulesEjbMessages.CURRENT_METHOD_NOT_CREATE, 501 new String []{currentMethod.toString()}); 502 503 throw new XDocletException(msg); 504 } 505 506 StringBuffer currentMethodName = new StringBuffer (currentMethod.getNameWithSignature(false)); 507 508 currentMethodName.insert(3, "Post"); 509 510 XMethod ejbPostCreateMethod = getCurrentClass().getMethod(currentMethodName.toString()); 511 512 if (ejbPostCreateMethod == null) { 513 generate(template); 514 } 515 } 516 517 524 public String ejbPostCreateSignature(Properties attributes) 525 { 526 StringBuffer currentMethodName = new StringBuffer (getCurrentMethod().getName()); 527 528 currentMethodName.insert(3, "Post"); 529 return currentMethodName.toString(); 530 } 531 532 543 public void ifIsHomeMethod(String template, Properties attributes) throws XDocletException 544 { 545 String superclasses_str = attributes.getProperty("superclasses"); 546 boolean superclasses = TypeConversionUtil.stringToBoolean(superclasses_str, true); 547 548 if (isHomeMethod(getCurrentMethod())) { 549 if (superclasses == false && getCurrentMethod().getContainingClass() != getCurrentClass() 550 && shouldTraverseSuperclassForDependentClass(getCurrentMethod().getContainingClass(), "ejb:home") == false) { 551 return; 552 } 553 554 generate(template); 555 } 556 } 557 558 566 public void ifNotRemoveMethod(String template) throws XDocletException 567 { 568 if (!isRemoveMethod(getCurrentMethod())) { 569 generate(template); 570 } 571 } 572 573 584 public void ifIsFinderMethod(String template, Properties attributes) throws XDocletException 585 { 586 String superclasses_str = attributes.getProperty("superclasses"); 587 boolean superclasses = TypeConversionUtil.stringToBoolean(superclasses_str, true); 588 589 if (isFinderMethod(getCurrentMethod())) { 590 boolean currentMethodDoesntBelongToCurrentClass = !getCurrentMethod().getContainingClass().equals(getCurrentClass()); 591 boolean shouldTraverse = shouldTraverseSuperclassForDependentClass(getCurrentMethod().getContainingClass(), "ejb:home"); 592 593 if (superclasses == false && currentMethodDoesntBelongToCurrentClass == true && shouldTraverse == false) { 594 return; 595 } 596 597 generate(template); 598 } 599 } 600 601 611 public String compName(Properties attributes) throws XDocletException 612 { 613 String prefix_with_ejbslash_str = attributes.getProperty("prefixWithEjbSlash"); 614 boolean prefix_with_ejbslash = TypeConversionUtil.stringToBoolean(prefix_with_ejbslash_str, false); 615 String type = attributes.getProperty("type"); 616 617 String ejb_name = getCompNameFor(getCurrentClass(), type); 618 619 String compName; 620 621 if (prefix_with_ejbslash == true) { 622 compName = prefixWithEjbSlash(ejb_name); 623 } 624 else { 625 compName = ejb_name; 626 } 627 628 return compName; 629 } 630 631 639 public String jndiName(Properties attributes) throws XDocletException 640 { 641 return getJndiNameOfTypeFor(attributes.getProperty("type"), getCurrentClass()); 642 } 643 644 652 public String extendsFrom(Properties attributes) throws XDocletException 653 { 654 String type = attributes.getProperty("type"); 655 656 type = type != null ? type : "remote"; 657 658 String extends_param_name = type.equals("remote") ? "extends" : "local-extends"; 659 String def_base_class_name = type.equals("remote") ? "javax.ejb.EJBHome" : "javax.ejb.EJBLocalHome"; 660 661 return extendsFromFor(getCurrentClass(), "ejb:home", type, extends_param_name, def_base_class_name); 662 } 663 664 678 public void forAllHomeMethods(String template, Properties attributes) throws XDocletException 679 { 680 Log log = LogUtil.getLog(HomeTagsHandler.class, "forAllHomeMethods"); 681 boolean superclasses = TypeConversionUtil.stringToBoolean(attributes.getProperty("superclasses"), false); 682 String type = attributes.getProperty("type"); 683 String tagType = attributes.getProperty("tagName"); 684 685 if (type == null) { 686 throw new XDocletException(Translator.getString(XDocletMessages.class, 687 XDocletMessages.ATTRIBUTE_NOT_PRESENT_ERROR, 688 new String []{"type"})); 689 } 690 691 Set already = new HashSet(); 692 XClass currentClass = getCurrentClass().getSuperclass(); 694 695 while (currentClass != null) { 696 if (log.isDebugEnabled()) { 697 log.debug("Looking for super definition in " + currentClass.getName()); 698 } 699 700 Collection methods = currentClass.getMethods(); 702 703 for (Iterator j = methods.iterator(); j.hasNext(); ) { 704 XMethod method = (XMethod) j.next(); 705 706 Collection tags = 710 method.getDoc().getTags(tagType, superclasses); 711 712 if (!matchesViewType(tags, type)) { 713 continue; 714 } 715 716 if (tagType.equals("ejb:finder")) { 717 if (!isFinderMethod(method)) { 718 continue; 719 } 720 } 721 else if (tagType.equals("ejb:create-method")) { 722 if (!isCreateMethod(method)) { 723 continue; 724 } 725 } 726 else if (tagType.equals("ejb:home-method")) { 727 if (!isHomeMethod(method)) { 728 continue; 729 } 730 } 731 732 String signature = getHomeDefinition(currentClass, method, tagType, type); 733 734 if (log.isDebugEnabled()) { 735 log.debug("Found " + signature); 736 } 737 already.add(signature); 738 } 739 740 Collection superTags = currentClass.getDoc().getTags(tagType, true); 742 743 for (Iterator i = superTags.iterator(); i.hasNext(); ) { 744 XTag superTag = (XTag) i.next(); 745 746 if (!matchesViewType(superTag, type)) { 750 continue; 751 } 752 753 String signature = fullPackageChange(superTag.getAttributeValue("signature")); 754 String typeMapping = superTag.getAttributeValue("result-type-mapping"); 755 756 if (typeMapping == null || typeMapping.equalsIgnoreCase(type)) { 757 if (log.isDebugEnabled()) { 758 log.debug("Found " + signature); 759 } 760 already.add(signature); 761 } 762 } 763 currentClass = currentClass.getSuperclass(); 764 } 765 766 Collection methods = getCurrentClass().getMethods(); 768 boolean fbpkFound = false; 769 770 for (Iterator j = methods.iterator(); j.hasNext(); ) { 771 XMethod method = (XMethod) j.next(); 772 773 Collection tags = 777 method.getDoc().getTags(tagType, superclasses); 778 779 if (!matchesViewType(tags, type)) { 780 continue; 781 } 782 783 String signature = null; 784 785 if (method.getDoc().getTag("ejb.permission") != null) { 786 setCurrentPermission("@ejb.permission " + method.getDoc().getTag("ejb.permission").getValue()); 787 } 788 789 if (log.isDebugEnabled()) { 790 log.debug("Finder Method = " + signature); 791 } 792 793 if (tagType.equals("ejb:finder")) { 794 if (!isFinderMethod(method)) { 795 continue; 796 } 797 signature = getHomeDefinition(getCurrentClass(), method, tagType, type); 798 799 if (!already.add(signature)) { 800 continue; 801 } 802 803 } 804 else if (tagType.equals("ejb:create-method")) { 805 if (!isCreateMethod(method)) { 806 continue; 807 } 808 signature = getHomeDefinition(getCurrentClass(), method, tagType, type); 809 810 if (!already.add(signature)) { 811 continue; 812 } 813 } 814 else if (tagType.equals("ejb:home-method")) { 815 if (!isHomeMethod(method)) { 816 continue; 817 } 818 signature = getHomeDefinition(getCurrentClass(), method, tagType, type); 819 820 if (!already.add(signature)) { 821 continue; 822 } 823 } 824 if (signature != null) { 825 setCurrentSignature(signature); 826 827 Collection exceptions = method.getThrownExceptions(); 828 StringBuffer exc = new StringBuffer (); 829 830 boolean comma = false; 831 832 for (Iterator k = exceptions.iterator(); k.hasNext(); ) { 833 XClass exception = (XClass) k.next(); 834 835 if (exception.getQualifiedName().equals("javax.ejb.EJBException")) 837 continue; 838 839 if (comma) { 840 exc.append(','); 841 } 842 exc.append(exception.getQualifiedName()); 843 comma = true; 844 } 845 if (tagType.equals("ejb:finder") && exc.indexOf("javax.ejb.FinderException") < 0) { 848 if (exc.length() > 0) { 849 exc.append(","); 850 } 851 exc.append("javax.ejb.FinderException"); 852 } 853 if (tagType.equals("ejb:create-method") && exc.indexOf("javax.ejb.CreateException") < 0) { 856 if (exc.length() > 0) { 857 exc.append(","); 858 } 859 exc.append("javax.ejb.CreateException"); 860 } 861 if (type.equalsIgnoreCase("remote")) { 864 if (exc.length() > 0) { 865 exc.append(","); 866 } 867 exc.append("java.rmi.RemoteException"); 868 } 869 setCurrentExceptions(exc.toString()); 870 setCurrentMethod(method); 872 873 if (method.getName().equals("findByPrimaryKey")) { 876 fbpkFound = true; 877 } 878 879 generate(template); 880 } 881 } 882 883 Collection tags = getCurrentClass().getDoc().getTags(tagType, superclasses); 885 886 for (Iterator i = tags.iterator(); i.hasNext(); ) { 887 XTag tag = (XTag) i.next(); 888 889 if (!matchesViewType(tag, type)) { 893 continue; 894 } 895 896 String signature = finderSignatureFunger(tag.getAttributeValue("signature"), getCurrentClass(), type); 897 String typeMapping = tag.getAttributeValue("result-type-mapping"); 898 899 if (typeMapping == null || typeMapping.equalsIgnoreCase(type)) { 900 if (!already.add(signature)) { 901 continue; 902 } 903 904 if (log.isDebugEnabled()) { 905 log.debug("Finder Method = " + signature); 906 } 907 908 if (signature.indexOf("findByPrimaryKey") != -1) { 909 fbpkFound = true; 910 } 911 912 setCurrentClassTag(tag); 913 setCurrentSignature(signature); 914 915 if (tag.getAttributeValue("unchecked") != null) { 916 setCurrentPermission("@ejb.permission unchecked=\"true\""); 917 } 918 else if (tag.getAttributeValue("role-name") != null) { 919 setCurrentPermission("@ejb.permission role-name=\"" + tag.getAttributeValue("role-name") + "\""); 920 } 921 else { 922 setCurrentPermission(""); 924 } 925 926 StringBuffer exc = new StringBuffer (); 927 928 exc.append("javax.ejb.FinderException"); 929 if (type.equalsIgnoreCase("remote")) { 930 exc.append(",java.rmi.RemoteException"); 931 } 932 setCurrentExceptions(exc.toString()); 933 934 generate(template); 935 } 936 } 937 938 if (!fbpkFound && CmpTagsHandler.isEntityCmp(getCurrentClass()) && tagType.equals("ejb:finder") && EntityTagsHandler.isAConcreteEJBean(getCurrentClass())) { 940 StringBuffer fbpkSign = new StringBuffer (InterfaceTagsHandler.getComponentInterface(type, getCurrentClass())); 941 942 fbpkSign.append(" findByPrimaryKey("); 943 fbpkSign.append(PkTagsHandler.getPkClassFor(getCurrentClass())).append(" pk").append(")"); 944 if (already.add(fbpkSign)) { 945 setCurrentSignature(fbpkSign.toString()); 946 947 StringBuffer exc = new StringBuffer (); 948 949 exc.append("javax.ejb.FinderException"); 950 if (type.equalsIgnoreCase("remote")) { 951 exc.append(",java.rmi.RemoteException"); 952 } 953 954 setCurrentExceptions(exc.toString()); 955 setCurrentMethod(null); 956 generate(template); 957 } 958 } 959 960 if (SessionTagsHandler.isSession(getCurrentClass()) && tagType.equals("ejb:create-method")) { 962 if (already.size() == 0 && SessionTagsHandler.isAConcreteEJBean(getCurrentClass())) { 963 StringBuffer createSign = new StringBuffer (InterfaceTagsHandler.getComponentInterface(type, getCurrentClass())); 964 965 createSign.append(" create()"); 966 setCurrentSignature(createSign.toString()); 967 968 StringBuffer exc = new StringBuffer (); 969 970 exc.append("javax.ejb.CreateException"); 971 if (type.equalsIgnoreCase("remote")) { 972 exc.append(",java.rmi.RemoteException"); 973 } 974 setCurrentExceptions(exc.toString()); 975 setCurrentMethod(null); 976 generate(template); 977 } 978 } 979 980 setCurrentClassTag(null); 981 setCurrentMethodTag(null); 982 setCurrentSignature(null); 983 setCurrentExceptions(null); 984 setCurrentMethod(null); 985 986 } 987 988 994 public String currentSignature() throws XDocletException 995 { 996 return currentSignature; 997 } 998 999 1006 public String currentPermission() throws XDocletException 1007 { 1008 return currentPermission; 1009 } 1010 1011 1019 public String currentType() throws XDocletException 1020 { 1021 String sig = currentSignature(); 1022 1023 int index = sig.indexOf(" "); 1024 1025 if (index >= 0) { 1026 return sig.substring(0, index); 1027 } 1028 throw new XDocletException("can not parse signature: " + sig); 1029 } 1030 1031 1039 public String finderClass() throws XDocletException 1040 { 1041 String sig = currentSignature(); 1042 int start = sig.indexOf("find"); 1043 int end = sig.indexOf("("); 1044 1045 if (start >= 0 && end > start) { 1046 return sig.substring(start, start + 1).toUpperCase() + sig.substring(start + 1, end); 1047 } 1048 throw new XDocletException("Cannot parse signature: " + sig); 1049 } 1050 1051 1059 public void ifIsCollectionType(String template, Properties param) throws XDocletException 1060 { 1061 String currentType = currentType(); 1062 1063 if ("Collection".equals(currentType) || 1064 "java.util.Collection".equals(currentType) || 1065 "Set".equals(currentType) || 1066 "java.util.Set".equals(currentType)) { 1067 generate(template); 1068 } 1069 } 1070 1071 1079 public void ifIsEnumerationType(String template, Properties param) throws XDocletException 1080 { 1081 String currentType = currentType(); 1082 1083 if ("Enumeration".equals(currentType) || "java.util.Enumeration".equals(currentType)) { 1084 generate(template); 1085 } 1086 } 1087 1088 1096 public void ifIsInterfaceType(String template, Properties param) throws XDocletException 1097 { 1098 1099 String type = currentType(); 1100 1101 if (type.equals(InterfaceTagsHandler.getComponentInterface("local", getCurrentClass())) || 1102 type.equals(InterfaceTagsHandler.getComponentInterface("remote", getCurrentClass()))) { 1103 generate(template); 1104 } 1105 } 1106 1107 1115 public String currentMethod() throws XDocletException 1116 { 1117 String sig = currentSignature(); 1118 int start = sig.indexOf(" "); 1119 int stop = sig.indexOf("("); 1120 1121 if (start < 0 || stop < 0) { 1122 throw new XDocletException("Cannot parse signature: " + sig); 1123 } 1124 return sig.substring(start + 1, stop); 1125 } 1126 1127 1135 public String parameterListDefinition() throws XDocletException 1136 { 1137 String sig = currentSignature(); 1138 int start = sig.indexOf("("); 1139 int stop = sig.indexOf(")"); 1140 1141 if (start < 0 || stop < 0) { 1142 throw new XDocletException("Cannot parse signature: " + sig); 1143 } 1144 return sig.substring(start + 1, stop); 1145 } 1146 1147 1154 public String parameterList() throws XDocletException 1155 { 1156 1157 String [] parameters = DocletUtil.tokenizeDelimitedToArray(parameterListDefinition(), " ,"); 1158 StringBuffer sb = new StringBuffer (); 1159 1160 for (int i = 1; i < parameters.length; i += 2) { 1161 if (i > 1) { 1162 sb.append(", "); 1163 } 1164 sb.append(parameters[i]); 1165 } 1166 return sb.toString(); 1167 } 1168 1169 1176 public String currentExceptions() throws XDocletException 1177 { 1178 return currentExceptions; 1179 } 1180 1181 1189 protected String getDependentClassFor(XClass clazz, String type) throws XDocletException 1190 { 1191 if ((type.equals("local") && InterfaceTagsHandler.isLocalEjb(clazz)) || (type.equals("remote") && InterfaceTagsHandler.isRemoteEjb(clazz))) { 1192 return getHomeInterface(type, clazz); 1193 } 1194 else { 1195 return null; 1196 } 1197 } 1198 1199 1204 protected void setCurrentSignature(String cs) 1205 { 1206 this.currentSignature = cs; 1207 } 1208 1209 1214 protected void setCurrentExceptions(String es) 1215 { 1216 this.currentExceptions = es; 1217 } 1218 1219 1227 protected boolean shouldTraverseSuperclassForDependentClass(XClass clazz, String tag_name) throws XDocletException 1228 { 1229 if (super.shouldTraverseSuperclassForDependentClass(clazz, tag_name) == false) { 1230 return false; 1231 } 1232 1233 if (isAConcreteEJBean(clazz)) { 1235 return false; 1236 } 1237 1238 return true; 1239 } 1240 1241 1249 protected boolean matchesViewType(XTag tag, String type) 1250 { 1251 String attr = tag.getAttributeValue("view-type"); 1252 1253 return attr == null || attr.length() == 0 || attr.equals(type) || attr.equals("both"); 1254 } 1255 1256 1265 protected boolean matchesViewType(Collection tags, String type) 1266 { 1267 boolean matches = true; 1270 1271 for (Iterator k = tags.iterator(); k.hasNext() && matches; ) { 1272 matches = matchesViewType((XTag) k.next(), type); 1273 } 1274 return matches; 1275 } 1276} 1277 | Popular Tags |