1 55 package org.jboss.axis.wsdl.toJava; 56 57 import org.jboss.axis.Constants; 58 import org.jboss.axis.enums.Style; 59 import org.jboss.axis.utils.JavaUtils; 60 import org.jboss.axis.wsdl.symbolTable.BindingEntry; 61 import org.jboss.axis.wsdl.symbolTable.CollectionTE; 62 import org.jboss.axis.wsdl.symbolTable.Element; 63 import org.jboss.axis.wsdl.symbolTable.MessageEntry; 64 import org.jboss.axis.wsdl.symbolTable.MimeInfo; 65 import org.jboss.axis.wsdl.symbolTable.Parameter; 66 import org.jboss.axis.wsdl.symbolTable.Parameters; 67 import org.jboss.axis.wsdl.symbolTable.SchemaUtils; 68 import org.jboss.axis.wsdl.symbolTable.SymbolTable; 69 import org.jboss.axis.wsdl.symbolTable.TypeEntry; 70 import org.w3c.dom.Node ; 71 import org.w3c.dom.NodeList ; 72 73 import javax.wsdl.BindingInput; 74 import javax.wsdl.BindingOperation; 75 import javax.wsdl.Input; 76 import javax.wsdl.Message; 77 import javax.wsdl.Operation; 78 import javax.wsdl.Part; 79 import javax.wsdl.extensions.ExtensibilityElement; 80 import javax.wsdl.extensions.UnknownExtensibilityElement; 81 import javax.wsdl.extensions.mime.MIMEMultipartRelated; 82 import javax.wsdl.extensions.soap.SOAPBody; 83 import javax.xml.namespace.QName ; 84 import javax.xml.rpc.holders.BooleanHolder ; 85 import java.io.File ; 86 import java.io.IOException ; 87 import java.net.MalformedURLException ; 88 import java.net.URL ; 89 import java.util.HashMap ; 90 import java.util.Iterator ; 91 import java.util.List ; 92 import java.util.Map ; 93 import java.util.StringTokenizer ; 94 import java.util.Vector ; 95 96 public class Utils extends org.jboss.axis.wsdl.symbolTable.Utils 97 { 98 101 public static String holder(MimeInfo mimeInfo, TypeEntry type, Emitter emitter) 102 { 103 String mimeType = mimeInfo == null ? null : mimeInfo.getType(); 104 String mimeDimensions = mimeInfo == null ? "" : mimeInfo.getDimensions(); 105 106 if (mimeType != null) 108 { 109 if (mimeType.equals("image/gif") || 110 mimeType.equals("image/jpeg")) 111 { 112 return "org.jboss.axis.holders.ImageHolder" + mimeDimensions; 113 } 114 else if (mimeType.equals("text/plain")) 115 { 116 return "javax.xml.rpc.holders.StringHolder" + mimeDimensions; 117 } 118 else if (mimeType.startsWith("multipart/")) 119 { 120 return "org.jboss.axis.holders.MimeMultipartHolder" + mimeDimensions; 121 } 122 else if (mimeType.startsWith("application/octetstream") 123 || mimeType.startsWith("application/octet-stream")) 124 { 125 return "org.jboss.axis.holders.OctetStreamHolder" + mimeDimensions; 126 } 127 else if (mimeType.equals("text/xml") || 128 mimeType.equals("application/xml")) 129 { 130 return "org.jboss.axis.holders.SourceHolder" + mimeDimensions; 131 } 132 } 133 134 String typeValue = type.getName(); 135 136 if (typeValue.equals("byte[]")) 138 { 139 return "javax.xml.rpc.holders.ByteArrayHolder"; 140 } 141 else if (typeValue.endsWith("[]")) 143 { 144 String name = emitter.getJavaName(type.getQName()); 145 name = JavaUtils.replace(name, "[]", "Array"); 148 name = addPackageName(name, "holders"); 149 return name + "Holder"; 150 } 151 else if (typeValue.equals("String")) 153 { 154 return "javax.xml.rpc.holders.StringHolder"; 155 } 156 else if (typeValue.equals("java.lang.String")) 157 { 158 return "javax.xml.rpc.holders.StringHolder"; 159 } 160 else if (typeValue.equals("Object")) 162 { 163 return "javax.xml.rpc.holders.ObjectHolder"; 164 } 165 else if (typeValue.equals("java.lang.Object")) 166 { 167 return "javax.xml.rpc.holders.ObjectHolder"; 168 } 169 else if (typeValue.equals("int") 171 || typeValue.equals("long") 172 || typeValue.equals("short") 173 || typeValue.equals("float") 174 || typeValue.equals("double") 175 || typeValue.equals("boolean") 176 || typeValue.equals("byte")) 177 { 178 return "javax.xml.rpc.holders." + capitalizeFirstChar(typeValue) + "Holder"; 179 } 180 else if (typeValue.startsWith("java.lang.")) 182 { 183 return "javax.xml.rpc.holders" + 184 typeValue.substring(typeValue.lastIndexOf(".")) + 185 "WrapperHolder"; 186 } 187 else if (typeValue.indexOf(".") < 0) 188 { 189 return "javax.xml.rpc.holders" + 190 typeValue + 191 "WrapperHolder"; 192 } 193 else if (typeValue.equals("java.math.BigDecimal")) 196 { 197 return "javax.xml.rpc.holders.BigDecimalHolder"; 198 } 199 else if (typeValue.equals("java.math.BigInteger")) 200 { 201 return "javax.xml.rpc.holders.BigIntegerHolder"; 202 } 203 else if (typeValue.equals("java.util.Date")) 204 { 205 return "org.jboss.axis.holders.DateHolder"; 206 } 207 else if (typeValue.equals("java.util.Calendar")) 208 { 209 return "javax.xml.rpc.holders.CalendarHolder"; 210 } 211 else if (typeValue.equals("javax.xml.namespace.QName")) 212 { 213 return "javax.xml.rpc.holders.QNameHolder"; 214 } 215 else if (typeValue.equals("javax.activation.DataHandler")) 216 { 217 return "org.jboss.axis.holders.DataHandlerHolder"; 218 } 219 else if (typeValue.startsWith("org.jboss.axis.types.")) 221 { 222 int i = typeValue.lastIndexOf('.'); 223 String t = typeValue.substring(i + 1); 224 return "org.jboss.axis.holders." + t + "Holder"; 225 } 226 else 229 { 230 return addPackageName(typeValue, "holders") + "Holder"; 231 } 232 } 234 241 public static String addPackageName(String className, String newPkg) 242 { 243 int index = className.lastIndexOf("."); 244 if (index >= 0) 245 { 246 return className.substring(0, index) 247 + "." + newPkg 248 + className.substring(index); 249 } 250 else 251 { 252 return newPkg + "." + className; 253 } 254 } 255 256 264 public static String getFullExceptionName(Message faultMessage, 265 SymbolTable symbolTable) 266 { 267 MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); 268 return (String )me.getDynamicVar(JavaGeneratorFactory.EXCEPTION_CLASS_NAME); 269 } 271 278 public static QName getFaultDataType(Message faultMessage, 279 SymbolTable symbolTable) 280 { 281 MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); 282 return (QName )me.getDynamicVar(JavaGeneratorFactory.EXCEPTION_DATA_TYPE); 283 } 285 292 public static boolean isFaultComplex(Message faultMessage, 293 SymbolTable symbolTable) 294 { 295 MessageEntry me = symbolTable.getMessageEntry(faultMessage.getQName()); 296 Boolean ret = (Boolean )me.getDynamicVar(JavaGeneratorFactory.COMPLEX_TYPE_FAULT); 297 if (ret != null) 298 { 299 return ret.booleanValue(); 300 } 301 else 302 { 303 return false; 304 } 305 } 307 314 public static Vector getEnumerationBaseAndValues(Node node, SymbolTable symbolTable) 315 { 316 if (node == null) 317 { 318 return null; 319 } 320 321 QName nodeKind = Utils.getNodeQName(node); 323 if (nodeKind != null && 324 nodeKind.getLocalPart().equals("element") && 325 Constants.isSchemaXSD(nodeKind.getNamespaceURI())) 326 { 327 NodeList children = node.getChildNodes(); 328 Node simpleNode = null; 329 for (int j = 0; j < children.getLength() && simpleNode == null; j++) 330 { 331 QName simpleKind = Utils.getNodeQName(children.item(j)); 332 if (simpleKind != null && 333 simpleKind.getLocalPart().equals("simpleType") && 334 Constants.isSchemaXSD(simpleKind.getNamespaceURI())) 335 { 336 simpleNode = children.item(j); 337 node = simpleNode; 338 } 339 } 340 } 341 nodeKind = Utils.getNodeQName(node); 343 if (nodeKind != null && 344 nodeKind.getLocalPart().equals("simpleType") && 345 Constants.isSchemaXSD(nodeKind.getNamespaceURI())) 346 { 347 348 NodeList children = node.getChildNodes(); 351 Node restrictionNode = null; 352 for (int j = 0; j < children.getLength() && restrictionNode == null; j++) 353 { 354 QName restrictionKind = Utils.getNodeQName(children.item(j)); 355 if (restrictionKind != null && 356 restrictionKind.getLocalPart().equals("restriction") && 357 Constants.isSchemaXSD(restrictionKind.getNamespaceURI())) 358 restrictionNode = children.item(j); 359 } 360 361 TypeEntry baseEType = null; 365 if (restrictionNode != null) 366 { 367 QName baseType = Utils.getTypeQName(restrictionNode, new BooleanHolder (), false); 368 baseEType = symbolTable.getType(baseType); 369 if (baseEType != null) 370 { 371 String javaName = baseEType.getName(); 372 if (javaName.equals("boolean") || 373 !SchemaUtils.isSimpleSchemaType(baseEType.getQName())) 374 { 375 baseEType = null; 376 } 377 } 378 } 379 380 if (baseEType != null && restrictionNode != null) 382 { 383 384 Vector v = new Vector (); 385 NodeList enums = restrictionNode.getChildNodes(); 386 for (int i = 0; i < enums.getLength(); i++) 387 { 388 QName enumKind = Utils.getNodeQName(enums.item(i)); 389 if (enumKind != null && 390 enumKind.getLocalPart().equals("enumeration") && 391 Constants.isSchemaXSD(enumKind.getNamespaceURI())) 392 { 393 394 Node enumNode = enums.item(i); 396 String value = Utils.getAttribute(enumNode, "value"); 397 if (value != null) 398 { 399 v.add(value); 400 } 401 } 402 } 403 404 if (v.isEmpty()) return null; 406 407 v.add(0, baseEType); 409 return v; 410 } 411 } 412 return null; 413 } 414 415 418 public static String capitalizeFirstChar(String name) 419 { 420 if (name == null || name.equals("")) 421 return name; 422 423 char start = name.charAt(0); 424 425 if (Character.isLowerCase(start)) 426 { 427 start = Character.toUpperCase(start); 428 return start + name.substring(1); 429 } 430 return name; 431 } 433 436 public static String addUnderscore(String name) 437 { 438 if (name == null || name.equals("")) 439 return name; 440 return "_" + name; 441 } 442 443 446 public static String xmlNameToJava(String name) 447 { 448 return JavaUtils.xmlNameToJava(name); 453 } 454 455 458 public static String xmlNameToJavaClass(String name) 459 { 460 return capitalizeFirstChar(xmlNameToJava(name)); 461 } 462 463 public static String makePackageName(String namespace) 464 { 465 String hostname = null; 466 String path = ""; 467 468 try 470 { 471 URL u = new URL (namespace); 472 hostname = u.getHost(); 473 path = u.getPath(); 474 } 475 catch (MalformedURLException e) 476 { 477 if (namespace.indexOf(":") > -1) 478 { 479 hostname = namespace.substring(namespace.indexOf(":") + 1); 480 if (hostname.indexOf("/") > -1) 481 hostname = hostname.substring(0, hostname.indexOf("/")); 482 } 483 else 484 { 485 hostname = namespace; 486 } 487 } 488 489 if (hostname == null) 491 { 492 return null; 493 } 494 495 hostname = hostname.replace('-', '_'); 497 path = path.replace('-', '_'); 498 499 if (path.length() > 0 && path.charAt(path.length() - 1) == '/') 501 { 502 path = path.substring(0, path.length() - 1); 503 } 504 505 StringTokenizer st = new StringTokenizer (hostname, ".:"); 507 String [] words = new String [st.countTokens()]; 508 for (int i = 0; i < words.length; ++i) 509 words[i] = st.nextToken(); 510 511 StringBuffer sb = new StringBuffer (namespace.length()); 512 for (int i = words.length - 1; i >= 0; --i) 513 { 514 addWordToPackageBuffer(sb, words[i], (i == words.length - 1)); 515 } 516 517 StringTokenizer st2 = new StringTokenizer (path, "/"); 519 while (st2.hasMoreTokens()) 520 { 521 addWordToPackageBuffer(sb, st2.nextToken(), false); 522 } 523 return sb.toString(); 524 } 525 526 535 private static void addWordToPackageBuffer(StringBuffer sb, String word, boolean firstWord) 536 { 537 if (JavaUtils.isJavaKeyword(word)) 538 { 539 word = JavaUtils.makeNonJavaKeyword(word); 540 } 541 if (!firstWord) 543 sb.append('.'); 544 545 if (Character.isDigit(word.charAt(0))) 547 sb.append('_'); 548 549 if (word.indexOf('.') != -1) 551 { 552 char[] buf = word.toCharArray(); 553 for (int i = 0; i < word.length(); i++) 554 { 555 if (buf[i] == '.') 556 { 557 buf[i] = '_'; 558 } 559 } 560 word = new String (buf); 561 } 562 sb.append(word); 563 } 564 565 568 public static String getJavaLocalName(String fullName) 569 { 570 return fullName.substring(fullName.lastIndexOf('.') + 1); 571 } 573 576 public static String getJavaPackageName(String fullName) 577 { 578 if (fullName.lastIndexOf('.') > 0) 579 { 580 return fullName.substring(0, fullName.lastIndexOf('.')); 581 } 582 else 583 { 584 return ""; 585 } 586 } 588 591 public static boolean fileExists(String name, String namespace, 592 Namespaces namespaces) throws IOException  593 { 594 String packageName = namespaces.getAsDir(namespace); 595 String fullName = packageName + name; 596 return new File (fullName).exists(); 597 } 599 602 private static HashMap TYPES = new HashMap (7); 603 604 static 605 { 606 TYPES.put("int", "java.lang.Integer"); 607 TYPES.put("float", "java.lang.Float"); 608 TYPES.put("boolean", "java.lang.Boolean"); 609 TYPES.put("double", "java.lang.Double"); 610 TYPES.put("byte", "java.lang.Byte"); 611 TYPES.put("short", "java.lang.Short"); 612 TYPES.put("long", "java.lang.Long"); 613 } 614 615 618 public static String wrapPrimitiveType(TypeEntry type, String var) 619 { 620 String objType = type == null ? null : (String )TYPES.get(type.getName()); 621 if (objType != null) 622 { 623 return "new " + objType + "(" + var + ")"; 624 } 625 else if (type != null && 626 type.getName().equals("byte[]") && 627 type.getQName().getLocalPart().equals("hexBinary")) 628 { 629 return "new org.jboss.axis.types.HexBinary(" + var + ")"; 631 } 632 else 633 { 634 return var; 635 } 636 } 638 642 public static String getResponseString(TypeEntry type, MimeInfo mimeInfo, 643 String var) 644 { 645 String mimeType = mimeInfo == null ? null : mimeInfo.getType(); 646 String mimeDimensions = mimeInfo == null ? "" : mimeInfo.getDimensions(); 647 if (type == null) 648 { 649 return ";"; 650 } 651 else if (mimeType != null) 652 { 653 if (mimeType.equals("image/jpeg")) 654 { 655 return "(java.awt.Image" + mimeDimensions + ") " + var + ";"; 656 } 657 else if (mimeType.equals("text/plain")) 658 { 659 return "(java.lang.String" + mimeDimensions + ") " + var + ";"; 660 } 661 else if (mimeType.equals("text/xml") || 662 mimeType.equals("application/xml")) 663 { 664 return "(javax.xml.transform.Source" + mimeDimensions + ") " + var + ";"; 665 } 666 else if (mimeType.startsWith("multipart/")) 667 { 668 return "(javax.mail.internet.MimeMultipart" + mimeDimensions + ") " + var + ";"; 669 } 670 else if (mimeType.startsWith("application/octetstream")) 671 { 672 return "(org.jboss.axis.attachments.OctetStream" + mimeDimensions + ") " + var + ";"; 673 } 674 else 675 { 676 return "(" + type.getName() + ") " + var + ";"; 677 } 678 } 679 else 680 { 681 String objType = (String )TYPES.get(type.getName()); 682 if (objType != null) 683 { 684 return "((" + objType + ") " + var + ")." + type.getName() + "Value();"; 685 } 686 else 687 { 688 return "(" + type.getName() + ") " + var + ";"; 689 } 690 } 691 } 693 public static boolean isPrimitiveType(TypeEntry type) 694 { 695 return TYPES.get(type.getName()) != null; 696 } 698 707 public static QName getOperationQName(BindingOperation bindingOper, 708 BindingEntry bEntry, 709 SymbolTable symbolTable) 710 { 711 712 Operation operation = bindingOper.getOperation(); 713 String operationName = operation.getName(); 714 715 if (bEntry.getBindingStyle() == Style.DOCUMENT && 721 symbolTable.isWrapped()) 722 { 723 Input input = operation.getInput(); 724 if (input != null) 725 { 726 Map parts = input.getMessage().getParts(); 727 if (parts != null && !parts.isEmpty()) 728 { 729 Iterator i = parts.values().iterator(); 730 Part p = (Part)i.next(); 731 return p.getElementName(); 732 } 733 } 734 } 735 736 String ns = null; 737 738 BindingInput bindInput = bindingOper.getBindingInput(); 742 if (bindInput != null) 743 { 744 Iterator it = bindInput.getExtensibilityElements().iterator(); 745 while (it.hasNext()) 746 { 747 ExtensibilityElement elem = (ExtensibilityElement)it.next(); 748 if (elem instanceof SOAPBody) 749 { 750 SOAPBody body = (SOAPBody)elem; 751 ns = body.getNamespaceURI(); 752 break; 753 } 754 else if (elem instanceof MIMEMultipartRelated) 755 { 756 Object part = null; 757 javax.wsdl.extensions.mime.MIMEMultipartRelated mpr = 758 (javax.wsdl.extensions.mime.MIMEMultipartRelated)elem; 759 List l = mpr.getMIMEParts(); 760 for (int j = 0; l != null && j < l.size() && part == null; j++) 761 { 762 javax.wsdl.extensions.mime.MIMEPart mp = (javax.wsdl.extensions.mime.MIMEPart)l.get(j); 763 List ll = mp.getExtensibilityElements(); 764 for (int k = 0; ll != null && k < ll.size() && part == null; k++) 765 { 766 part = ll.get(k); 767 if (part instanceof SOAPBody) 768 { 769 SOAPBody body = (SOAPBody)part; 770 ns = body.getNamespaceURI(); 771 break; 772 } 773 else 774 { 775 part = null; 776 } 777 } 778 } 779 } 780 else if (elem instanceof UnknownExtensibilityElement) 781 { 782 UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement)elem; 784 QName name = unkElement.getElementType(); 785 if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) && 786 name.getLocalPart().equals("body")) 787 { 788 ns = unkElement.getElement().getAttribute("namespace"); 789 } 790 } 791 } 792 } 793 794 if (ns == null) 799 { 800 ns = ""; 801 } 802 803 return new QName (ns, operationName); 804 } 805 806 810 public static String getNewQName(javax.xml.namespace.QName qname) 811 { 812 return "new javax.xml.namespace.QName(\"" + 813 qname.getNamespaceURI() + "\", \"" + 814 qname.getLocalPart() + "\")"; 815 } 816 817 822 public static String getParameterTypeName(Parameter parm) 823 { 824 String ret; 825 if (parm.getMIMEInfo() == null) 826 { 827 ret = parm.getType().getName(); 828 } 829 else 830 { 831 String mime = parm.getMIMEInfo().getType(); 832 ret = JavaUtils.mimeToJava(mime); 833 if (ret == null) 834 { 835 ret = parm.getType().getName(); 836 } 837 else 838 { 839 ret += parm.getMIMEInfo().getDimensions(); 840 } 841 } 842 return ret; 843 } 845 852 public static QName getXSIType(Parameter param) 853 { 854 if (param.getMIMEInfo() != null) 855 { 856 return getMIMETypeQName(param.getMIMEInfo().getType()); 857 } 858 return getXSIType(param.getType()); 859 } 861 868 public static QName getXSIType(TypeEntry te) 869 { 870 QName xmlType = null; 871 872 if (te != null && 875 te instanceof Element && 876 te.getRefType() != null) 877 { 878 te = te.getRefType(); 879 } 880 if (te != null && 890 te instanceof CollectionTE && 891 te.getRefType() != null) 892 { 893 te = te.getRefType(); 894 } 895 if (te != null) 896 { 897 xmlType = te.getQName(); 898 } 899 return xmlType; 900 } 901 902 908 public static QName getMIMETypeQName(String mimeName) 909 { 910 if ("text/plain".equals(mimeName)) 911 { 912 return Constants.MIME_PLAINTEXT; 913 } 914 else if ("image/gif".equals(mimeName) || "image/jpeg".equals(mimeName)) 915 { 916 return Constants.MIME_IMAGE; 917 } 918 else if ("text/xml".equals(mimeName) || "application/xml".equals(mimeName)) 919 { 920 return Constants.MIME_SOURCE; 921 } 922 else if ("application/octetstream".equals(mimeName)) 923 { 924 return Constants.MIME_OCTETSTREAM; 925 } 926 else if (mimeName != null && mimeName.startsWith("multipart/")) 927 { 928 return Constants.MIME_MULTIPART; 929 } 930 else 931 { 932 return null; 933 } 934 } 936 937 940 public static boolean hasMIME(BindingEntry bEntry) 941 { 942 List operations = bEntry.getBinding().getBindingOperations(); 943 for (int i = 0; i < operations.size(); ++i) 944 { 945 BindingOperation operation = (BindingOperation)operations.get(i); 946 if (hasMIME(bEntry, operation)) 947 { 948 return true; 949 } 950 } 951 return false; 952 } 954 957 public static boolean hasMIME(BindingEntry bEntry, BindingOperation operation) 958 { 959 Parameters parameters = 960 bEntry.getParameters(operation.getOperation()); 961 if (parameters != null) 962 { 963 for (int idx = 0; idx < parameters.list.size(); ++idx) 964 { 965 Parameter p = (Parameter)parameters.list.get(idx); 966 if (p.getMIMEInfo() != null) 967 { 968 return true; 969 } 970 } 971 } 972 return false; 973 } 975 private static HashMap constructorMap = new HashMap (50); 976 private static HashMap constructorThrowMap = new HashMap (50); 977 978 static 979 { 980 constructorMap.put("int", "0"); 985 constructorMap.put("float", "0"); 986 constructorMap.put("boolean", "true"); 987 constructorMap.put("double", "0"); 988 constructorMap.put("byte", "(byte)0"); 989 constructorMap.put("short", "(short)0"); 990 constructorMap.put("long", "0"); 991 constructorMap.put("java.lang.Boolean", "new java.lang.Boolean(false)"); 992 constructorMap.put("java.lang.Byte", "new java.lang.Byte((byte)0)"); 993 constructorMap.put("java.lang.Double", "new java.lang.Double(0)"); 994 constructorMap.put("java.lang.Float", "new java.lang.Float(0)"); 995 constructorMap.put("java.lang.Integer", "new java.lang.Integer(0)"); 996 constructorMap.put("java.lang.Long", "new java.lang.Long(0)"); 997 constructorMap.put("java.lang.Short", "new java.lang.Short((short)0)"); 998 constructorMap.put("java.math.BigDecimal", "new java.math.BigDecimal(0)"); 999 constructorMap.put("java.math.BigInteger", "new java.math.BigInteger(\"0\")"); 1000 constructorMap.put("java.lang.Object", "new java.lang.String()"); 1001 constructorMap.put("byte[]", "new byte[0]"); 1002 constructorMap.put("java.util.Calendar", "java.util.Calendar.getInstance()"); 1003 constructorMap.put("javax.xml.namespace.QName", "new javax.xml.namespace.QName(\"http://double-double\", \"toil-and-trouble\")"); 1004 constructorMap.put("org.jboss.axis.types.NonNegativeInteger", "new org.jboss.axis.types.NonNegativeInteger(\"0\")"); 1005 constructorMap.put("org.jboss.axis.types.PositiveInteger", "new org.jboss.axis.types.PositiveInteger(\"1\")"); 1006 constructorMap.put("org.jboss.axis.types.NonPositiveInteger", "new org.jboss.axis.types.NonPositiveInteger(\"0\")"); 1007 constructorMap.put("org.jboss.axis.types.NegativeInteger", "new org.jboss.axis.types.NegativeInteger(\"-1\")"); 1008 1009 constructorThrowMap.put("org.jboss.axis.types.Time", "new org.jboss.axis.types.Time(\"15:45:45.275Z\")"); 1011 constructorThrowMap.put("org.jboss.axis.types.UnsignedLong", "new org.jboss.axis.types.UnsignedLong(0)"); 1012 constructorThrowMap.put("org.jboss.axis.types.UnsignedInt", "new org.jboss.axis.types.UnsignedInt(0)"); 1013 constructorThrowMap.put("org.jboss.axis.types.UnsignedShort", "new org.jboss.axis.types.UnsignedShort(0)"); 1014 constructorThrowMap.put("org.jboss.axis.types.UnsignedByte", "new org.jboss.axis.types.UnsignedByte(0)"); 1015 constructorThrowMap.put("org.jboss.axis.types.URI", "new org.jboss.axis.types.URI(\"urn:testing\")"); 1016 constructorThrowMap.put("org.jboss.axis.types.Year", "new org.jboss.axis.types.Year(2000)"); 1017 constructorThrowMap.put("org.jboss.axis.types.Month", "new org.jboss.axis.types.Month(1)"); 1018 constructorThrowMap.put("org.jboss.axis.types.Day", "new org.jboss.axis.types.Day(1)"); 1019 constructorThrowMap.put("org.jboss.axis.types.YearMonth", "new org.jboss.axis.types.YearMonth(2000,1)"); 1020 constructorThrowMap.put("org.jboss.axis.types.MonthDay", "new org.jboss.axis.types.MonthDay(1, 1)"); 1021 } 1022 1023 1024 1041 public static String getConstructorForParam(Parameter param, 1042 SymbolTable symbolTable, 1043 BooleanHolder bThrow) 1044 { 1045 1046 String paramType = param.getType().getName(); 1047 String mimeType = param.getMIMEInfo() == null ? null : param.getMIMEInfo().getType(); 1048 String mimeDimensions = param.getMIMEInfo() == null ? "" : param.getMIMEInfo().getDimensions(); 1049 String out = null; 1050 1051 if (mimeType != null) 1053 { 1054 if (mimeType.equals("image/gif") || 1055 mimeType.equals("image/jpeg")) 1056 { 1057 return "null"; 1058 } 1059 else if (mimeType.equals("text/xml") || 1060 mimeType.equals("application/xml")) 1061 { 1062 if (mimeDimensions.length() <= 0) 1063 return "new javax.xml.transform.stream.StreamSource()"; 1064 else 1065 return "new javax.xml.transform.stream.StreamSource[0]"; 1066 } 1067 else if (mimeType.equals("application/octetstream")) 1068 { 1069 if (mimeDimensions.length() <= 0) 1070 return "new org.jboss.axis.attachments.OctetStream()"; 1071 else 1072 return "new org.jboss.axis.attachments.OctetStream[0]"; 1073 } 1074 else 1075 { 1076 return "new " + Utils.getParameterTypeName(param) + "()"; 1077 } 1078 } 1079 1080 out = (String )constructorMap.get(paramType); 1082 if (out != null) 1083 { 1084 return out; 1085 } 1086 1087 out = (String )constructorThrowMap.get(paramType); 1089 if (out != null) 1090 { 1091 bThrow.value = true; 1092 return out; 1093 } 1094 1095 if (paramType.endsWith("[]")) 1097 { 1098 return "new " + JavaUtils.replace(paramType, "[]", "[0]"); 1099 } 1100 1101 1102 1103 Vector v = Utils.getEnumerationBaseAndValues(param.getType().getNode(), symbolTable); 1105 if (v != null) 1106 { 1107 String enumeration = (String ) 1109 JavaEnumTypeWriter.getEnumValueIds(v).get(0); 1110 return paramType + "." + enumeration; 1111 } 1112 1113 return "new " + paramType + "()"; 1115 1116 } 1117 1118} | Popular Tags |