1 23 package com.sun.enterprise.deployment; 24 25 import java.lang.reflect.Method ; 26 import java.util.*; 27 import com.sun.enterprise.util.LocalStringManagerImpl; 28 import com.sun.enterprise.util.TypeUtil; 29 import java.util.logging.*; 30 import com.sun.enterprise.deployment.util.LogDomains; 31 32 36 37 public class MethodDescriptor extends Descriptor { 38 39 public static String EJB_HOME = "Home"; 40 41 public static String EJB_LOCALHOME = "LocalHome"; 42 43 public static String EJB_REMOTE = "Remote"; 44 45 public static String EJB_LOCAL = "Local"; 46 47 public static String EJB_WEB_SERVICE = "ServiceEndpoint"; 48 49 public static String EJB_BEAN = "Bean"; 50 51 public static String ALL_OF_NAME = "AllOfName"; 52 53 public static String ALL_EJB_METHODS = "*"; 54 public static String ALL_METHODS = "*"; 55 56 private String [] parameterClassNames = null; 57 private String [] javaParameterClassNames = null; 58 private String className = ""; private String ejbClassSymbol; 60 private String ejbName; 61 private static LocalStringManagerImpl localStrings = 62 new LocalStringManagerImpl(MethodDescriptor.class); 63 64 static Logger _logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 65 66 private int JAVA_FORMAT = 1; 67 private int XML_FORMAT = -1; 68 private int XML_JAVA_FORMAT = 0; 69 private boolean isExact = false; 70 71 76 public MethodDescriptor(String name, String description, String [] parameterClassNames, String ejbClassSymbol) { 77 super(name, description); 78 if (name == null) { 79 super.setName(""); 80 } 81 if (parameterClassNames != null) 82 convertToAppropriateFormat (parameterClassNames); 83 this.setEjbClassSymbol(ejbClassSymbol); 84 } 85 86 private void convertToAppropriateFormat (String [] parameterClassNames){ 88 int format = isJavaFormat (parameterClassNames); 89 if (format == JAVA_FORMAT) { 91 this.javaParameterClassNames = parameterClassNames; 92 this.parameterClassNames = 93 fixParamClassNames (parameterClassNames); 94 } else if (format == XML_FORMAT) { this.javaParameterClassNames = 96 xmlFormat2JavaClassNames (parameterClassNames); 97 this.parameterClassNames = parameterClassNames; 98 } else if (format == XML_JAVA_FORMAT){ 99 this.javaParameterClassNames = parameterClassNames; 101 this.parameterClassNames = parameterClassNames; 102 } 103 } 104 107 108 public MethodDescriptor(String name, String description, String ejbClassSymbol) { 109 super(name, description); 110 this.parameterClassNames = null; 111 this.setEjbClassSymbol(ejbClassSymbol); 112 } 113 114 116 public MethodDescriptor(Method method, String methodIntf) { 117 this(method); 118 isExact=true; 119 this.setEjbClassSymbol(methodIntf); 120 } 121 122 124 public MethodDescriptor(Method method) { 125 super(method.getName(), ""); 126 Class methodClass = method.getClass(); 127 Method [] methods = methodClass.getMethods(); 128 this.parameterClassNames = getParameterClassNamesFor(method); 129 this.javaParameterClassNames = getJavaFormatClassNamesFor(method); 130 this.className = method.getDeclaringClass().getName(); 131 } 132 133 public MethodDescriptor() { 134 } 135 136 public void addParameterClass(String parameter) { 138 if (parameterClassNames==null) { 139 parameterClassNames = new String [1]; 140 } else { 141 String [] newParameterClassNames = new String [parameterClassNames.length + 1]; 142 for (int i=0;i<parameterClassNames.length;i++) { 143 newParameterClassNames[i] = parameterClassNames[i]; 144 } 145 parameterClassNames = newParameterClassNames; 146 } 147 parameterClassNames[parameterClassNames.length-1]=parameter; 148 javaParameterClassNames = xmlFormat2JavaClassNames (parameterClassNames); 149 } 150 151 public void setEjbName(String ejbName) { 152 this.ejbName = ejbName; 153 } 154 155 public String getEjbName() { 156 return ejbName; 157 } 158 159 160 163 public boolean isExact() { 164 if (isExact) { 165 return true; 166 } 167 boolean isExactName = !this.getName().equals(ALL_EJB_METHODS); 168 boolean hasMethodIntf = getEjbClassSymbol()!=null; 169 boolean hasParamsListed = (this.getParameterClassNames() != null); 170 return isExactName && hasMethodIntf && hasParamsListed; 171 } 172 173 179 public int getStyle() { 180 if (getName().equals(ALL_EJB_METHODS)) 181 return 1; 182 if (getParameterClassNames()==null) 183 return 2; 184 return 3; 185 } 186 187 public Method getMethod(EjbDescriptor ejbDescriptor) { 188 Method method = null; 189 try { 190 ClassLoader classloader = ejbDescriptor.getEjbBundleDescriptor().getClassLoader(); 191 String [] javaParamClassNames = getJavaParameterClassNames(); 192 193 if ( ejbClassSymbol == null || ejbClassSymbol.equals("") 194 || ejbClassSymbol.equals(EJB_BEAN) ) { 195 try { 196 if ( !(className.equals("")) ) { 197 Class declaringClass =classloader.loadClass(className); 202 return TypeUtil.getDeclaredMethod 203 (declaringClass, classloader, getName(), 204 javaParamClassNames); 205 } else { 206 Class ejbClass = classloader.loadClass 209 (ejbDescriptor.getEjbClassName()); 210 return TypeUtil.getMethod(ejbClass, classloader, 211 getName(), javaParamClassNames); 212 } 213 } catch(NoSuchMethodException nsme) {} 214 try { 215 if( ejbDescriptor.isRemoteInterfacesSupported() ) { 216 Class homeClass = classloader.loadClass 217 (ejbDescriptor.getHomeClassName()); 218 return TypeUtil.getMethod(homeClass, classloader, 219 getName(), javaParamClassNames); 220 } 221 } catch(NoSuchMethodException nsme) {} 222 try { 223 if( ejbDescriptor.isLocalInterfacesSupported() ) { 224 Class cl = classloader.loadClass 225 (ejbDescriptor.getLocalHomeClassName()); 226 return TypeUtil.getMethod(cl, classloader, 227 getName(), javaParamClassNames); 228 } 229 } catch(NoSuchMethodException nsme) {} 230 try { 231 if( ejbDescriptor.hasWebServiceEndpointInterface() ) { 232 Class cl = classloader.loadClass 233 (ejbDescriptor.getWebServiceEndpointInterfaceName()); 234 return TypeUtil.getMethod(cl, classloader, 235 getName(), javaParamClassNames); 236 } 237 } catch(NoSuchMethodException nsme) {} 238 } 239 else if ( ejbClassSymbol.equals(EJB_HOME) ) { 240 try { 241 Class homeClass = 242 classloader.loadClass(ejbDescriptor.getHomeClassName()); 243 method = TypeUtil.getMethod(homeClass, classloader, 244 getName(), javaParamClassNames); 245 } catch(NoSuchMethodException nsme) {} 246 } 247 else if ( ejbClassSymbol.equals(EJB_LOCALHOME) ) { 248 try { 249 Class cl = classloader.loadClass( 250 ejbDescriptor.getLocalHomeClassName()); 251 method = TypeUtil.getMethod(cl, classloader, 252 getName(), javaParamClassNames); 253 } catch(NoSuchMethodException nsme) {} 254 } 255 else if ( ejbClassSymbol.equals(EJB_REMOTE) ) { 256 if( ejbDescriptor.isRemoteInterfacesSupported() ) { 257 try { 258 Class cl = classloader.loadClass( 259 ejbDescriptor.getRemoteClassName()); 260 method = TypeUtil.getMethod(cl, classloader, 261 getName(), javaParamClassNames); 262 } catch(NoSuchMethodException nsme) {} 263 } 264 if( (method == null) && 265 ejbDescriptor.isRemoteBusinessInterfacesSupported() ) { 266 267 for(String intf : 268 ejbDescriptor.getRemoteBusinessClassNames() ) { 269 try { 270 Class cl = classloader.loadClass(intf); 271 method = TypeUtil.getMethod(cl, classloader, 272 getName(), javaParamClassNames); 273 } catch(NoSuchMethodException nsme) {} 274 275 if( method != null ) { 276 break; 277 } 278 } 279 } 280 } 281 else if ( ejbClassSymbol.equals(EJB_LOCAL) ) { 282 if( ejbDescriptor.isLocalInterfacesSupported() ) { 283 try { 284 Class cl = classloader.loadClass( 285 ejbDescriptor.getLocalClassName()); 286 method = TypeUtil.getMethod(cl, classloader, 287 getName(), javaParamClassNames); 288 } catch(NoSuchMethodException nsme) {} 289 } 290 if( (method == null) && 291 ejbDescriptor.isLocalBusinessInterfacesSupported() ) { 292 293 for(String intf : 294 ejbDescriptor.getLocalBusinessClassNames() ) { 295 try { 296 Class cl = classloader.loadClass(intf); 297 method = TypeUtil.getMethod(cl, classloader, 298 getName(), javaParamClassNames); 299 } catch(NoSuchMethodException nsme) {} 300 301 if( method != null ) { 302 break; 303 } 304 } 305 } 306 } 307 else if ( ejbClassSymbol.equals(EJB_WEB_SERVICE) ) { 308 try { 309 Class cl = classloader.loadClass 310 (ejbDescriptor.getWebServiceEndpointInterfaceName()); 311 method = TypeUtil.getMethod(cl, classloader, 312 getName(), javaParamClassNames); 313 } catch(NoSuchMethodException nsme) {} 314 } 315 } catch(Exception e) { 316 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object []{ejbDescriptor}); 317 } 318 return method; 319 } 320 321 322 public Method getMethod(Class declaringClass) 323 { 324 try { 325 return TypeUtil.getMethod(declaringClass, 326 declaringClass.getClassLoader(), 327 getName(), getJavaParameterClassNames()); 328 } catch(Exception e) { 329 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object []{declaringClass}); 330 return null; 331 } 332 } 333 334 public Method getDeclaredMethod(Class declaringClass) 335 { 336 try { 337 return TypeUtil.getDeclaredMethod(declaringClass, 338 declaringClass.getClassLoader(), 339 getName(), getJavaParameterClassNames()); 340 } catch(Exception e) { 341 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object []{declaringClass}); 342 return null; 343 } 344 } 345 346 350 public Vector doStyleConversion(EjbDescriptor ejbDescriptor, Collection allMethods) { Vector v = new Vector(); 352 if (this.getName().equals(ALL_EJB_METHODS)) { for (Iterator itr = allMethods.iterator(); itr.hasNext();) { 354 MethodDescriptor next = (MethodDescriptor) itr.next(); 355 if (this.getEjbName() != null 358 && this.getEjbName().length() > 0) { 359 next.setEjbName(ejbDescriptor.getName()); 360 } 361 if (!next.isExact()) { 362 } 364 if (this.getDescription() != null 365 && this.getDescription().length() > 0) { 366 next.setDescription(this.getDescription()); 367 } 368 if (getEjbClassSymbol()==null) { 369 v.addElement(next); 370 } else if (this.getEjbClassSymbol().equals(next.getEjbClassSymbol())) { 371 v.addElement(next); 372 } 373 374 } 375 } else if (this.getParameterClassNames() == null) { v.addAll(this.getMethodDescriptorsOfName(this.getName(), allMethods)); 377 } else { if (getEjbClassSymbol()==null) { 379 v.addAll(this.getMethodDescriptorsOfNameAndParameters(this.getName(), this.getParameterClassNames(), allMethods)); 380 } else { 381 v.addElement(this); } 383 } 384 return v; 385 } 386 387 private Set getMethodDescriptorsOfNameAndParameters(String name, String [] parameterArray, Collection methodDescriptors) { 388 Set methods = new HashSet(); 389 for (Iterator itr = getMethodDescriptorsOfName(name, methodDescriptors).iterator(); itr.hasNext();) { 390 MethodDescriptor next = (MethodDescriptor) itr.next(); 391 next.setEjbName(getEjbName()); 392 if (stringArrayEquals(parameterArray, next.getParameterClassNames())) { 393 methods.add(next); 394 } 395 } 396 return methods; 397 } 398 399 private Set getMethodDescriptorsOfName(String name, Collection methodDescriptors) { 400 Set set = new HashSet(); 401 for (Iterator itr = methodDescriptors.iterator(); itr.hasNext();) { 402 MethodDescriptor next = (MethodDescriptor) itr.next(); 403 next.setEjbName(getEjbName()); 404 if (name.equals(next.getName())) { 405 if (getEjbClassSymbol()==null) { 406 set.add(next); 407 } else if (getEjbClassSymbol().equals(next.getEjbClassSymbol())) { 408 set.add(next); 409 } 410 } 411 } 412 return set; 413 } 414 415 416 public String getEjbClassSymbol() { 417 return this.ejbClassSymbol; 418 } 419 420 public void setEjbClassSymbol(String ejbClassSymbol) { 421 this.ejbClassSymbol = ejbClassSymbol; 422 } 423 424 425 private void processEjbSymbol(Method method, EjbDescriptor ejbDescriptor, ClassLoader classloader) { 426 try { 427 Class bean, declaringClass = null; 428 String declaringClassname = method.getDeclaringClass().getName(); 429 430 431 ClassLoader cl = (classloader != null) ? classloader : 432 ejbDescriptor.getEjbBundleDescriptor().getClassLoader(); 433 bean = cl.loadClass(ejbDescriptor.getEjbClassName()); 434 declaringClass = classloader.loadClass(declaringClassname); 435 436 if( ejbDescriptor.getType().equals(EjbMessageBeanDescriptor.TYPE) ) { 438 if (declaringClass.isAssignableFrom(bean)) { 439 this.ejbClassSymbol = EJB_BEAN; 440 } 441 else { 442 _logger.log(Level.FINE,"declaring class = " + declaringClass); 443 _logger.log(Level.FINE,"method = " + this); 444 _logger.log(Level.FINE,"bean class = " + bean); 445 throw new IllegalArgumentException (); 446 } 447 } 448 else { 449 boolean foundremote = ejbDescriptor.isRemoteInterfacesSupported(); 450 if ( ejbDescriptor.isRemoteInterfacesSupported() ) { 451 Class home = cl.loadClass(ejbDescriptor.getHomeClassName()); 452 Class remote = cl.loadClass(ejbDescriptor.getRemoteClassName()); 453 if (declaringClass.isAssignableFrom(home)) { 454 this.ejbClassSymbol = EJB_HOME; 455 } else if (declaringClass.isAssignableFrom(remote)) { 456 this.ejbClassSymbol = EJB_REMOTE; 457 } else if (declaringClass.isAssignableFrom(bean)) { 458 this.ejbClassSymbol = EJB_BEAN; 459 } 460 else { 461 foundremote = false; 462 } 463 } 464 465 boolean foundremotebusiness = 466 ejbDescriptor.isRemoteBusinessInterfacesSupported(); 467 if( ejbDescriptor.isRemoteBusinessInterfacesSupported() ) { 468 469 boolean match = false; 470 for( String intfName : 471 ejbDescriptor.getRemoteBusinessClassNames()) { 472 473 Class intf = cl.loadClass(intfName); 474 475 if( declaringClass.isAssignableFrom(intf) ) { 476 this.ejbClassSymbol = EJB_REMOTE; 477 match = true; 478 break; 479 } else if( declaringClass.isAssignableFrom(bean) ) { 480 this.ejbClassSymbol = EJB_BEAN; 481 match = true; 482 break; 483 } 484 } 485 foundremotebusiness = match; 486 } 487 488 489 boolean foundlocal = ejbDescriptor.isLocalInterfacesSupported(); 490 if ( !foundremote && !foundremotebusiness && 491 ejbDescriptor.isLocalInterfacesSupported() ) { 492 Class localhome = cl.loadClass(ejbDescriptor.getLocalHomeClassName()); 493 Class local = cl.loadClass(ejbDescriptor.getLocalClassName()); 494 if (declaringClass.isAssignableFrom(localhome)) { 495 this.ejbClassSymbol = EJB_LOCALHOME; 496 } else if (declaringClass.isAssignableFrom(local)) { 497 this.ejbClassSymbol = EJB_LOCAL; 498 } else if (declaringClass.isAssignableFrom(bean)) { 499 this.ejbClassSymbol = EJB_BEAN; 500 } 501 else { 502 foundlocal = false; 503 } 504 } 505 506 boolean foundlocalbusiness = 507 ejbDescriptor.isLocalBusinessInterfacesSupported(); 508 if( ejbDescriptor.isLocalBusinessInterfacesSupported() ) { 509 510 boolean match = false; 511 for( String intfName : 512 ejbDescriptor.getLocalBusinessClassNames()) { 513 514 Class intf = cl.loadClass(intfName); 515 516 if( declaringClass.isAssignableFrom(intf) ) { 517 this.ejbClassSymbol = EJB_LOCAL; 518 match = true; 519 break; 520 } else if( declaringClass.isAssignableFrom(bean) ) { 521 this.ejbClassSymbol = EJB_BEAN; 522 match = true; 523 break; 524 } 525 } 526 foundlocalbusiness = match; 527 } 528 529 530 boolean foundwebservice = 531 ejbDescriptor.hasWebServiceEndpointInterface(); 532 533 if ( !foundremote && !foundremotebusiness && !foundlocal && 534 !foundlocalbusiness && 535 ejbDescriptor.hasWebServiceEndpointInterface() ) { 536 Class webServiceClass = classloader.loadClass 537 (ejbDescriptor.getWebServiceEndpointInterfaceName()); 538 if (declaringClass.isAssignableFrom(webServiceClass)) { 539 this.ejbClassSymbol = EJB_WEB_SERVICE; 540 } else if (declaringClass.isAssignableFrom(bean)) { 541 this.ejbClassSymbol = EJB_BEAN; 542 } else { 543 foundwebservice = false; 544 } 545 } 546 if ( !foundlocal && !foundlocalbusiness && !foundremote && 547 !foundremotebusiness && !foundwebservice) { 548 _logger.log(Level.FINE,"method class = " + declaringClass); 549 _logger.log(Level.FINE,"bean class = " + bean); 550 throw new IllegalArgumentException ("Method is not on any EJB interface"); 551 } 552 } 553 } catch (Throwable t) { 554 if (_logger.isLoggable(Level.SEVERE)) { 555 _logger.log(Level.SEVERE,"enterprise.deployment.backend.methodClassLoadFailure",new Object [] {method}); 556 } 557 558 throw new IllegalArgumentException (localStrings.getLocalString( 559 "enterprise.deployment.exceptionmethodnotfound", 560 "{0} not found in {1}", new Object [] {method,ejbDescriptor})); 561 } 562 ejbName=ejbDescriptor.getName(); 563 } 564 565 public String getFormattedString() { 566 return this.getName() + this.getPrettyParameterString(); 567 } 568 569 public String getPrettyParameterString() { 570 String prettyParameterString = "("; 571 if (this.parameterClassNames != null) { 572 for (int i = 0; i < this.parameterClassNames.length; i++) { 573 int j = i + 1; 574 if (i > 0) { 575 prettyParameterString = prettyParameterString + ", " + this.parameterClassNames[i] + " p" + j; 576 } else { 577 prettyParameterString = prettyParameterString + this.parameterClassNames[i] + " p" + j; 578 } 579 } 580 } 581 prettyParameterString = prettyParameterString + ")"; 582 return prettyParameterString; 583 } 584 585 public String [] getParameterClassNames() { 586 return parameterClassNames; 587 } 588 public String [] getJavaParameterClassNames (){ 589 return javaParameterClassNames; 590 } 591 private boolean stringArrayEquals(String [] s1, String [] s2) { 592 if (s1 == null && s2 == null) { 593 return true; 594 } 595 if (s1 == null && s2 != null) { 596 return false; 597 } 598 if (s2 == null && s1 != null) { 599 return false; 600 } 601 if (s1.length == s2.length) { 602 for (int i = 0; i < s1.length; i++) { 603 if (!s1[i].equals(s2[i])) { 604 return false; 605 } 606 } 607 return true; 608 } else { 609 return false; 610 } 611 } 612 613 614 public boolean equals(Object other) { 615 if (other != null && other instanceof MethodDescriptor) { 616 MethodDescriptor otherMethodDescriptor = (MethodDescriptor) other; 617 if (otherMethodDescriptor.getName().equals(getName()) 618 && stringArrayEquals(otherMethodDescriptor.getParameterClassNames(), getParameterClassNames())) { 619 if (getEjbClassSymbol()!=null && otherMethodDescriptor.getEjbClassSymbol()!=null) { 620 return getEjbClassSymbol().equals(otherMethodDescriptor.getEjbClassSymbol()); 621 } 622 return true; 625 } 626 } 627 return false; 628 } 629 630 631 public boolean implies(Object other) { 632 if (other != null && other instanceof MethodDescriptor) { 633 MethodDescriptor otherMethodDescriptor = (MethodDescriptor) other; 634 if (getName().equals(ALL_METHODS) || 635 getName().equals(otherMethodDescriptor.getName())) { 636 if (getParameterClassNames() == null || 637 stringArrayEquals(getParameterClassNames(), 638 otherMethodDescriptor.getParameterClassNames())) { 639 return true; 640 } 641 } 642 } 643 return false; 644 } 645 646 647 648 public int hashCode() { 649 return this.getPrettyParameterString().hashCode() + this.getName().hashCode(); 650 } 651 652 public void print(StringBuffer toStringBuffer) { 653 toStringBuffer.append("Method Descriptor").append((ejbName==null?"":" for ejb " + ejbName)).append( 654 " name: ").append(this.getName()).append(" params: ").append(this.getPrettyParameterString()).append( 655 " intf: ").append(this.ejbClassSymbol); 656 } 657 658 public String prettyPrint() { 659 return "Name : " + this.getName() + " Params: " + this.getPrettyParameterString() + " Intf: " + this.ejbClassSymbol; 660 } 661 662 663 public String [] getParameterClassNamesFor(Method method) { 664 Class [] classes = method.getParameterTypes(); 665 if (classes.length==0) 666 return null; 667 String [] classNames = new String [classes.length]; 668 for (int i = 0; i < classes.length; i++) { 669 Class compType = classes[i].getComponentType(); 670 if ( compType == null ) { classNames[i] = classes[i].getName(); 672 } 673 else { 674 int dimensions = 1; 677 while(compType.getComponentType()!=null) { 678 dimensions++; 679 compType=compType.getComponentType(); 680 } 681 682 classNames[i] = compType.getName(); 683 for (int j=0;j<dimensions;j++) { 685 classNames[i] += "[]"; 686 } 687 } 688 } 689 return classNames; 690 } 691 692 private int isJavaFormat (String [] params){ 693 int ret = XML_JAVA_FORMAT; 694 for (int i=0; i<params.length; i++){ 695 int index = params[i].indexOf ('['); 696 if (index == -1) { 697 ret = XML_JAVA_FORMAT; 699 continue; 700 } else if (index == 0) { return JAVA_FORMAT; 702 } else { return XML_FORMAT; 704 } 705 } 706 return ret; 707 } 708 709 private String [] getJavaFormatClassNamesFor(Method method){ 710 Class [] classes = method.getParameterTypes(); 711 String [] classNames = new String [classes.length]; 712 for (int i = 0; i < classes.length; i++) { 713 classNames[i] = classes[i].getName(); 714 } 715 return classNames; 716 } 717 718 private String [] fixParamClassNames(String [] paramClassNames) 719 { 720 if(paramClassNames == null) { 721 return null; 722 } 723 724 String [] newParams = new String [paramClassNames.length]; 725 726 for ( int i=0; i<paramClassNames.length; i++ ) { 729 newParams[i] = fixParamClassName(paramClassNames[i]); 730 731 } 732 733 return newParams; 734 } 735 private String [] xmlFormat2JavaClassNames (String [] from) { 736 String [] to = new String [from.length]; 737 for (int i=0; i<from.length; i++) { 738 to[i] = new String (xmlFormat2JavaClassNames (from[i])); 739 } 740 return to; 741 } 742 743 public static String xmlFormat2JavaClassNames (String param){ 745 int indexOfArray = param.indexOf ('['); 746 if (indexOfArray == -1) { return param; 748 } 749 String buf = param.substring (0, indexOfArray); 750 int lastIndexOf = param.lastIndexOf (']'); 751 int dimension = lastIndexOf - indexOfArray + 1; 752 dimension = dimension / 2; 753 StringBuffer fs = new StringBuffer (); 754 for (int i=0; i<dimension; i++) { 755 fs.append ("["); 756 } 757 String javaPrimitiveType = (String ) getJavaPrimitiveTypes().get(buf); 758 if (javaPrimitiveType!=null) { 759 fs.append(javaPrimitiveType); 760 } else { fs.append ("L"); 762 fs.append (buf); 763 fs.append (";"); 764 } 765 return fs.toString (); 766 } 767 768 774 public static Map getJavaPrimitiveTypes() { 775 if (javaPrimitivesTypes==null) { 776 javaPrimitivesTypes = new Hashtable(); 777 javaPrimitivesTypes.put("char", "C"); 778 javaPrimitivesTypes.put("byte", "B"); 779 javaPrimitivesTypes.put("double", "D"); 780 javaPrimitivesTypes.put("float", "F"); 781 javaPrimitivesTypes.put("int", "I"); 782 javaPrimitivesTypes.put("long", "J"); 783 javaPrimitivesTypes.put("short", "S"); 784 javaPrimitivesTypes.put("boolean", "Z"); 785 } 786 return javaPrimitivesTypes; 787 } 788 789 private static Map javaPrimitivesTypes; 790 791 public static String fixParamClassName(String param) 793 { 794 if ( param.charAt(0) == '[' ) { int dimensions = param.lastIndexOf('[') + 1; 796 char code = param.charAt(dimensions); 797 String newparam=null; 798 switch (code) { 799 case 'B': 800 newparam = "byte"; 801 case 'C': 802 newparam = "char"; 803 case 'D': 804 newparam = "double"; 805 case 'F': 806 newparam = "float"; 807 case 'I': 808 newparam = "int"; 809 case 'J': 810 newparam = "long"; 811 case 'S': 812 newparam = "short"; 813 case 'Z': 814 newparam = "boolean"; 815 case 'L': 816 newparam = param.substring(dimensions+1); 817 } 818 for ( int j=0; j<dimensions; j++ ) 819 newparam += "[]"; 820 return newparam; 821 } 822 else { 823 return param; 824 } 825 } 826 827 } 828 | Popular Tags |