1 16 package org.apache.axis.wsdl.toJava; 17 18 import org.apache.axis.Constants; 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.axis.constants.Style; 21 import org.apache.axis.constants.Use; 22 import org.apache.axis.utils.JavaUtils; 23 import org.apache.axis.utils.Messages; 24 import org.apache.axis.wsdl.symbolTable.*; 25 import org.apache.commons.logging.Log; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.NodeList ; 28 29 import javax.wsdl.BindingInput; 30 import javax.wsdl.BindingOperation; 31 import javax.wsdl.Input; 32 import javax.wsdl.Message; 33 import javax.wsdl.Operation; 34 import javax.wsdl.Part; 35 import javax.wsdl.extensions.ExtensibilityElement; 36 import javax.wsdl.extensions.UnknownExtensibilityElement; 37 import javax.wsdl.extensions.mime.MIMEMultipartRelated; 38 import javax.wsdl.extensions.soap.SOAPBody; 39 import javax.wsdl.extensions.soap.SOAPOperation; 40 import javax.xml.namespace.QName ; 41 import javax.xml.rpc.holders.BooleanHolder ; 42 import java.io.File ; 43 import java.io.IOException ; 44 import java.net.MalformedURLException ; 45 import java.net.URL ; 46 import java.util.HashMap ; 47 import java.util.Iterator ; 48 import java.util.List ; 49 import java.util.Map ; 50 import java.util.StringTokenizer ; 51 import java.util.Vector ; 52 53 58 public class Utils extends org.apache.axis.wsdl.symbolTable.Utils { 59 60 61 protected static Log log = LogFactory.getLog(Utils.class.getName()); 62 63 66 public static String holder(TypeEntry type, Emitter emitter) { 67 Parameter arg = new Parameter(); 68 arg.setType(type); 70 return holder(arg, emitter); 71 } 72 80 public static String holder(Parameter p, Emitter emitter) { 81 String mimeType = (p.getMIMEInfo() == null) 82 ? null 83 : p.getMIMEInfo().getType(); 84 String mimeDimensions = (mimeType == null) 85 ? "" 86 : p.getMIMEInfo().getDimensions(); 87 88 if (mimeType != null) { 90 if (mimeType.equals("image/gif") || mimeType.equals("image/jpeg")) { 91 return "org.apache.axis.holders.ImageHolder" + mimeDimensions; 92 } else if (mimeType.equals("text/plain")) { 93 return "javax.xml.rpc.holders.StringHolder" + mimeDimensions; 94 } else if (mimeType.startsWith("multipart/")) { 95 return "org.apache.axis.holders.MimeMultipartHolder" 96 + mimeDimensions; 97 } else if (mimeType.startsWith("application/octetstream") 98 || mimeType.startsWith("application/octet-stream")) { 99 return "org.apache.axis.holders.OctetStreamHolder" 100 + mimeDimensions; 101 } else if (mimeType.equals("text/xml") 102 || mimeType.equals("application/xml")) { 103 return "org.apache.axis.holders.SourceHolder" + mimeDimensions; 104 } else { 105 return "org.apache.axis.holders.DataHandlerHolder" 106 + mimeDimensions; 107 } 108 } 109 110 TypeEntry type = p.getType(); 111 String typeValue = type.getName(); 112 if (p.isOmittable() 115 && (type instanceof BaseType 116 || type instanceof DefinedElement 117 && type.getRefType() instanceof BaseType)) { 118 String wrapperTypeValue = (String ) TYPES.get(typeValue); 119 typeValue = wrapperTypeValue == null ? typeValue 120 : wrapperTypeValue; 121 } 122 123 if (typeValue.equals("byte[]") && type.isBaseType()) { 125 return "javax.xml.rpc.holders.ByteArrayHolder"; 126 } 127 128 else if (typeValue.endsWith("[]")) { 130 String name = emitter.getJavaName(type.getQName()); 131 String packagePrefix = ""; 132 133 if ((type instanceof CollectionType) 136 && (type.getRefType() instanceof BaseType)) { 137 String uri = type.getRefType().getQName().getNamespaceURI(); 138 139 packagePrefix = emitter.getNamespaces().getCreate(uri, false); 140 141 if (packagePrefix == null) { 142 packagePrefix = ""; 143 } else { 144 packagePrefix += '.'; 145 } 146 } 147 148 name = JavaUtils.replace(name, "java.lang.", ""); 149 150 name = JavaUtils.replace(name, "[]", "Array"); 153 name = addPackageName(name, "holders"); 154 155 return packagePrefix + name + "Holder"; 156 } 157 158 else if (typeValue.equals("String")) { 160 return "javax.xml.rpc.holders.StringHolder"; 161 } else if (typeValue.equals("java.lang.String")) { 162 return "javax.xml.rpc.holders.StringHolder"; 163 } 164 165 else if (typeValue.equals("Object")) { 167 return "javax.xml.rpc.holders.ObjectHolder"; 168 } else if (typeValue.equals("java.lang.Object")) { 169 return "javax.xml.rpc.holders.ObjectHolder"; 170 } 171 172 else if (typeValue.equals("int") || typeValue.equals("long") 174 || typeValue.equals("short") || typeValue.equals("float") 175 || typeValue.equals("double") || typeValue.equals("boolean") 176 || typeValue.equals("byte")) { 177 return "javax.xml.rpc.holders." + capitalizeFirstChar(typeValue) 178 + "Holder"; 179 } 180 181 else if (typeValue.startsWith("java.lang.")) { 183 return "javax.xml.rpc.holders" 184 + typeValue.substring(typeValue.lastIndexOf(".")) 185 + "WrapperHolder"; 186 } else if (typeValue.indexOf(".") < 0) { 187 return "javax.xml.rpc.holders" + typeValue + "WrapperHolder"; 188 } 189 190 else if (typeValue.equals("java.math.BigDecimal")) { 193 return "javax.xml.rpc.holders.BigDecimalHolder"; 194 } else if (typeValue.equals("java.math.BigInteger")) { 195 return "javax.xml.rpc.holders.BigIntegerHolder"; 196 } else if (typeValue.equals("java.util.Date")) { 197 return "org.apache.axis.holders.DateHolder"; 198 } else if (typeValue.equals("java.util.Calendar")) { 199 return "javax.xml.rpc.holders.CalendarHolder"; 200 } else if (typeValue.equals("javax.xml.namespace.QName")) { 201 return "javax.xml.rpc.holders.QNameHolder"; 202 } else if (typeValue.equals("javax.activation.DataHandler")) { 203 return "org.apache.axis.holders.DataHandlerHolder"; 204 } 205 206 else if (typeValue.startsWith("org.apache.axis.types.")) { 208 int i = typeValue.lastIndexOf('.'); 209 String t = typeValue.substring(i + 1); 210 211 return "org.apache.axis.holders." + t + "Holder"; 212 } 213 214 else { 217 return addPackageName(typeValue, "holders") + "Holder"; 218 } 219 } 221 228 public static String addPackageName(String className, String newPkg) { 229 230 int index = className.lastIndexOf("."); 231 232 if (index >= 0) { 233 return className.substring(0, index) + "." + newPkg 234 + className.substring(index); 235 } else { 236 return newPkg + "." + className; 237 } 238 } 239 240 248 public static String getFullExceptionName(Message faultMessage, 249 SymbolTable symbolTable) { 250 251 MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); 252 253 return (String ) me.getDynamicVar( 254 JavaGeneratorFactory.EXCEPTION_CLASS_NAME); 255 } 257 264 public static QName getFaultDataType(Message faultMessage, 265 SymbolTable symbolTable) { 266 267 MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); 268 269 return (QName ) me.getDynamicVar( 270 JavaGeneratorFactory.EXCEPTION_DATA_TYPE); 271 } 273 280 public static boolean isFaultComplex(Message faultMessage, 281 SymbolTable symbolTable) { 282 283 MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); 284 Boolean ret = 285 (Boolean ) me.getDynamicVar(JavaGeneratorFactory.COMPLEX_TYPE_FAULT); 286 287 if (ret != null) { 288 return ret.booleanValue(); 289 } else { 290 return false; 291 } 292 } 294 305 public static Vector getEnumerationBaseAndValues(Node node, 306 SymbolTable symbolTable) { 307 308 if (node == null) { 309 return null; 310 } 311 312 QName nodeKind = Utils.getNodeQName(node); 314 315 if ((nodeKind != null) && nodeKind.getLocalPart().equals("element") 316 && Constants.isSchemaXSD(nodeKind.getNamespaceURI())) { 317 NodeList children = node.getChildNodes(); 318 Node simpleNode = null; 319 320 for (int j = 0; (j < children.getLength()) && (simpleNode == null); 321 j++) { 322 QName simpleKind = Utils.getNodeQName(children.item(j)); 323 324 if ((simpleKind != null) 325 && simpleKind.getLocalPart().equals("simpleType") 326 && Constants.isSchemaXSD( 327 simpleKind.getNamespaceURI())) { 328 simpleNode = children.item(j); 329 node = simpleNode; 330 } 331 } 332 } 333 334 nodeKind = Utils.getNodeQName(node); 336 337 if ((nodeKind != null) && nodeKind.getLocalPart().equals("simpleType") 338 && Constants.isSchemaXSD(nodeKind.getNamespaceURI())) { 339 340 NodeList children = node.getChildNodes(); 343 Node restrictionNode = null; 344 345 for (int j = 0; 346 (j < children.getLength()) && (restrictionNode == null); 347 j++) { 348 QName restrictionKind = Utils.getNodeQName(children.item(j)); 349 350 if ((restrictionKind != null) 351 && restrictionKind.getLocalPart().equals("restriction") 352 && Constants.isSchemaXSD( 353 restrictionKind.getNamespaceURI())) { 354 restrictionNode = children.item(j); 355 } 356 } 357 358 TypeEntry baseEType = null; 362 363 if (restrictionNode != null) { 364 QName baseType = Utils.getTypeQName(restrictionNode, 365 new BooleanHolder (), false); 366 367 baseEType = symbolTable.getType(baseType); 368 369 if (baseEType != null) { 370 String javaName = baseEType.getName(); 371 372 if (javaName.equals("boolean") 373 || !SchemaUtils.isSimpleSchemaType( 374 baseEType.getQName())) { 375 baseEType = null; 376 } 377 } 378 } 379 380 if ((baseEType != null) && (restrictionNode != null)) { 382 Vector v = new Vector (); 383 NodeList enums = restrictionNode.getChildNodes(); 384 385 for (int i = 0; i < enums.getLength(); i++) { 386 QName enumKind = Utils.getNodeQName(enums.item(i)); 387 388 if ((enumKind != null) 389 && enumKind.getLocalPart().equals("enumeration") 390 && Constants.isSchemaXSD( 391 enumKind.getNamespaceURI())) { 392 393 Node enumNode = enums.item(i); 395 String value = Utils.getAttribute(enumNode, "value"); 396 397 if (value != null) { 398 v.add(value); 399 } 400 } 401 } 402 403 if (v.isEmpty()) { 405 return null; 406 } 407 408 v.add(0, baseEType); 410 411 return v; 412 } 413 } 414 415 return null; 416 } 417 418 424 public static String capitalizeFirstChar(String name) { 425 426 if ((name == null) || name.equals("")) { 427 return name; 428 } 429 430 char start = name.charAt(0); 431 432 if (Character.isLowerCase(start)) { 433 start = Character.toUpperCase(start); 434 435 return start + name.substring(1); 436 } 437 438 return name; 439 } 441 447 public static String addUnderscore(String name) { 448 449 if ((name == null) || name.equals("")) { 450 return name; 451 } 452 453 return "_" + name; 454 } 455 456 462 public static String xmlNameToJava(String name) { 463 464 return JavaUtils.xmlNameToJava(name); 469 } 470 471 477 public static String xmlNameToJavaClass(String name) { 478 return capitalizeFirstChar(xmlNameToJava(name)); 479 } 480 481 487 public static String makePackageName(String namespace) { 488 489 String hostname = null; 490 String path = ""; 491 492 try { 494 URL u = new URL (namespace); 495 496 hostname = u.getHost(); 497 path = u.getPath(); 498 } catch (MalformedURLException e) { 499 if (namespace.indexOf(":") > -1) { 500 hostname = namespace.substring(namespace.indexOf(":") + 1); 501 502 if (hostname.indexOf("/") > -1) { 503 hostname = hostname.substring(0, hostname.indexOf("/")); 504 } 505 } else { 506 hostname = namespace; 507 } 508 } 509 510 if (hostname == null) { 512 return null; 513 } 514 515 hostname = hostname.replace('-', '_'); 517 path = path.replace('-', '_'); 518 519 if ((path.length() > 0) && (path.charAt(path.length() - 1) == '/')) { 521 path = path.substring(0, path.length() - 1); 522 } 523 524 StringTokenizer st = new StringTokenizer (hostname, ".:"); 526 String [] words = new String [st.countTokens()]; 527 528 for (int i = 0; i < words.length; ++i) { 529 words[i] = st.nextToken(); 530 } 531 532 StringBuffer sb = new StringBuffer (namespace.length()); 533 534 for (int i = words.length - 1; i >= 0; --i) { 535 addWordToPackageBuffer(sb, words[i], (i == words.length - 1)); 536 } 537 538 StringTokenizer st2 = new StringTokenizer (path, "/"); 540 541 while (st2.hasMoreTokens()) { 542 addWordToPackageBuffer(sb, st2.nextToken(), false); 543 } 544 545 return sb.toString(); 546 } 547 548 557 private static void addWordToPackageBuffer(StringBuffer sb, String word, 558 boolean firstWord) { 559 560 if (JavaUtils.isJavaKeyword(word)) { 561 word = JavaUtils.makeNonJavaKeyword(word); 562 } 563 564 if (!firstWord) { 566 sb.append('.'); 567 } 568 569 if (Character.isDigit(word.charAt(0))) { 571 sb.append('_'); 572 } 573 574 if (word.indexOf('.') != -1) { 576 char[] buf = word.toCharArray(); 577 578 for (int i = 0; i < word.length(); i++) { 579 if (buf[i] == '.') { 580 buf[i] = '_'; 581 } 582 } 583 584 word = new String (buf); 585 } 586 587 sb.append(word); 588 } 589 590 596 public static String getJavaLocalName(String fullName) { 597 return fullName.substring(fullName.lastIndexOf('.') + 1); 598 } 600 606 public static String getJavaPackageName(String fullName) { 607 608 if (fullName.lastIndexOf('.') > 0) { 609 return fullName.substring(0, fullName.lastIndexOf('.')); 610 } else { 611 return ""; 612 } 613 } 615 624 public static boolean fileExists( 625 String name, String namespace, Namespaces namespaces) 626 throws IOException { 627 628 String packageName = namespaces.getAsDir(namespace); 629 String fullName = packageName + name; 630 631 return new File (fullName).exists(); 632 } 634 635 private static HashMap TYPES = new HashMap (7); 636 637 static { 638 TYPES.put("int", "java.lang.Integer"); 639 TYPES.put("float", "java.lang.Float"); 640 TYPES.put("boolean", "java.lang.Boolean"); 641 TYPES.put("double", "java.lang.Double"); 642 TYPES.put("byte", "java.lang.Byte"); 643 TYPES.put("short", "java.lang.Short"); 644 TYPES.put("long", "java.lang.Long"); 645 } 646 647 654 public static String wrapPrimitiveType(TypeEntry type, String var) { 655 656 String objType = (type == null) 657 ? null 658 : (String ) TYPES.get(type.getName()); 659 660 if (objType != null) { 661 return "new " + objType + "(" + var + ")"; 662 } else if ((type != null) && type.getName().equals("byte[]") 663 && type.getQName().getLocalPart().equals("hexBinary")) { 664 665 return "new org.apache.axis.types.HexBinary(" + var + ")"; 667 } else { 668 return var; 669 } 670 } 672 679 public static String getResponseString(Parameter param, 680 String var) { 681 if (param.getType() == null) { 682 return ";"; 683 } 684 String typeName = param.getType().getName(); 685 MimeInfo mimeInfo = param.getMIMEInfo(); 686 687 String mimeType = (mimeInfo == null) 688 ? null 689 : mimeInfo.getType(); 690 String mimeDimensions = (mimeInfo == null) 691 ? "" 692 : mimeInfo.getDimensions(); 693 694 if (mimeType != null) { 695 if (mimeType.equals("image/gif") || mimeType.equals("image/jpeg")) { 696 return "(java.awt.Image" + mimeDimensions + ") " + var + ";"; 697 } else if (mimeType.equals("text/plain")) { 698 return "(java.lang.String" + mimeDimensions + ") " + var + ";"; 699 } else if (mimeType.equals("text/xml") 700 || mimeType.equals("application/xml")) { 701 return "(javax.xml.transform.Source" + mimeDimensions + ") " 702 + var + ";"; 703 } else if (mimeType.startsWith("multipart/")) { 704 return "(javax.mail.internet.MimeMultipart" + mimeDimensions 705 + ") " + var + ";"; 706 } else if (mimeType.startsWith("application/octetstream") 707 || mimeType.startsWith("application/octet-stream")) { 708 return "(org.apache.axis.attachments.OctetStream" 711 + mimeDimensions + ") " + var + ";"; 712 } else { 713 return "(javax.activation.DataHandler" + mimeDimensions + ") " 714 + var + ";"; 715 } 716 } 717 718 String objType = (String ) TYPES.get(typeName); 719 720 if (objType != null) { 721 if ((param.isOmittable() && param.getType().getDimensions().equals("")) 724 || param.getType().getUnderlTypeNillable()) { 725 726 typeName = getWrapperType(param.getType()); 727 } else { 728 return "((" + objType + ") " + var + ")." + typeName + 729 "Value();"; 730 } 731 } 732 733 return "(" + typeName + ") " + var + ";"; 734 } 736 742 public static boolean isPrimitiveType(TypeEntry type) { 743 return TYPES.get(type.getName()) != null; 744 } 746 755 public static String getWrapperType(String type) { 756 String ret = (String )TYPES.get(type); 757 return (ret == null) ? type : ret; 758 } 759 760 767 public static String getWrapperType(TypeEntry type) { 768 String dims = type.getDimensions(); 769 if (!dims.equals("")) { 770 771 TypeEntry te = type.getRefType(); 772 if (te != null 773 && !te.getDimensions().equals("")) { 774 775 return getWrapperType(te) + dims; 776 } 777 if (te instanceof BaseType 778 || te instanceof DefinedElement 779 && te.getRefType() instanceof BaseType) { 780 781 return getWrapperType(te) + dims; 782 } 783 } 784 return getWrapperType(type.getName()); 785 } 786 787 796 public static QName getOperationQName(BindingOperation bindingOper, 797 BindingEntry bEntry, 798 SymbolTable symbolTable) { 799 800 Operation operation = bindingOper.getOperation(); 801 String operationName = operation.getName(); 802 803 if ((bEntry.getBindingStyle() == Style.DOCUMENT) 809 && symbolTable.isWrapped()) { 810 Input input = operation.getInput(); 811 812 if (input != null) { 813 Map parts = input.getMessage().getParts(); 814 815 if ((parts != null) && !parts.isEmpty()) { 816 Iterator i = parts.values().iterator(); 817 Part p = (Part) i.next(); 818 819 return p.getElementName(); 820 } 821 } 822 } 823 824 String ns = null; 825 826 BindingInput bindInput = bindingOper.getBindingInput(); 830 831 if (bindInput != null) { 832 Iterator it = bindInput.getExtensibilityElements().iterator(); 833 834 while (it.hasNext()) { 835 ExtensibilityElement elem = (ExtensibilityElement) it.next(); 836 837 if (elem instanceof SOAPBody) { 838 SOAPBody body = (SOAPBody) elem; 839 840 ns = body.getNamespaceURI(); 841 if (bEntry.getInputBodyType(operation) == Use.ENCODED && (ns == null || ns.length() == 0)) { 842 log.warn(Messages.getMessage("badNamespaceForOperation00", 843 bEntry.getName(), 844 operation.getName())); 845 846 } 847 break; 848 } else if (elem instanceof MIMEMultipartRelated) { 849 Object part = null; 850 javax.wsdl.extensions.mime.MIMEMultipartRelated mpr = 851 (javax.wsdl.extensions.mime.MIMEMultipartRelated) elem; 852 List l = 853 mpr.getMIMEParts(); 854 855 for (int j = 0; 856 (l != null) && (j < l.size()) && (part == null); 857 j++) { 858 javax.wsdl.extensions.mime.MIMEPart mp = 859 (javax.wsdl.extensions.mime.MIMEPart) l.get(j); 860 List ll = 861 mp.getExtensibilityElements(); 862 863 for (int k = 0; (ll != null) && (k < ll.size()) 864 && (part == null); k++) { 865 part = ll.get(k); 866 867 if (part instanceof SOAPBody) { 868 SOAPBody body = (SOAPBody) part; 869 870 ns = body.getNamespaceURI(); 871 if (bEntry.getInputBodyType(operation) == Use.ENCODED && (ns == null || ns.length() == 0)) { 872 log.warn(Messages.getMessage("badNamespaceForOperation00", 873 bEntry.getName(), 874 operation.getName())); 875 876 } 877 break; 878 } else { 879 part = null; 880 } 881 } 882 } 883 } else if (elem instanceof UnknownExtensibilityElement) { 884 885 UnknownExtensibilityElement unkElement = 887 (UnknownExtensibilityElement) elem; 888 QName name = 889 unkElement.getElementType(); 890 891 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) 892 && name.getLocalPart().equals("body")) { 893 ns = unkElement.getElement().getAttribute("namespace"); 894 } 895 } 896 } 897 } 898 899 if (ns == null) { 904 ns = ""; 905 } 906 907 return new QName (ns, operationName); 908 } 909 910 916 public static String getOperationSOAPAction(BindingOperation bindingOper) { 917 List elems = bindingOper.getExtensibilityElements(); 919 Iterator it = elems.iterator(); 920 boolean found = false; 921 String action = null; 922 923 while (!found && it.hasNext()) { 924 ExtensibilityElement elem = 925 (ExtensibilityElement) it.next(); 926 927 if (elem instanceof SOAPOperation) { 928 SOAPOperation soapOp = (SOAPOperation) elem; 929 action = soapOp.getSoapActionURI(); 930 found = true; 931 } else if (elem instanceof UnknownExtensibilityElement) { 932 933 UnknownExtensibilityElement unkElement = 935 (UnknownExtensibilityElement) elem; 936 QName name = 937 unkElement.getElementType(); 938 939 if (name.getNamespaceURI().equals( 940 Constants.URI_WSDL12_SOAP) 941 && name.getLocalPart().equals("operation")) { 942 action = unkElement.getElement().getAttribute( 943 "soapAction"); 944 found = true; 945 } 946 } 947 } 948 return action; 949 } 950 951 958 public static String getNewQName(javax.xml.namespace.QName qname) { 959 return "new javax.xml.namespace.QName(\"" + qname.getNamespaceURI() 960 + "\", \"" + qname.getLocalPart() + "\")"; 961 } 962 963 public static String getNewQNameWithLastLocalPart(javax.xml.namespace.QName qname) { 964 return "new javax.xml.namespace.QName(\"" + qname.getNamespaceURI() 965 + "\", \"" + getLastLocalPart(qname.getLocalPart()) + "\")"; 966 } 967 968 976 public static String getParameterTypeName(Parameter parm) { 977 978 String ret; 979 980 if (parm.getMIMEInfo() == null) { 981 ret = parm.getType().getName(); 982 983 if ((parm.isOmittable() && parm.getType().getDimensions().equals("")) 986 || parm.getType().getUnderlTypeNillable()) { 987 988 ret = getWrapperType(parm.getType()); 989 } 990 } else { 991 String mime = parm.getMIMEInfo().getType(); 992 993 ret = JavaUtils.mimeToJava(mime); 994 995 if (ret == null) { 996 ret = parm.getType().getName(); 997 } else { 998 ret += parm.getMIMEInfo().getDimensions(); 999 } 1000 } 1001 1002 return ret; 1003 } 1005 1012 public static QName getXSIType(Parameter param) { 1013 1014 if (param.getMIMEInfo() != null) { 1015 return getMIMETypeQName(param.getMIMEInfo().getType()); 1016 } 1017 1018 return getXSIType(param.getType()); 1019 } 1021 1028 public static QName getXSIType(TypeEntry te) { 1029 1030 QName xmlType = null; 1031 1032 if ((te != null) && (te instanceof Element) 1035 && (te.getRefType() != null)) { 1036 te = te.getRefType(); 1037 } 1038 1039 if ((te != null) && (te instanceof CollectionTE) 1049 && (te.getRefType() != null)) { 1050 te = te.getRefType(); 1051 } 1052 1053 if (te != null) { 1054 xmlType = te.getQName(); 1055 } 1056 1057 return xmlType; 1058 } 1059 1060 1066 public static QName getMIMETypeQName(String mimeName) { 1067 1068 if ("text/plain".equals(mimeName)) { 1069 return Constants.MIME_PLAINTEXT; 1070 } else if ("image/gif".equals(mimeName) 1071 || "image/jpeg".equals(mimeName)) { 1072 return Constants.MIME_IMAGE; 1073 } else if ("text/xml".equals(mimeName) 1074 || "applications/xml".equals(mimeName)) { 1075 return Constants.MIME_SOURCE; 1076 } else if ("application/octet-stream".equals(mimeName) || 1077 "application/octetstream".equals(mimeName)) { 1078 return Constants.MIME_OCTETSTREAM; 1079 } else if ((mimeName != null) && mimeName.startsWith("multipart/")) { 1080 return Constants.MIME_MULTIPART; 1081 } else { 1082 return Constants.MIME_DATA_HANDLER; 1083 } 1084 } 1086 1092 public static boolean hasMIME(BindingEntry bEntry) { 1093 1094 List operations = bEntry.getBinding().getBindingOperations(); 1095 1096 for (int i = 0; i < operations.size(); ++i) { 1097 BindingOperation operation = (BindingOperation) operations.get(i); 1098 1099 if (hasMIME(bEntry, operation)) { 1100 return true; 1101 } 1102 } 1103 1104 return false; 1105 } 1107 1114 public static boolean hasMIME(BindingEntry bEntry, 1115 BindingOperation operation) { 1116 1117 Parameters parameters = bEntry.getParameters(operation.getOperation()); 1118 1119 if (parameters != null) { 1120 for (int idx = 0; idx < parameters.list.size(); ++idx) { 1121 Parameter p = (Parameter) parameters.list.get(idx); 1122 1123 if (p.getMIMEInfo() != null) { 1124 return true; 1125 } 1126 } 1127 } 1128 1129 return false; 1130 } 1132 1133 private static HashMap constructorMap = new HashMap (50); 1134 1135 1136 private static HashMap constructorThrowMap = new HashMap (50); 1137 1138 static { 1139 1140 constructorMap.put("int", "0"); 1145 constructorMap.put("float", "0"); 1146 constructorMap.put("boolean", "true"); 1147 constructorMap.put("double", "0"); 1148 constructorMap.put("byte", "(byte)0"); 1149 constructorMap.put("short", "(short)0"); 1150 constructorMap.put("long", "0"); 1151 constructorMap.put("java.lang.Boolean", "new java.lang.Boolean(false)"); 1152 constructorMap.put("java.lang.Byte", "new java.lang.Byte((byte)0)"); 1153 constructorMap.put("java.lang.Double", "new java.lang.Double(0)"); 1154 constructorMap.put("java.lang.Float", "new java.lang.Float(0)"); 1155 constructorMap.put("java.lang.Integer", "new java.lang.Integer(0)"); 1156 constructorMap.put("java.lang.Long", "new java.lang.Long(0)"); 1157 constructorMap.put("java.lang.Short", "new java.lang.Short((short)0)"); 1158 constructorMap.put("java.math.BigDecimal", 1159 "new java.math.BigDecimal(0)"); 1160 constructorMap.put("java.math.BigInteger", 1161 "new java.math.BigInteger(\"0\")"); 1162 constructorMap.put("java.lang.Object", "new java.lang.String()"); 1163 constructorMap.put("byte[]", "new byte[0]"); 1164 constructorMap.put("java.util.Calendar", 1165 "java.util.Calendar.getInstance()"); 1166 constructorMap.put( 1167 "javax.xml.namespace.QName", 1168 "new javax.xml.namespace.QName(\"http://double-double\", \"toil-and-trouble\")"); 1169 constructorMap.put( 1170 "org.apache.axis.types.NonNegativeInteger", 1171 "new org.apache.axis.types.NonNegativeInteger(\"0\")"); 1172 constructorMap.put("org.apache.axis.types.PositiveInteger", 1173 "new org.apache.axis.types.PositiveInteger(\"1\")"); 1174 constructorMap.put( 1175 "org.apache.axis.types.NonPositiveInteger", 1176 "new org.apache.axis.types.NonPositiveInteger(\"0\")"); 1177 constructorMap.put("org.apache.axis.types.NegativeInteger", 1178 "new org.apache.axis.types.NegativeInteger(\"-1\")"); 1179 1180 constructorThrowMap.put( 1182 "org.apache.axis.types.Time", 1183 "new org.apache.axis.types.Time(\"15:45:45.275Z\")"); 1184 constructorThrowMap.put("org.apache.axis.types.UnsignedLong", 1185 "new org.apache.axis.types.UnsignedLong(0)"); 1186 constructorThrowMap.put("org.apache.axis.types.UnsignedInt", 1187 "new org.apache.axis.types.UnsignedInt(0)"); 1188 constructorThrowMap.put("org.apache.axis.types.UnsignedShort", 1189 "new org.apache.axis.types.UnsignedShort(0)"); 1190 constructorThrowMap.put("org.apache.axis.types.UnsignedByte", 1191 "new org.apache.axis.types.UnsignedByte(0)"); 1192 constructorThrowMap.put( 1193 "org.apache.axis.types.URI", 1194 "new org.apache.axis.types.URI(\"urn:testing\")"); 1195 constructorThrowMap.put("org.apache.axis.types.Year", 1196 "new org.apache.axis.types.Year(2000)"); 1197 constructorThrowMap.put("org.apache.axis.types.Month", 1198 "new org.apache.axis.types.Month(1)"); 1199 constructorThrowMap.put("org.apache.axis.types.Day", 1200 "new org.apache.axis.types.Day(1)"); 1201 constructorThrowMap.put("org.apache.axis.types.YearMonth", 1202 "new org.apache.axis.types.YearMonth(2000,1)"); 1203 constructorThrowMap.put("org.apache.axis.types.MonthDay", 1204 "new org.apache.axis.types.MonthDay(1, 1)"); 1205 } 1206 1207 1225 public static String getConstructorForParam(Parameter param, 1226 SymbolTable symbolTable, 1227 BooleanHolder bThrow) { 1228 1229 String paramType = param.getType().getName(); 1230 if (param.isOmittable()) { 1231 paramType = Utils.getWrapperType(paramType); 1232 } 1233 String mimeType = (param.getMIMEInfo() == null) 1234 ? null 1235 : param.getMIMEInfo().getType(); 1236 String mimeDimensions = (param.getMIMEInfo() == null) 1237 ? "" 1238 : param.getMIMEInfo().getDimensions(); 1239 String out = null; 1240 1241 if (mimeType != null) { 1243 if (mimeType.equals("image/gif") || mimeType.equals("image/jpeg")) { 1244 return "null"; 1245 } else if (mimeType.equals("text/xml") 1246 || mimeType.equals("application/xml")) { 1247 if (mimeDimensions.length() <= 0) { 1248 return "new javax.xml.transform.stream.StreamSource()"; 1249 } else { 1250 return "new javax.xml.transform.stream.StreamSource[0]"; 1251 } 1252 } else if (mimeType.equals("application/octet-stream")|| 1253 mimeType.equals("application/octetstream")) { 1254 if (mimeDimensions.length() <= 0) { 1255 return "new org.apache.axis.attachments.OctetStream()"; 1256 } else { 1257 return "new org.apache.axis.attachments.OctetStream[0]"; 1258 } 1259 } else { 1260 return "new " + Utils.getParameterTypeName(param) + "()"; 1261 } 1262 } 1263 1264 out = (String ) constructorMap.get(paramType); 1266 1267 if (out != null) { 1268 return out; 1269 } 1270 1271 out = (String ) constructorThrowMap.get(paramType); 1273 1274 if (out != null) { 1275 bThrow.value = true; 1276 1277 return out; 1278 } 1279 1280 if (paramType.endsWith("[]")) { 1282 return "new " + JavaUtils.replace(paramType, "[]", "[0]"); 1283 } 1284 1285 1286 1287 Vector v = Utils.getEnumerationBaseAndValues(param.getType().getNode(), 1289 symbolTable); 1290 1291 if (v != null) { 1292 1293 String enumeration = 1295 (String ) JavaEnumTypeWriter.getEnumValueIds(v).get(0); 1296 1297 return paramType + "." + enumeration; 1298 } 1299 1300 if(param.getType().getRefType()!= null){ 1301 Vector v2 = Utils.getEnumerationBaseAndValues(param.getType().getRefType().getNode(), 1303 symbolTable); 1304 1305 if (v2 != null) { 1306 1307 String enumeration = 1309 (String ) JavaEnumTypeWriter.getEnumValueIds(v2).get(0); 1310 1311 return paramType + "." + enumeration; 1312 } 1313 } 1314 1315 return "new " + paramType + "()"; 1317 } 1318 1319 public static boolean shouldEmit(TypeEntry type) { 1320 return (!(((type.getBaseType() != null) && (type.getRefType() == null)) 1329 || (type instanceof CollectionTE) 1330 || (type instanceof Element) || !type.isReferenced() 1331 || type.isOnlyLiteralReferenced() 1332 || ((type.getNode() != null) 1333 && (isXsNode(type.getNode(), "group") || 1334 isXsNode(type.getNode(), "attributeGroup"))))); 1335 } 1336 1337 1338 1341 public static boolean isXsNode (Node node, String nameName) 1342 { 1343 return (node.getLocalName().equals(nameName) 1344 && Constants.isSchemaXSD (node.getNamespaceURI ())); 1345 } 1346 1347 1348 public static QName getItemQName(TypeEntry te) { 1349 if (te instanceof DefinedElement) { 1350 te = te.getRefType(); 1351 } 1352 return te.getItemQName(); 1353 } 1354 1355 public static QName getItemType(TypeEntry te) { 1356 if (te instanceof DefinedElement) { 1357 te = te.getRefType(); 1358 } 1359 return te.getComponentType(); 1360 } 1361} | Popular Tags |