1 23 package com.sun.enterprise.tools.verifier.tests.ejb; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.reflect.*; 27 import java.util.*; 28 import com.sun.enterprise.deployment.EjbDescriptor; 29 import com.sun.enterprise.deployment.MethodDescriptor; 30 import com.sun.enterprise.tools.verifier.*; 31 import java.lang.ClassLoader ; 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 39 public class RmiIIOPUtils { 40 41 42 43 109 public static boolean isValidRmiIIOPInterface(Class RMIIIOPinterface) { 110 111 boolean validInterface = false; 114 Class c = RMIIIOPinterface; 115 do { 117 if (RMIIIOPinterface.getName().equals("java.rmi.Remote")) { 118 validInterface = true; 119 break; 120 } else { 121 Class [] interfaces = RMIIIOPinterface.getInterfaces(); 124 for (int i = 0; i < interfaces.length; i++) { 126 127 if ((interfaces[i].getName().equals("java.rmi.Remote")) || 129 (interfaces[i].getName().equals("javax.ejb.EJBObject")) || 132 (interfaces[i].getName().equals("javax.ejb.EJBHome"))) { 133 validInterface = true; 134 break; 135 } 136 else if (isValidRmiIIOPInterface(interfaces[i])) { 137 return true; 138 } 139 } 140 } 141 } while ((((RMIIIOPinterface=RMIIIOPinterface.getSuperclass()) != null) && (!validInterface))); 142 143 if (validInterface) { 144 return true; 145 } else { 146 return false; 147 } 148 } 149 150 151 152 153 154 161 public static boolean isValidRmiIIOPInterfaceMethods(Class RMIIIOPinterface) { 162 163 Class c = RMIIIOPinterface; 164 166 try { 171 Method methods[] = c.getDeclaredMethods(); 172 Class [] methodExceptionTypes; 173 for (int i=0; i< methods.length; i++) { 174 methodExceptionTypes = methods[i].getExceptionTypes(); 178 if (!EjbUtils.isValidRemoteException(methodExceptionTypes)) { 179 return false; 180 } else { 181 continue; 182 } 183 } 184 185 188 194 for (int i=0; i < methods.length; i++) { 198 methodExceptionTypes = methods[i].getExceptionTypes(); 199 if (!isValidRmiIIOPException(methodExceptionTypes)) { 200 return false; 201 } else { 202 continue; 203 } 204 } 205 206 215 219 Field fields[] = c.getFields(); 220 for (int i=0; i< fields.length; i++) { 221 if (!(isValidRmiIIOPField(fields[i]))) { 224 return false; 225 } else { 226 continue; 227 } 228 } 229 230 } catch (Throwable t) { 236 Verifier.debug(t); 237 return false; 238 } 239 return true; 240 } 241 242 300 public static boolean isValidRmiIIOPParameters(Class [] RMIIIOPparams) { 301 if (RMIIIOPparams.length > 0) { 302 for (int ii = 0; ii < RMIIIOPparams.length; ii++) { 303 Class c = RMIIIOPparams[ii]; 304 305 if (!(isValidRmiIDLPrimitiveType(c)) && 309 !(isValidRmiIIOPValueType(c)) && 310 !(isValidRmiIIOPInterfaceType(c)) && 311 !(isJavaLangStringType(c)) && 312 !(isValidRmiIIOPException(RMIIIOPparams)) && 313 !(c.getName().equals("java.lang.Object")) && 314 !(isValidRmiIIOPCORBAObjectType(c)) && 315 !(isValidRmiIIOPIDLEntityType(c))) { 316 return false; 318 } 319 } 320 return true; 323 } else { 324 return true; 325 } 326 } 327 328 329 339 public static boolean isValidRmiIIOPCORBAObjectType(Class RMIIIOPvaluetype) { 340 341 Class c = RMIIIOPvaluetype; 342 boolean validInterface = false; 343 344 do { 345 Class [] interfaces = c.getInterfaces(); 346 for (int i = 0; i < interfaces.length; i++) { 347 if (interfaces[i].getName().equals("org.omg.CORBA.Object")) { 348 validInterface = true; 349 break; 350 } else { 351 Class superClass = interfaces[i]; 354 do { 355 if (superClass.getName().equals("org.omg.CORBA.Object")) { 356 validInterface = true; 357 break; 358 } 359 } while ((((superClass=superClass.getSuperclass()) != null) && (!validInterface))); 360 } 361 } 362 } while ((((c=c.getSuperclass()) != null) && (!validInterface))); 363 if (!validInterface) { 364 return false; 365 } else { 366 return true; 367 } 368 } 369 370 380 public static boolean isValidRmiIIOPIDLEntityType(Class RMIIIOPvaluetype) { 381 382 Class c = RMIIIOPvaluetype; 383 boolean validInterface = false; 384 385 do { 386 Class [] interfaces = c.getInterfaces(); 387 for (int i = 0; i < interfaces.length; i++) { 388 if (interfaces[i].getName().equals("org.omg.CORBA.portable.IDLEntity")) { 389 validInterface = true; 390 break; 391 } else { 392 Class superClass = interfaces[i]; 395 do { 396 if (superClass.getName().equals("org.omg.CORBA.portable.IDLEntity")) { 397 validInterface = true; 398 break; 399 } 400 } while ((((superClass=superClass.getSuperclass()) != null) && (!validInterface))); 401 } 402 } 403 } while ((((c=c.getSuperclass()) != null) && (!validInterface))); 404 if (!validInterface) { 405 return false; 406 } else { 407 return true; 408 } 409 } 410 411 422 public static boolean isValidRmiIIOPValueType(Class RMIIIOPvaluetype) { 423 424 Class c = RMIIIOPvaluetype; 425 boolean validInterface = false; 426 boolean badOne = false; 427 if (c.getName().equals("java.lang.Object")) { 433 return true; 435 } 436 457 validInterface = java.io.Serializable .class.isAssignableFrom(c); 458 459 if (validInterface == false) { 460 return false; 461 } else { 462 466 467 471 485 486 badOne = java.rmi.Remote .class.isAssignableFrom(c); 487 488 if (badOne) { 489 return false; 490 } 491 492 495 500 507 } 508 if (validInterface) { 509 return true; 510 } else { 511 return false; 512 } 513 } 514 515 516 533 public static boolean isValidRmiIIOPField(Field RMIIIOPField) { 534 boolean validPrimitiveType = false; 535 if ((isValidRmiIDLPrimitiveType(RMIIIOPField)) || 536 (RMIIIOPField.getType().equals(java.lang.String .class))) { 537 validPrimitiveType = true; 538 } 539 return validPrimitiveType; 540 } 541 542 543 544 562 public static boolean isValidRmiIDLPrimitiveType(Field RMIIIOPField) { 563 boolean validPrimitiveType = false; 564 if ((RMIIIOPField.getType().getName().equals("void")) || 565 (RMIIIOPField.getType().getName().equals("boolean")) || 566 (RMIIIOPField.getType().getName().equals("byte")) || 567 (RMIIIOPField.getType().getName().equals("char")) || 568 (RMIIIOPField.getType().getName().equals("short")) || 569 (RMIIIOPField.getType().getName().equals("int")) || 570 (RMIIIOPField.getType().getName().equals("long")) || 571 (RMIIIOPField.getType().getName().equals("float")) || 572 (RMIIIOPField.getType().getName().equals("double"))) { 573 validPrimitiveType = true; 574 } 575 return validPrimitiveType; 576 } 577 578 579 593 private static boolean isValidRmiIIOPInterfaceType(Class interfaceClass) { 594 if (interfaceClass.isInterface()) { 595 return true; 596 } else { 597 return false; 598 } 599 } 600 601 602 615 public static boolean isValidRmiIDLPrimitiveType(Class primitiveClass) { 616 boolean validPrimitiveType = false; 617 if ((primitiveClass.getName().equals("void")) || 618 (primitiveClass.getName().equals("boolean")) || 619 (primitiveClass.getName().equals("byte")) || 620 (primitiveClass.getName().equals("char")) || 621 (primitiveClass.getName().equals("short")) || 622 (primitiveClass.getName().equals("int")) || 623 (primitiveClass.getName().equals("long")) || 624 (primitiveClass.getName().equals("float")) || 625 (primitiveClass.getName().equals("double"))) { 626 validPrimitiveType = true; 627 } 628 return validPrimitiveType; 629 } 630 631 632 646 public static boolean isJavaLangStringType(Class jlsClass) { 647 boolean validJlsType = false; 648 if (jlsClass.getName().equals("java.lang.String")) { 649 validJlsType = true; 650 } 651 return validJlsType; 652 } 653 654 677 public static boolean isValidRmiIIOPException(Class [] RMIIIOPexceptions) { 678 boolean throwsRemoteException = false; 680 for (int kk = 0; kk < RMIIIOPexceptions.length; ++kk) { 681 if ((RMIIIOPexceptions[kk].getName().equals("java.rmi.RemoteException")) || 682 (RMIIIOPexceptions[kk].getName().equals("RemoteException"))) { 683 throwsRemoteException = true; 684 break; 685 } 686 } 687 return throwsRemoteException; 688 } 689 690 702 public static boolean isValidRmiIIOPReturnType(Class RMIIIOPReturnType) { 703 if (!((isValidRmiIDLPrimitiveType(RMIIIOPReturnType)) || 707 (isValidRmiIIOPValueType(RMIIIOPReturnType)) || 708 (isValidRmiIIOPInterfaceType(RMIIIOPReturnType)) || 709 (isJavaLangStringType(RMIIIOPReturnType)) || 710 (isValidRmiIIOPCORBAObjectType(RMIIIOPReturnType)) || 712 (RMIIIOPReturnType.getName().equals("java.lang.Object")) || 713 (isValidRmiIIOPIDLEntityType(RMIIIOPReturnType)))) { 714 return false; 715 } else { 716 return true; 717 } 718 } 719 720 721 732 public static boolean isValidSerializableType(Class c) { 733 734 return java.io.Serializable .class.isAssignableFrom(c); 735 736 773 } 774 775 776 799 public static boolean isPersistentFieldTypeValid(Class CmpField, String HomeClass, String RemoteClass) { 800 if (!((isValidRmiIDLPrimitiveType(CmpField)) || 803 (isValidSerializableType(CmpField)) || 804 (CmpField.getName().equals(HomeClass)) || 805 (CmpField.getName().equals(RemoteClass)))) { 806 return false; 807 } else { 808 return true; 809 } 810 811 } 812 813 814 848 public static boolean isEjbFindMethodExceptionsSubsetOfFindMethodExceptions 849 (Class [] ejbFindExceptions, Class [] findExceptions) { 850 boolean oneFailed = false; 851 if (Arrays.equals(ejbFindExceptions,findExceptions)) { 852 return true; 853 } else { 854 List ejbFindList = Arrays.asList(ejbFindExceptions); 856 List findList = Arrays.asList(findExceptions); 857 if (!ejbFindList.isEmpty()) { 858 for (Iterator itr = ejbFindList.iterator(); itr.hasNext();) { 859 Class nextEjbFindMethodException = (Class ) itr.next(); 860 if (findList.contains(nextEjbFindMethodException)) { 861 continue; 862 } else { 863 if (isSuperClassofClass("java.lang.RuntimeException", 872 nextEjbFindMethodException)) { 873 continue; 876 } else { 877 oneFailed = true; 881 break; 885 } 886 } 887 } 888 889 if (oneFailed) { 891 return false; 892 } else { 893 return true; 898 } 899 } else { 900 return true; 902 } 903 } 904 } 905 906 907 917 private static boolean isSuperClassofClass(String superClass, Class fromClass) { 918 boolean validSuperClass = false; 919 Class c = fromClass; 920 do { 922 if (c.getName().equals(superClass)) { 923 validSuperClass = true; 924 break; 925 } 926 } while ((((c=c.getSuperclass()) != null) && (!validSuperClass))); 927 928 if (!validSuperClass){ 929 return false; 930 } else { 931 return true; 932 } 933 934 935 936 } 937 938 939 } 940 | Popular Tags |