1 55 package org.jboss.axis.description; 56 57 import org.jboss.axis.AxisServiceConfig; 58 import org.jboss.axis.Constants; 59 import org.jboss.axis.InternalException; 60 import org.jboss.axis.encoding.DefaultTypeMappingImpl; 61 import org.jboss.axis.encoding.TypeMapping; 62 import org.jboss.axis.encoding.TypeMappingRegistry; 63 import org.jboss.axis.encoding.TypeMappingRegistryImpl; 64 import org.jboss.axis.enums.Style; 65 import org.jboss.axis.enums.Use; 66 import org.jboss.axis.message.SOAPBodyElementAxisImpl; 67 import org.jboss.axis.message.SOAPEnvelopeAxisImpl; 68 import org.jboss.axis.utils.JavaUtils; 69 import org.jboss.axis.utils.Messages; 70 import org.jboss.axis.utils.bytecode.ParamNameExtractor; 71 import org.jboss.axis.wsdl.Skeleton; 72 import org.jboss.axis.wsdl.fromJava.Namespaces; 73 import org.jboss.logging.Logger; 74 import org.w3c.dom.Document ; 75 import org.w3c.dom.Element ; 76 77 import javax.xml.namespace.QName ; 78 import javax.xml.rpc.holders.Holder ; 79 import javax.xml.rpc.server.ServiceLifecycle ; 80 import java.lang.reflect.InvocationTargetException ; 81 import java.lang.reflect.Method ; 82 import java.lang.reflect.Modifier ; 83 import java.util.ArrayList ; 84 import java.util.Collection ; 85 import java.util.Collections ; 86 import java.util.Comparator ; 87 import java.util.HashMap ; 88 import java.util.Iterator ; 89 import java.util.List ; 90 import java.util.StringTokenizer ; 91 92 93 102 public class ServiceDesc 103 { 104 105 private static Logger log = Logger.getLogger(ServiceDesc.class.getName()); 106 107 110 private String name = null; 111 112 113 116 private List allowedMethods = null; 117 118 121 private List disallowedMethods = null; 122 123 126 private Style style = Style.RPC; 127 private Use use = Use.ENCODED; 128 129 private boolean useSet = false; 133 134 137 private Class implClass = null; 138 139 142 private ArrayList operations = new ArrayList (); 143 144 147 private List namespaceMappings = null; 148 149 155 private String wsdlFileName = null; 156 157 162 private String endpointURL = null; 163 164 167 private HashMap properties = null; 168 169 173 private boolean isSkeletonClass = false; 174 175 178 private Method skelMethod = null; 179 180 184 private ArrayList stopClasses = null; 185 186 189 private HashMap name2OperationsMap = null; 190 private HashMap qname2OperationsMap = null; 191 private HashMap method2OperationMap = new HashMap (); 192 private HashMap method2ParamsMap = new HashMap (); 193 private OperationDesc messageServiceDefaultOp = null; 194 195 198 private ArrayList completedNames = new ArrayList (); 199 200 203 private TypeMapping tm = DefaultTypeMappingImpl.getSingleton(); 204 205 private TypeMappingRegistry tmr = null; 206 207 private boolean haveAllSkeletonMethods = false; 208 private boolean introspectionComplete = false; 209 210 213 public ServiceDesc() 214 { 215 } 216 217 222 public Style getStyle() 223 { 224 return style; 225 } 226 227 public void setStyle(Style style) 228 { 229 this.style = style; 230 if (!useSet) 231 { 232 use = style == Style.RPC ? Use.ENCODED : Use.LITERAL; 234 } 235 } 236 237 242 public Use getUse() 243 { 244 return use; 245 } 246 247 public void setUse(Use use) 248 { 249 useSet = true; 250 this.use = use; 251 } 252 253 262 public boolean isWrapped() 263 { 264 return ((style == Style.RPC) || 265 (style == Style.WRAPPED)); 266 } 267 268 274 public String getWSDLFile() 275 { 276 return wsdlFileName; 277 } 278 279 286 public void setWSDLFile(String wsdlFileName) 287 { 288 this.wsdlFileName = wsdlFileName; 289 } 290 291 public List getAllowedMethods() 292 { 293 return allowedMethods; 294 } 295 296 public void setAllowedMethods(List allowedMethods) 297 { 298 this.allowedMethods = allowedMethods; 299 } 300 301 public Class getImplClass() 302 { 303 return implClass; 304 } 305 306 316 public void setImplClass(Class implClass) 317 { 318 if (this.implClass != null) 319 throw new IllegalArgumentException (Messages.getMessage("implAlreadySet")); 320 321 this.implClass = implClass; 322 if (Skeleton.class.isAssignableFrom(implClass)) 323 { 324 isSkeletonClass = true; 325 loadSkeletonOperations(); 326 } 327 } 328 329 private void loadSkeletonOperations() 330 { 331 Method method = null; 332 try 333 { 334 method = implClass.getDeclaredMethod("getOperationDescs", 335 new Class []{}); 336 } 337 catch (NoSuchMethodException e) 338 { 339 } 340 catch (SecurityException e) 341 { 342 } 343 if (method == null) 344 { 345 return; 347 } 348 349 try 350 { 351 Collection opers = (Collection )method.invoke(implClass, null); 352 for (Iterator i = opers.iterator(); i.hasNext();) 353 { 354 OperationDesc skelDesc = (OperationDesc)i.next(); 355 addOperationDesc(skelDesc); 356 } 357 } 358 catch (IllegalAccessException e) 359 { 360 return; 361 } 362 catch (IllegalArgumentException e) 363 { 364 return; 365 } 366 catch (InvocationTargetException e) 367 { 368 return; 369 } 370 haveAllSkeletonMethods = true; 371 } 372 373 public TypeMapping getTypeMapping() 374 { 375 return tm; 376 } 377 378 public void setTypeMapping(TypeMapping tm) 379 { 380 this.tm = tm; 381 } 382 383 386 public String getName() 387 { 388 return name; 389 } 390 391 396 public void setName(String name) 397 { 398 this.name = name; 399 } 400 401 public ArrayList getStopClasses() 402 { 403 return stopClasses; 404 } 405 406 public void setStopClasses(ArrayList stopClasses) 407 { 408 this.stopClasses = stopClasses; 409 } 410 411 public List getDisallowedMethods() 412 { 413 return disallowedMethods; 414 } 415 416 public void setDisallowedMethods(List disallowedMethods) 417 { 418 this.disallowedMethods = disallowedMethods; 419 } 420 421 public void addOperationDesc(OperationDesc operation) 422 { 423 operations.add(operation); 424 operation.setParent(this); 425 if (name2OperationsMap == null) 426 { 427 name2OperationsMap = new HashMap (); 428 } 429 430 String name = operation.getName(); 432 ArrayList overloads = (ArrayList )name2OperationsMap.get(name); 433 if (overloads == null) 434 { 435 overloads = new ArrayList (); 436 name2OperationsMap.put(name, overloads); 437 } 438 overloads.add(operation); 439 } 440 441 448 public ArrayList getOperations() 449 { 450 loadServiceDescByIntrospection(); return operations; 452 } 453 454 460 public OperationDesc[] getOperationsByName(String methodName) 461 { 462 getSyncedOperationsForName(implClass, methodName); 463 464 if (name2OperationsMap == null) 465 return null; 466 467 ArrayList overloads = (ArrayList )name2OperationsMap.get(methodName); 468 if (overloads == null) 469 { 470 return null; 471 } 472 473 OperationDesc[] array = new OperationDesc[overloads.size()]; 474 return (OperationDesc[])overloads.toArray(array); 475 } 476 477 483 public OperationDesc getOperationByName(String methodName) 484 { 485 getSyncedOperationsForName(implClass, methodName); 489 490 if (name2OperationsMap == null) 491 return null; 492 493 ArrayList overloads = (ArrayList )name2OperationsMap.get(methodName); 494 if (overloads == null) 495 { 496 return null; 497 } 498 499 return (OperationDesc)overloads.get(0); 500 } 501 502 508 public OperationDesc getOperationByElementQName(QName qname) 509 { 510 OperationDesc[] overloads = getOperationsByQName(qname); 511 512 if ((overloads != null) && overloads.length > 0) 514 return overloads[0]; 515 516 return null; 517 } 518 519 525 public OperationDesc[] getOperationsByQName(QName qname) 526 { 527 529 initQNameMap(); 531 532 ArrayList overloads = (ArrayList )qname2OperationsMap.get(qname); 533 534 if (overloads == null) 535 { 536 if ((isWrapped() || 538 ((style == Style.MESSAGE) && 539 (getDefaultNamespace() == null))) && 540 (name2OperationsMap != null)) 541 { 542 overloads = (ArrayList )name2OperationsMap.get(qname.getLocalPart()); 544 } 545 546 if ((style == Style.MESSAGE) && (messageServiceDefaultOp != null)) 549 return new OperationDesc[]{messageServiceDefaultOp}; 550 551 if (overloads == null) 552 return null; 553 } 554 555 getSyncedOperationsForName(implClass, 556 ((OperationDesc)overloads.get(0)).getName()); 557 558 Collections.sort(overloads, 563 new Comparator () 564 { 565 public int compare(Object o1, Object o2) 566 { 567 Method meth1 = ((OperationDesc)o1).getMethod(); 568 Method meth2 = ((OperationDesc)o2).getMethod(); 569 return (meth1.getParameterTypes().length - 570 meth2.getParameterTypes().length); 571 } 572 }); 573 574 OperationDesc[] array = new OperationDesc[overloads.size()]; 575 return (OperationDesc[])overloads.toArray(array); 576 } 577 578 private synchronized void initQNameMap() 579 { 580 if (qname2OperationsMap == null) 581 { 582 loadServiceDescByIntrospection(); 583 584 qname2OperationsMap = new HashMap (); 585 for (Iterator i = operations.iterator(); i.hasNext();) 586 { 587 OperationDesc operationDesc = (OperationDesc)i.next(); 588 QName qname = operationDesc.getElementQName(); 589 ArrayList list = (ArrayList )qname2OperationsMap.get(qname); 590 if (list == null) 591 { 592 list = new ArrayList (); 593 qname2OperationsMap.put(qname, list); 594 } 595 list.add(operationDesc); 596 } 597 } 598 } 599 600 609 private void syncOperationToClass(OperationDesc opDesc, Class implClass) 610 { 611 log.debug("Enter: syncOperationToClass " + opDesc); 612 613 678 if (opDesc.getMethod() != null) 680 return; 681 682 684 Method [] methods = implClass.getDeclaredMethods(); 685 Method possibleMatch = null; 687 688 for (int i = 0; i < methods.length; i++) 689 { 690 Method method = methods[i]; 691 if (Modifier.isPublic(method.getModifiers()) && 692 method.getName().equals(opDesc.getName()) && 693 method2OperationMap.get(method) == null) 694 { 695 696 log.debug("Sync method: " + method); 697 698 if (style == Style.MESSAGE) 699 { 700 int messageOperType = checkMessageMethod(method); 701 if (messageOperType == OperationDesc.MSG_METHOD_NONCONFORMING) continue; 702 if (messageOperType == -1) 703 { 704 throw new InternalException("Couldn't match method to any of the allowable message-style patterns!"); 705 } 706 opDesc.setMessageOperationStyle(messageOperType); 707 } 708 709 Class [] paramTypes = method.getParameterTypes(); 711 if (paramTypes.length != opDesc.getNumParams()) 712 { 713 log.debug("Number of parameters don't match"); 714 continue; 715 } 716 717 int j; 718 boolean conversionNecessary = false; 719 for (j = 0; j < paramTypes.length; j++) 720 { 721 Class type = paramTypes[j]; 722 Class actualType = type; 723 724 log.debug("Converting param: " + type); 725 726 if (Holder .class.isAssignableFrom(type)) 727 actualType = JavaUtils.getHolderValueType(type); 728 729 ParameterDesc param = opDesc.getParameter(j); 730 Class paramClass = param.getJavaType(); 731 732 QName typeQName = param.getTypeQName(); 733 if (typeQName == null) 734 { 735 typeQName = tm.getTypeQName(type); 743 param.setTypeQName(typeQName); 744 log.debug("Setting param TypeQName: " + typeQName); 745 746 } 747 else 748 { 749 if (paramClass != null && JavaUtils.getHolderValueType(paramClass) != null) 756 { 757 paramClass = JavaUtils.getHolderValueType(paramClass); 758 log.debug("Setting param class to holder type: " + paramClass); 759 } 760 if (paramClass == null) 761 { 762 paramClass = tm.getClassForQName(param.getTypeQName()); 763 log.debug("Setting param class from TypeQName: " + paramClass); 764 } 765 766 if (paramClass != null) 767 { 768 if (!JavaUtils.isConvertable(paramClass, actualType)) 772 { 773 log.debug("Param class is not convertible: [param=" + paramClass + ",actual=" + actualType + "]"); 774 break; 775 } 776 777 if (!actualType.isAssignableFrom(paramClass)) 778 { 779 conversionNecessary = true; 781 log.debug("Actual type is not assignable from param class: [param=" + paramClass + ",actual=" + actualType + "]"); 782 } 783 } 784 } 785 param.setJavaType(type); 789 log.debug("Setting param java type: " + type); 790 } 791 792 if (j != paramTypes.length) 793 { 794 continue; 796 } 797 798 possibleMatch = method; 800 log.debug("Possible match: " + possibleMatch); 801 802 if (!conversionNecessary) 805 { 806 break; 807 } 808 809 log.debug("Conversion still necessary"); 810 } 811 } 812 813 if (possibleMatch != null) 818 { 819 ParameterDesc retParamDesc = opDesc.getReturnParamDesc(); 820 QName retTypeQName = retParamDesc.getTypeQName(); 821 Class retType = retParamDesc.getJavaType(); 822 if (retTypeQName != null && retType == null) 823 retType = tm.getClassForQName(retTypeQName); 824 825 if (retType != null) 826 { 827 Class seiReturnType = possibleMatch.getReturnType(); 828 if (JavaUtils.isConvertable(retType, seiReturnType)) 829 { 830 opDesc.setReturnClass(seiReturnType); 831 log.debug("Setting return type: " + seiReturnType); 832 } 833 else 834 { 835 log.warn("Return type is not convertible to: " + retType); 836 } 838 } 839 840 if (possibleMatch != null) 841 { 842 createFaultMetadata(possibleMatch, opDesc); 844 845 opDesc.setMethod(possibleMatch); 846 method2OperationMap.put(possibleMatch, opDesc); 847 log.debug("Setting operation method: " + possibleMatch); 848 } 849 } 850 851 if (opDesc.getMethod() == null) 853 { 854 Class superClass = implClass.getSuperclass(); 855 if (superClass != null && 856 !superClass.getName().startsWith("java.") && 857 !superClass.getName().startsWith("javax.") && 858 (stopClasses == null || 859 !stopClasses.contains(superClass.getName()))) 860 { 861 862 log.debug("No match found, trying super class"); 863 syncOperationToClass(opDesc, superClass); 864 } 865 } 866 867 if (opDesc.getMethod() == null) 869 { 870 InternalException ie = 871 new InternalException(Messages.getMessage("serviceDescOperSync00", 872 opDesc.getName(), 873 implClass.getName())); 874 throw ie; 875 } 876 } 877 878 private int checkMessageMethod(Method method) 879 { 880 Class [] params = method.getParameterTypes(); 883 884 if (params.length == 1) 885 { 886 if ((params[0] == Element [].class) && 887 (method.getReturnType() == Element [].class)) 888 { 889 return OperationDesc.MSG_METHOD_ELEMENTARRAY; 890 } 891 892 if ((params[0] == SOAPBodyElementAxisImpl[].class) && 893 (method.getReturnType() == SOAPBodyElementAxisImpl[].class)) 894 { 895 return OperationDesc.MSG_METHOD_BODYARRAY; 896 } 897 898 if ((params[0] == Document .class) && 899 (method.getReturnType() == Document .class)) 900 { 901 return OperationDesc.MSG_METHOD_DOCUMENT; 902 } 903 } 904 else if (params.length == 2) 905 { 906 if ((params[0] == SOAPEnvelopeAxisImpl.class) && 907 (params[1] == SOAPEnvelopeAxisImpl.class) && 908 (method.getReturnType() == void.class)) 909 { 910 return OperationDesc.MSG_METHOD_SOAPENVELOPE; 911 } 912 } 913 if (null != allowedMethods && !allowedMethods.isEmpty()) 914 throw new InternalException(Messages.getMessage("badMsgMethodParams", 915 method.getName())); 916 return OperationDesc.MSG_METHOD_NONCONFORMING; 917 } 918 919 923 public void loadServiceDescByIntrospection() 924 { 925 loadServiceDescByIntrospection(implClass); 926 927 completedNames = null; 930 } 931 932 936 public void loadServiceDescByIntrospection(Class implClass) 937 { 938 if (introspectionComplete || implClass == null) 939 { 940 return; 941 } 942 943 this.implClass = implClass; 945 if (Skeleton.class.isAssignableFrom(implClass)) 946 { 947 isSkeletonClass = true; 948 loadSkeletonOperations(); 949 } 950 951 954 AxisServiceConfig axisConfig = null; 955 try 956 { 957 Method method = implClass.getDeclaredMethod("getAxisServiceConfig", new Class []{}); 958 if (method != null && Modifier.isStatic(method.getModifiers())) 959 { 960 axisConfig = (AxisServiceConfig)method.invoke(null, null); 961 } 962 } 963 catch (Exception e) 964 { 965 } 967 968 if (axisConfig != null) 969 { 970 String allowedMethodsStr = axisConfig.getAllowedMethods(); 971 if (allowedMethodsStr != null && !"*".equals(allowedMethodsStr)) 972 { 973 ArrayList methodList = new ArrayList (); 974 StringTokenizer tokenizer = 975 new StringTokenizer (allowedMethodsStr, " ,"); 976 while (tokenizer.hasMoreTokens()) 977 { 978 methodList.add(tokenizer.nextToken()); 979 } 980 setAllowedMethods(methodList); 981 } 982 } 983 984 loadServiceDescByIntrospectionRecursive(implClass); 985 986 for (Iterator iterator = operations.iterator(); iterator.hasNext();) 988 { 989 OperationDesc operation = (OperationDesc)iterator.next(); 990 if (operation.getMethod() == null) 991 { 992 throw new InternalException(Messages.getMessage("badWSDDOperation", 993 operation.getName(), 994 "" + operation.getNumParams())); 995 } 996 } 997 998 if ((style == Style.MESSAGE) && operations.size() == 1) 999 { 1000 messageServiceDefaultOp = (OperationDesc)operations.get(0); 1001 } 1002 1003 introspectionComplete = true; 1004 } 1005 1006 1012 private boolean isServiceLifeCycleMethod(Class implClass, Method m) 1013 { 1014 if (ServiceLifecycle .class.isAssignableFrom(implClass)) 1015 { 1016 String methodName = m.getName(); 1017 1018 if (methodName.equals("init")) 1019 { 1020 Class [] classes = m.getParameterTypes(); 1023 if (classes != null && 1024 classes.length == 1 && 1025 classes[0] == Object .class && 1026 m.getReturnType() == Void.TYPE) 1027 { 1028 return true; 1029 } 1030 } 1031 else if (methodName.equals("destroy")) 1032 { 1033 Class [] classes = m.getParameterTypes(); 1036 if (classes != null && 1037 classes.length == 0 && 1038 m.getReturnType() == Void.TYPE) 1039 { 1040 return true; 1041 } 1042 } 1043 } 1044 return false; 1045 } 1046 1047 1050 private void loadServiceDescByIntrospectionRecursive(Class implClass) 1051 { 1052 if (Skeleton.class.equals(implClass)) 1053 { 1054 return; 1055 } 1056 1057 Method [] methods = implClass.getDeclaredMethods(); 1058 1059 for (int i = 0; i < methods.length; i++) 1060 { 1061 if (Modifier.isPublic(methods[i].getModifiers()) && !isServiceLifeCycleMethod(implClass, methods[i])) 1062 { 1063 getSyncedOperationsForName(implClass, methods[i].getName()); 1064 } 1065 } 1066 1067 if (implClass.isInterface()) 1068 { 1069 Class [] superClasses = implClass.getInterfaces(); 1070 for (int i = 0; i < superClasses.length; i++) 1071 { 1072 Class superClass = superClasses[i]; 1073 if (!superClass.getName().startsWith("java.") && 1074 !superClass.getName().startsWith("javax.") && 1075 (stopClasses == null || 1076 !stopClasses.contains(superClass.getName()))) 1077 { 1078 loadServiceDescByIntrospectionRecursive(superClass); 1079 } 1080 } 1081 } 1082 else 1083 { 1084 Class superClass = implClass.getSuperclass(); 1085 if (superClass != null && 1086 !superClass.getName().startsWith("java.") && 1087 !superClass.getName().startsWith("javax.") && 1088 (stopClasses == null || 1089 !stopClasses.contains(superClass.getName()))) 1090 { 1091 loadServiceDescByIntrospectionRecursive(superClass); 1092 } 1093 } 1094 } 1095 1096 1101 public void loadServiceDescByIntrospection(Class cls, TypeMapping tm) 1102 { 1103 implClass = cls; 1105 this.tm = tm; 1106 1107 if (Skeleton.class.isAssignableFrom(implClass)) 1108 { 1109 isSkeletonClass = true; 1110 loadSkeletonOperations(); 1111 } 1112 1113 loadServiceDescByIntrospection(); 1114 } 1115 1116 1120 private void getSyncedOperationsForName(Class implClass, String methodName) 1121 { 1122 if (isSkeletonClass) 1124 { 1125 if (methodName.equals("getOperationDescByName") || 1126 methodName.equals("getOperationDescs")) 1127 return; 1128 } 1129 1130 if (implClass == null) 1133 return; 1134 1135 if (completedNames == null || completedNames.contains(methodName)) 1137 return; 1138 1139 if ((allowedMethods != null) && 1141 !allowedMethods.contains(methodName)) 1142 return; 1143 1144 if ((disallowedMethods != null) && 1145 disallowedMethods.contains(methodName)) 1146 return; 1147 1148 if (isSkeletonClass && !haveAllSkeletonMethods) 1152 { 1153 1155 if (skelMethod == null) 1156 { 1157 try 1159 { 1160 skelMethod = implClass.getDeclaredMethod("getOperationDescByName", 1161 new Class []{String .class}); 1162 } 1163 catch (NoSuchMethodException e) 1164 { 1165 } 1166 catch (SecurityException e) 1167 { 1168 } 1169 if (skelMethod == null) 1170 { 1171 return; 1173 } 1174 } 1175 try 1176 { 1177 List skelList = 1178 (List )skelMethod.invoke(implClass, 1179 new Object []{methodName}); 1180 if (skelList != null) 1181 { 1182 Iterator i = skelList.iterator(); 1183 while (i.hasNext()) 1184 { 1185 addOperationDesc((OperationDesc)i.next()); 1186 } 1187 } 1188 } 1189 catch (IllegalAccessException e) 1190 { 1191 return; 1192 } 1193 catch (IllegalArgumentException e) 1194 { 1195 return; 1196 } 1197 catch (InvocationTargetException e) 1198 { 1199 return; 1200 } 1201 } 1202 1203 if (name2OperationsMap != null) 1206 { 1207 ArrayList currentOverloads = 1208 (ArrayList )name2OperationsMap.get(methodName); 1209 if (currentOverloads != null) 1210 { 1211 for (Iterator i = currentOverloads.iterator(); i.hasNext();) 1213 { 1214 OperationDesc oper = (OperationDesc)i.next(); 1215 if (oper.getMethod() == null) 1216 { 1217 syncOperationToClass(oper, implClass); 1218 } 1219 } 1220 } 1221 } 1222 1223 1232 createOperationsForName(implClass, methodName); 1233 1234 completedNames.add(methodName); 1236 } 1237 1238 1244 private void createOperationsForName(Class implClass, String methodName) 1245 { 1246 if (isSkeletonClass) 1248 { 1249 if (methodName.equals("getOperationDescByName") || 1250 methodName.equals("getOperationDescs")) 1251 return; 1252 } 1253 1254 Method [] methods = implClass.getDeclaredMethods(); 1255 1256 for (int i = 0; i < methods.length; i++) 1257 { 1258 Method method = methods[i]; 1259 if (Modifier.isPublic(method.getModifiers()) && 1260 method.getName().equals(methodName)) 1261 { 1262 createOperationForMethod(method); 1263 } 1264 } 1265 1266 Class superClass = implClass.getSuperclass(); 1267 if (superClass != null && 1268 !superClass.getName().startsWith("java.") && 1269 !superClass.getName().startsWith("javax.")) 1270 { 1271 createOperationsForName(superClass, methodName); 1272 } 1273 } 1274 1275 1285 private void createOperationForMethod(Method method) 1286 { 1287 if (method2OperationMap.get(method) != null) 1289 { 1290 return; 1291 } 1292 1293 Class [] paramTypes = method.getParameterTypes(); 1294 1295 1298 ArrayList overloads = name2OperationsMap == null ? null : 1299 (ArrayList )name2OperationsMap.get(method.getName()); 1300 if (overloads != null && !overloads.isEmpty()) 1301 { 1302 for (int i = 0; i < overloads.size(); i++) 1305 { 1306 OperationDesc op = (OperationDesc)overloads.get(i); 1307 Method checkMethod = op.getMethod(); 1308 if (checkMethod != null) 1309 { 1310 Class [] others = checkMethod.getParameterTypes(); 1311 if (paramTypes.length == others.length) 1312 { 1313 int j = 0; 1314 for (; j < others.length; j++) 1315 { 1316 if (!others[j].equals(paramTypes[j])) 1317 break; 1318 } 1319 if (j == others.length) 1321 return; 1322 } 1323 } 1324 } 1325 } 1326 1327 OperationDesc operation = new OperationDesc(); 1329 operation.setName(method.getName()); 1330 String defaultNS = ""; 1331 if (namespaceMappings != null && !namespaceMappings.isEmpty()) 1332 { 1333 defaultNS = (String )namespaceMappings.get(0); 1336 } 1337 if (defaultNS.length() == 0) 1338 { 1339 defaultNS = Namespaces.makeNamespace(method.getDeclaringClass().getName()); 1340 } 1341 operation.setElementQName(new QName (defaultNS, method.getName())); 1342 operation.setMethod(method); 1343 1344 if (style == Style.MESSAGE) 1347 { 1348 int messageOperType = checkMessageMethod(method); 1349 if (messageOperType == OperationDesc.MSG_METHOD_NONCONFORMING) return; 1350 if (messageOperType == -1) 1351 { 1352 throw new InternalException("Couldn't match method to any of the allowable message-style patterns!"); 1353 } 1354 operation.setMessageOperationStyle(messageOperType); 1355 operation.setReturnClass(Object .class); 1356 operation.setReturnType(Constants.XSD_ANYTYPE); 1357 } 1358 else 1359 { 1360 Class retClass = method.getReturnType(); 1362 operation.setReturnClass(retClass); 1363 operation.setReturnType(tm.getTypeQName(method.getReturnType())); 1364 1365 String [] paramNames = getParamNames(method); 1366 1367 for (int k = 0; k < paramTypes.length; k++) 1368 { 1369 Class type = paramTypes[k]; 1370 ParameterDesc paramDesc = new ParameterDesc(); 1371 String opNamespace = operation.getElementQName().getNamespaceURI(); 1372 1373 if (paramNames != null && paramNames[k] != null && 1376 paramNames[k].length() > 0) 1377 { 1378 paramDesc.setQName(new QName (opNamespace, paramNames[k])); 1379 } 1380 else 1381 { 1382 paramDesc.setQName(new QName (opNamespace, "in" + k)); 1383 } 1384 1385 1388 Class heldClass = JavaUtils.getHolderValueType(type); 1389 if (heldClass != null) 1390 { 1391 paramDesc.setMode(ParameterDesc.INOUT); 1392 paramDesc.setTypeQName(tm.getTypeQName(heldClass)); 1393 } 1394 else 1395 { 1396 paramDesc.setMode(ParameterDesc.IN); 1397 paramDesc.setTypeQName(tm.getTypeQName(type)); 1398 } 1399 paramDesc.setJavaType(type); 1400 operation.addParameter(paramDesc); 1401 } 1402 } 1403 1404 createFaultMetadata(method, operation); 1405 1406 addOperationDesc(operation); 1407 method2OperationMap.put(method, operation); 1408 } 1409 1410 private void createFaultMetadata(Method method, OperationDesc operation) 1411 { 1412 1413 Class [] exceptionTypes = new Class [method.getExceptionTypes().length]; 1415 exceptionTypes = method.getExceptionTypes(); 1416 1417 for (int i = 0; i < exceptionTypes.length; i++) 1418 { 1419 1420 Class ex = exceptionTypes[i]; 1424 if (ex != java.rmi.RemoteException .class && 1425 ex != org.jboss.axis.AxisFault.class && 1426 !ex.getName().startsWith("java.") && 1427 !ex.getName().startsWith("javax.")) 1428 { 1429 1430 log.debug("createFaultMetadata: " + ex); 1431 1432 1444 1445 1467 1468 FaultDesc fault = operation.getFaultByClass(ex); 1469 1470 if (fault == null) 1472 { 1473 fault = new FaultDesc(); 1474 log.debug("Creating new fault desc: " + fault); 1475 } 1476 1477 1479 QName xmlType = fault.getXmlType(); 1481 if (xmlType == null) 1482 { 1483 QName typeQName = tm.getTypeQName(ex); 1484 fault.setXmlType(typeQName); 1485 log.debug("Setting XMLType: " + typeQName); 1486 } 1487 1488 String pkgAndClsName = ex.getName(); 1490 if (fault.getClassName() == null) 1491 { 1492 fault.setClassName(pkgAndClsName); 1493 log.debug("Setting ClassName: " + pkgAndClsName); 1494 } 1495 1496 if (fault.getName() == null) 1497 { 1498 String name = pkgAndClsName.substring(pkgAndClsName.lastIndexOf('.') + 1, 1499 pkgAndClsName.length()); 1500 fault.setName(name); 1501 log.debug("Setting Name: " + name); 1502 } 1503 1504 if (fault.getParameters() == null) 1507 { 1508 if (xmlType == null) 1509 { 1510 xmlType = tm.getTypeQName(ex); 1511 } 1512 QName qname = fault.getQName(); 1513 if (qname == null) 1514 { 1515 qname = new QName ("", "fault"); 1516 } 1517 ParameterDesc param = new ParameterDesc(qname, ParameterDesc.IN, xmlType); 1518 param.setJavaType(ex); 1519 ArrayList exceptionParams = new ArrayList (); 1520 exceptionParams.add(param); 1521 fault.setParameters(exceptionParams); 1522 } 1523 1524 if (fault.getQName() == null) 1526 { 1527 fault.setQName(new QName (pkgAndClsName)); 1528 } 1529 1530 operation.addFault(fault); 1532 } 1533 } 1534 } 1535 1536 private String [] getParamNames(Method method) 1537 { 1538 synchronized (method2ParamsMap) 1539 { 1540 String [] paramNames = (String [])method2ParamsMap.get(method); 1541 if (paramNames != null) 1542 return paramNames; 1543 paramNames = ParamNameExtractor.getParameterNamesFromDebugInfo(method); 1544 method2ParamsMap.put(method, paramNames); 1545 return paramNames; 1546 } 1547 } 1548 1549 public void setNamespaceMappings(List namespaces) 1550 { 1551 namespaceMappings = namespaces; 1552 } 1553 1554 public String getDefaultNamespace() 1555 { 1556 if (namespaceMappings == null || namespaceMappings.isEmpty()) 1557 return null; 1558 return (String )namespaceMappings.get(0); 1559 } 1560 1561 public void setDefaultNamespace(String namespace) 1562 { 1563 if (namespaceMappings == null) 1564 namespaceMappings = new ArrayList (); 1565 namespaceMappings.add(0, namespace); 1566 } 1567 1568 public void setProperty(String name, Object value) 1569 { 1570 if (properties == null) 1571 { 1572 properties = new HashMap (); 1573 } 1574 properties.put(name, value); 1575 } 1576 1577 public Object getProperty(String name) 1578 { 1579 if (properties == null) 1580 return null; 1581 1582 return properties.get(name); 1583 } 1584 1585 public String getEndpointURL() 1586 { 1587 return endpointURL; 1588 } 1589 1590 public void setEndpointURL(String endpointURL) 1591 { 1592 this.endpointURL = endpointURL; 1593 } 1594 1595 public TypeMappingRegistry getTypeMappingRegistry() 1596 { 1597 if (tmr == null) 1598 { 1599 tmr = new TypeMappingRegistryImpl(); 1600 } 1601 return tmr; 1602 } 1603 1604 public void setTypeMappingRegistry(TypeMappingRegistry tmr) 1605 { 1606 this.tmr = tmr; 1607 } 1608} 1609 | Popular Tags |