1 55 56 package org.jboss.axis.wsdl.fromJava; 57 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.Constants; 60 import org.jboss.axis.InternalException; 61 import org.jboss.axis.description.ServiceDesc; 62 import org.jboss.axis.encoding.Serializer; 63 import org.jboss.axis.encoding.SerializerFactory; 64 import org.jboss.axis.encoding.SimpleType; 65 import org.jboss.axis.encoding.TypeMapping; 66 import org.jboss.axis.encoding.ser.BeanSerializerFactory; 67 import org.jboss.axis.encoding.ser.EnumSerializerFactory; 68 import org.jboss.axis.enums.Style; 69 import org.jboss.axis.utils.JavaUtils; 70 import org.jboss.axis.utils.Messages; 71 import org.jboss.axis.utils.XMLUtils; 72 import org.jboss.axis.wsdl.symbolTable.BaseTypeMapping; 73 import org.jboss.axis.wsdl.symbolTable.SymbolTable; 74 import org.jboss.logging.Logger; 75 import org.w3c.dom.Attr ; 76 import org.w3c.dom.Document ; 77 import org.w3c.dom.Element ; 78 import org.w3c.dom.NamedNodeMap ; 79 import org.w3c.dom.Node ; 80 import org.w3c.dom.NodeList ; 81 import org.xml.sax.SAXException ; 82 83 import javax.wsdl.Definition; 84 import javax.wsdl.WSDLException; 85 import javax.xml.namespace.QName ; 86 import javax.xml.parsers.ParserConfigurationException ; 87 import javax.xml.rpc.holders.Holder ; 88 import java.io.IOException ; 89 import java.lang.reflect.Field ; 90 import java.lang.reflect.Modifier ; 91 import java.net.URL ; 92 import java.util.ArrayList ; 93 import java.util.HashMap ; 94 import java.util.Iterator ; 95 import java.util.List ; 96 97 105 public class Types 106 { 107 private static Logger log = Logger.getLogger(Types.class.getName()); 108 109 Definition def; 110 Namespaces namespaces = null; 111 TypeMapping tm; 112 TypeMapping defaultTM; 113 String targetNamespace; 114 Element wsdlTypesElem = null; 115 HashMap schemaTypes = null; 116 HashMap schemaElementNames = null; 117 HashMap schemaUniqueElementNames = null; 118 HashMap wrapperMap = new HashMap (); 119 List stopClasses = null; 120 List beanCompatErrs = new ArrayList (); 121 ServiceDesc serviceDesc = null; 122 123 133 public Types(Definition def, 134 TypeMapping tm, 135 TypeMapping defaultTM, 136 Namespaces namespaces, 137 String targetNamespace, 138 List stopClasses, 139 ServiceDesc serviceDesc) 140 { 141 this.def = def; 142 this.serviceDesc = serviceDesc; 143 createDocumentFragment(); 144 this.tm = tm; 145 this.defaultTM = defaultTM; 146 this.namespaces = namespaces; 147 this.targetNamespace = targetNamespace; 148 this.stopClasses = stopClasses; 149 schemaElementNames = new HashMap (); 150 schemaUniqueElementNames = new HashMap (); 151 schemaTypes = new HashMap (); 152 } 153 154 157 public Namespaces getNamespaces() 158 { 159 return namespaces; 160 } 161 162 167 public void loadInputSchema(String inputSchema) 168 throws IOException , WSDLException, SAXException , 169 ParserConfigurationException 170 { 171 Document doc = XMLUtils.newDocument(inputSchema); 173 174 Element root = doc.getDocumentElement(); 176 if (root.getLocalName().equals("schema") && 177 Constants.isSchemaXSD(root.getNamespaceURI())) 178 { 179 Node schema = docHolder.importNode(root, true); 180 if (null == wsdlTypesElem) 181 { 182 writeWsdlTypesElement(); 183 } 184 wsdlTypesElem.appendChild(schema); 185 186 BaseTypeMapping btm = 188 new BaseTypeMapping() 189 { 190 public String getBaseName(QName qNameIn) 191 { 192 QName qName = new QName (qNameIn.getNamespaceURI(), 193 qNameIn.getLocalPart()); 194 Class cls = defaultTM.getClassForQName(qName); 195 if (cls == null) 196 return null; 197 else 198 return JavaUtils.getTextClassName(cls.getName()); 199 } 200 }; 201 SymbolTable symbolTable = new SymbolTable(btm, 202 true, false, false); 203 symbolTable.populateTypes(new URL (inputSchema), doc); 204 205 processSymTabEntries(symbolTable); 206 } 207 else 208 { 209 ; 212 } 213 } 214 215 222 private void processSymTabEntries(SymbolTable symbolTable) 223 { 224 Iterator iterator = symbolTable.getElementIndex().keySet().iterator(); 225 while (iterator.hasNext()) 226 { 227 QName name = (QName )iterator.next(); 228 addToElementsList(name); 229 } 230 iterator = symbolTable.getTypeIndex().keySet().iterator(); 231 while (iterator.hasNext()) 232 { 233 QName name = (QName )iterator.next(); 234 addToTypesList(name); 235 } 236 } 237 238 243 public void loadInputTypes(String inputWSDL) 244 throws IOException , WSDLException, 245 SAXException , ParserConfigurationException 246 { 247 248 Document doc = XMLUtils.newDocument(inputWSDL); 250 251 NodeList elements = doc.getChildNodes(); 253 if (elements.getLength() > 0 && 254 elements.item(0).getLocalName().equals("definitions")) 255 { 256 elements = elements.item(0).getChildNodes(); 257 for (int i = 0; 258 i < elements.getLength() && wsdlTypesElem == null; 259 i++) 260 { 261 Node node = elements.item(i); 262 if (node.getLocalName() != null && 263 node.getLocalName().equals("types")) 264 { 265 wsdlTypesElem = (Element )node; 266 } 267 } 268 } 269 270 if (wsdlTypesElem == null) 272 { 273 return; 274 } 275 276 wsdlTypesElem = 278 (Element )docHolder.importNode(wsdlTypesElem, true); 279 docHolder.appendChild(wsdlTypesElem); 280 281 BaseTypeMapping btm = 283 new BaseTypeMapping() 284 { 285 public String getBaseName(QName qNameIn) 286 { 287 QName qName = new QName (qNameIn.getNamespaceURI(), 288 qNameIn.getLocalPart()); 289 Class cls = defaultTM.getClassForQName(qName); 290 if (cls == null) 291 return null; 292 else 293 return JavaUtils.getTextClassName(cls.getName()); 294 } 295 }; 296 SymbolTable symbolTable = new SymbolTable(btm, 297 true, false, false); 298 symbolTable.populate(null, doc); 299 300 processSymTabEntries(symbolTable); 301 } 302 303 313 public QName writeTypeForPart(Class type, QName qname) throws AxisFault 314 { 315 323 if (type.getName().equals("void")) 324 { 325 return null; 326 } 327 328 if (Holder .class.isAssignableFrom(type)) 329 { 330 type = JavaUtils.getHolderValueType(type); 331 } 332 333 if (qname == null || 335 (Constants.isSOAP_ENC(qname.getNamespaceURI()) && 336 "Array".equals(qname.getLocalPart()))) 337 { 338 qname = getTypeQName(type); 339 if (qname == null) 340 { 341 throw new AxisFault("Class:" + type.getName()); 342 } 343 } 344 345 if (!makeTypeElement(type, qname, null)) 346 { 347 qname = Constants.XSD_ANYTYPE; 348 } 349 350 return qname; 351 } 352 353 361 public QName writeElementForPart(Class type, QName qname) throws AxisFault 362 { 363 371 if (type.getName().equals("void")) 372 { 373 return null; 374 } 375 376 if (Holder .class.isAssignableFrom(type)) 377 { 378 type = JavaUtils.getHolderValueType(type); 379 } 380 381 if (qname == null || 383 (Constants.isSOAP_ENC(qname.getNamespaceURI()) && 384 "Array".equals(qname.getLocalPart()))) 385 { 386 qname = getTypeQName(type); 387 if (qname == null) 388 { 389 throw new AxisFault("Class:" + type.getName()); 390 } 391 } 392 393 String nsURI = qname.getNamespaceURI(); 395 if (Constants.isSchemaXSD(nsURI) || 396 (Constants.isSOAP_ENC(nsURI) && 397 !"Array".equals(qname.getLocalPart()))) 398 { 399 return null; 400 } 401 402 if (wsdlTypesElem == null) 404 { 405 writeWsdlTypesElement(); 406 } 407 408 if (writeTypeAsElement(type, qname) == null) 410 { 411 qname = null; 412 } 413 return qname; 414 } 415 416 433 public Element writeWrapperElement(QName qname, 434 boolean request, 435 boolean hasParams) throws AxisFault 436 { 437 if (wsdlTypesElem == null) 439 { 440 writeWsdlTypesElement(); 441 } 442 443 writeTypeNamespace(qname); 445 446 Element wrapperElement = docHolder.createElement("element"); 448 writeSchemaElement(qname, wrapperElement); 449 wrapperElement.setAttribute("name", qname.getLocalPart()); 450 451 Element complexType = docHolder.createElement("complexType"); 453 wrapperElement.appendChild(complexType); 454 455 if (hasParams) 458 { 459 Element sequence = docHolder.createElement("sequence"); 460 complexType.appendChild(sequence); 461 return sequence; 462 } 463 464 return null; 465 } 466 467 475 public void writeWrappedParameter(Element sequence, String name, 476 QName type, Class javaType) 477 throws AxisFault 478 { 479 480 if (javaType == void.class) 481 { 482 return; 483 } 484 485 if (type == null) 486 { 487 type = writeTypeForPart(javaType, type); 488 } 489 490 if (type == null) 491 { 492 } 494 495 Element childElem; 496 if (isAnonymousType(type)) 497 { 498 childElem = createElementWithAnonymousType(name, javaType, 499 false, docHolder); 500 } 501 else 502 { 503 childElem = docHolder.createElement("element"); 505 childElem.setAttribute("name", name); 506 507 String prefix = namespaces.getCreatePrefix(type.getNamespaceURI()); 508 String prefixedName = prefix + ":" + type.getLocalPart(); 509 childElem.setAttribute("type", prefixedName); 510 } 511 sequence.appendChild(childElem); 512 } 513 514 private boolean isAnonymousType(QName type) 515 { 516 return type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) != -1; 517 } 518 519 525 private QName writeTypeAsElement(Class type, QName qName) throws AxisFault 526 { 527 if (qName == null || 528 Constants.equals(Constants.SOAP_ARRAY, qName)) 529 { 530 qName = getTypeQName(type); 531 } 532 QName typeQName = writeTypeNamespace(type, qName); 533 534 String elementType = writeType(type, qName); 535 if (elementType != null) 536 { 537 Element element = createElementDecl(qName.getLocalPart(), type, qName, isNullable(type), false); 538 if (element != null) 539 writeSchemaElement(typeQName, element); 540 return qName; 541 } 542 return null; 543 } 544 545 553 private QName writeTypeNamespace(Class type, QName qName) 554 { 555 if (qName == null) 556 { 557 qName = getTypeQName(type); 558 } 559 writeTypeNamespace(qName); 560 return qName; 561 } 562 563 568 private void writeTypeNamespace(QName qName) 569 { 570 if (qName != null && !qName.getNamespaceURI().equals("")) 571 { 572 String pref = def.getPrefix(qName.getNamespaceURI()); 573 if (pref == null) 574 def.addNamespace(namespaces.getCreatePrefix(qName.getNamespaceURI()), 575 qName.getNamespaceURI()); 576 577 } 578 } 579 580 586 public QName getTypeQName(Class javaType) 587 { 588 QName qName = null; 589 590 QName dQName = null; 592 if (defaultTM != null) 593 { 594 dQName = defaultTM.getTypeQName(javaType); 595 } 596 if (tm != null) 597 { 598 qName = tm.getTypeQName(javaType); 599 } 600 if (qName == null) 601 { 602 qName = dQName; 603 } 604 else if (qName != null && qName != dQName) 605 { 606 if (Constants.isSchemaXSD(qName.getNamespaceURI())) 610 { 611 qName = dQName; 612 } 613 } 614 615 if (javaType.isArray() && 619 qName != null && 620 Constants.equals(Constants.SOAP_ARRAY, qName)) 621 { 622 Class componentType = javaType.getComponentType(); 623 QName cqName = getTypeQName(componentType); 628 if (targetNamespace.equals(cqName.getNamespaceURI())) 629 { 630 qName = new QName (targetNamespace, 631 "ArrayOf" + cqName.getLocalPart()); 632 } 633 else 634 { 635 String pre = namespaces.getCreatePrefix(cqName.getNamespaceURI()); 636 qName = new QName (targetNamespace, 637 "ArrayOf_" + pre + "_" + cqName.getLocalPart()); 638 } 639 return qName; 640 } 641 642 if (qName == null) 645 { 646 String pkg = getPackageNameFromFullName(javaType.getName()); 647 String lcl = getLocalNameFromFullName(javaType.getName()); 648 649 String ns = namespaces.getCreate(pkg); 650 namespaces.getCreatePrefix(ns); 651 String localPart = lcl.replace('$', '_'); 652 qName = new QName (ns, localPart); 653 } 654 655 return qName; 656 } 657 658 666 public String getQNameString(QName qname) 667 { 668 String prefix = namespaces.getCreatePrefix(qname.getNamespaceURI()); 669 return prefix + ":" + qname.getLocalPart(); 670 } 671 672 678 public static String getPackageNameFromFullName(String full) 679 { 680 if (full.lastIndexOf('.') < 0) 681 return ""; 682 else 683 return full.substring(0, full.lastIndexOf('.')); 684 } 685 686 692 public static String getLocalNameFromFullName(String full) 693 { 694 if (full.lastIndexOf('.') < 0) 695 return full; 696 else 697 return full.substring(full.lastIndexOf('.') + 1); 698 } 699 700 707 public void writeSchemaElement(QName qName, Element element) 708 throws AxisFault 709 { 710 if (wsdlTypesElem == null) 711 { 712 try 713 { 714 writeWsdlTypesElement(); 715 } 716 catch (Exception e) 717 { 718 log.error(e); 719 return; 720 } 721 } 722 String namespaceURI = qName.getNamespaceURI(); 723 if (namespaceURI == null || namespaceURI.equals("")) 724 { 725 throw new AxisFault(Constants.FAULT_SERVER_GENERAL, 726 Messages.getMessage("noNamespace00", 727 qName.toString()), 728 null, null); 729 } 730 731 Element schemaElem = null; 732 NodeList nl = wsdlTypesElem.getChildNodes(); 733 for (int i = 0; i < nl.getLength(); i++) 734 { 735 NamedNodeMap attrs = nl.item(i).getAttributes(); 736 if (attrs != null) 737 { 738 for (int n = 0; n < attrs.getLength(); n++) 739 { 740 Attr a = (Attr )attrs.item(n); 741 if (a.getName().equals("targetNamespace") && 742 a.getValue().equals(namespaceURI)) 743 schemaElem = (Element )nl.item(i); 744 } 745 } 746 } 747 if (schemaElem == null) 748 { 749 schemaElem = docHolder.createElement("schema"); 750 wsdlTypesElem.appendChild(schemaElem); 751 schemaElem.setAttribute("xmlns", Constants.URI_DEFAULT_SCHEMA_XSD); 752 schemaElem.setAttribute("targetNamespace", namespaceURI); 753 754 if (serviceDesc.getStyle() == Style.RPC) 756 { 757 Element importElem = docHolder.createElement("import"); 758 schemaElem.appendChild(importElem); 759 importElem.setAttribute("namespace", Constants.URI_DEFAULT_SOAP_ENC); 760 } 761 762 writeTypeNamespace(qName); 763 } 764 schemaElem.appendChild(element); 765 } 766 767 770 private void writeWsdlTypesElement() 771 { 772 if (wsdlTypesElem == null) 773 { 774 wsdlTypesElem = 776 docHolder.createElementNS(Constants.NS_URI_WSDL11, "types"); 777 wsdlTypesElem.setPrefix(Constants.NS_PREFIX_WSDL); 778 } 779 } 780 781 791 public String writeType(Class type) throws AxisFault 792 { 793 return writeType(type, null); 794 } 795 796 807 public String writeType(Class type, QName qName) throws AxisFault 808 { 809 if (qName == null || 811 Constants.equals(Constants.SOAP_ARRAY, qName)) 812 { 813 qName = getTypeQName(type); 814 } 815 816 if (!makeTypeElement(type, qName, null)) 817 { 818 return null; 819 } 820 return getQNameString(qName); 821 } 822 823 public Element createArrayElement(String componentTypeName) 824 { 825 Element complexType = docHolder.createElement("complexType"); 827 828 Element complexContent = docHolder.createElement("complexContent"); 829 complexType.appendChild(complexContent); 830 831 Element restriction = docHolder.createElement("restriction"); 832 complexContent.appendChild(restriction); 833 restriction.setAttribute("base", 834 Constants.NS_PREFIX_SOAP_ENC + ":Array"); 835 836 Element attribute = docHolder.createElement("attribute"); 837 restriction.appendChild(attribute); 838 attribute.setAttribute("ref", 839 Constants.NS_PREFIX_SOAP_ENC + ":arrayType"); 840 attribute.setAttribute(Constants.NS_PREFIX_WSDL + ":arrayType", 841 componentTypeName); 842 843 return complexType; 844 } 845 846 850 public static boolean isEnumClass(Class cls) 851 { 852 try 853 { 854 java.lang.reflect.Method m = cls.getMethod("getValue", null); 855 java.lang.reflect.Method m2 = cls.getMethod("toString", null); 856 if (m != null && m2 != null) 857 { 858 java.lang.reflect.Method m3 = 859 cls.getDeclaredMethod("fromString", 860 new Class []{java.lang.String .class}); 861 java.lang.reflect.Method m4 = 862 cls.getDeclaredMethod("fromValue", 863 new Class []{m.getReturnType()}); 864 865 if (m3 != null && 866 Modifier.isStatic(m3.getModifiers()) && 867 Modifier.isPublic(m3.getModifiers()) && 868 m4 != null && 869 Modifier.isStatic(m4.getModifiers()) && 870 Modifier.isPublic(m4.getModifiers())) 871 { 872 try 874 { 875 if (cls.getMethod("setValue", 876 new Class []{m.getReturnType()}) == null) 877 return true; 878 return false; 879 } 880 catch (java.lang.NoSuchMethodException e) 881 { 882 return true; 883 } 884 } 885 } 886 } 887 catch (java.lang.NoSuchMethodException e) 888 { 889 } 890 return false; 891 } 892 893 900 public Element writeEnumType(QName qName, Class cls) 901 throws NoSuchMethodException , IllegalAccessException , AxisFault 902 { 903 904 if (!isEnumClass(cls)) 905 return null; 906 907 java.lang.reflect.Method m = cls.getMethod("getValue", null); 909 Class base = m.getReturnType(); 910 911 Element simpleType = docHolder.createElement("simpleType"); 913 simpleType.setAttribute("name", qName.getLocalPart()); 914 Element restriction = docHolder.createElement("restriction"); 915 simpleType.appendChild(restriction); 916 String baseType = writeType(base, null); 917 restriction.setAttribute("base", baseType); 918 919 Field [] fields = cls.getDeclaredFields(); 921 for (int i = 0; i < fields.length; i++) 922 { 923 Field field = fields[i]; 924 int mod = field.getModifiers(); 925 926 if (Modifier.isPublic(mod) && 929 Modifier.isStatic(mod) && 930 Modifier.isFinal(mod) && 931 field.getType() == base) 932 { 933 Element enumeration = docHolder.createElement("enumeration"); 935 enumeration.setAttribute("value", field.get(null).toString()); 936 restriction.appendChild(enumeration); 937 } 938 } 939 940 return simpleType; 941 } 942 943 949 public Element createElementDecl(String name, 950 Class javaType, 951 QName typeQName, 952 boolean nillable, 953 boolean omittable) throws AxisFault 954 { 955 Element element = docHolder.createElement("element"); 956 957 959 element.setAttribute("name", name); 960 961 if (nillable) 962 element.setAttribute("nillable", "true"); 963 if (omittable) 964 { 965 element.setAttribute("minOccurs", "0"); 966 element.setAttribute("maxOccurs", "1"); 967 } 968 969 makeTypeElement(javaType, typeQName, element); 972 return element; 973 } 974 975 983 public Element createElement(String elementName, 984 String elementType, 985 boolean nullable, 986 boolean omittable, 987 Document docHolder) 988 { 989 Element element = docHolder.createElement("element"); 990 element.setAttribute("name", elementName); 991 if (nullable) 992 element.setAttribute("nillable", "true"); 993 if (omittable) 994 { 995 element.setAttribute("minOccurs", "0"); 996 element.setAttribute("maxOccurs", "1"); 997 } 998 if (elementType != null) 999 element.setAttribute("type", elementType); 1000 return element; 1001 } 1002 1003 1004 1011 public Element createAttributeElement(String elementName, 1012 Class javaType, 1013 QName xmlType, 1014 boolean nullable, 1015 Document docHolder) throws AxisFault 1016 { 1017 Element element = docHolder.createElement("attribute"); 1018 element.setAttribute("name", elementName); 1019 if (nullable) 1020 element.setAttribute("nillable", "true"); 1021 1022 makeTypeElement(javaType, xmlType, element); 1023 return element; 1024 } 1025 1026 1034 boolean isSimpleType(Class type) 1035 { 1036 QName qname = tm.getTypeQName(type); 1037 if (qname == null) 1038 return false; 1040 String nsURI = qname.getNamespaceURI(); 1041 return (Constants.isSchemaXSD(nsURI) || 1042 Constants.isSOAP_ENC(nsURI)); 1043 } 1044 1045 1051 public boolean isAcceptableAsAttribute(Class type) 1052 { 1053 return isSimpleType(type) || 1054 isEnumClass(type) || 1055 implementsSimpleType(type); 1056 } 1057 1058 1064 boolean implementsSimpleType(Class type) 1065 { 1066 Class [] impls = type.getInterfaces(); 1067 for (int i = 0; i < impls.length; i++) 1068 { 1069 if (impls[i] == SimpleType.class) 1070 { 1071 return true; 1072 } 1073 } 1074 return false; 1075 } 1076 1083 1095 1105 private boolean addToTypesList(QName qName) 1106 { 1107 boolean added = false; 1108 ArrayList types = (ArrayList )schemaTypes.get(qName.getNamespaceURI()); 1109 1110 if (Constants.isSchemaXSD(qName.getNamespaceURI()) || 1112 (Constants.isSOAP_ENC(qName.getNamespaceURI()) && 1113 !"Array".equals(qName.getLocalPart()))) 1114 { 1115 writeTypeNamespace(qName); 1117 return false; 1118 } 1119 1120 if (types == null) 1121 { 1122 types = new ArrayList (); 1123 types.add(qName.getLocalPart()); 1124 schemaTypes.put(qName.getNamespaceURI(), types); 1125 added = true; 1126 } 1127 else 1128 { 1129 if (!types.contains(qName.getLocalPart())) 1130 { 1131 types.add(qName.getLocalPart()); 1132 added = true; 1133 } 1134 } 1135 1136 if (added) 1139 { 1140 String prefix = namespaces.getCreatePrefix(qName.getNamespaceURI()); 1141 if (prefix.equals(Constants.NS_PREFIX_SOAP_ENV) || 1142 prefix.equals(Constants.NS_PREFIX_SOAP_ENC) || 1143 prefix.equals(Constants.NS_PREFIX_SCHEMA_XSD) || 1144 prefix.equals(Constants.NS_PREFIX_WSDL) || 1145 prefix.equals(Constants.NS_PREFIX_WSDL_SOAP)) 1146 return false; 1147 else 1148 return true; 1149 } 1150 return false; 1151 } 1152 1153 1162 private boolean addToElementsList(QName qName) 1163 { 1164 if (qName == null) 1165 { 1166 return false; 1167 } 1168 1169 boolean added = false; 1170 ArrayList elements = (ArrayList )schemaElementNames.get(qName.getNamespaceURI()); 1171 if (elements == null) 1172 { 1173 elements = new ArrayList (); 1174 elements.add(qName.getLocalPart()); 1175 schemaElementNames.put(qName.getNamespaceURI(), elements); 1176 added = true; 1177 } 1178 else 1179 { 1180 if (!elements.contains(qName.getLocalPart())) 1181 { 1182 elements.add(qName.getLocalPart()); 1183 added = true; 1184 } 1185 } 1186 return added; 1187 } 1188 1189 1190 1197 public boolean isNullable(Class type) 1198 { 1199 if (type.isPrimitive() || 1200 (type.isArray() && type.getComponentType() == byte.class)) 1201 return false; 1202 else 1203 return true; 1204 } 1205 1206 1207 1213 Document docHolder; 1215 1216 private void createDocumentFragment() 1217 { 1218 try 1219 { 1220 this.docHolder = XMLUtils.newDocument(); 1221 } 1222 catch (ParserConfigurationException e) 1223 { 1224 throw new InternalException(e); 1226 } 1227 } 1228 1229 public void updateNamespaces() 1230 { 1231 Namespaces namespaces = getNamespaces(); 1232 Iterator nspIterator = namespaces.getNamespaces(); 1233 while (nspIterator.hasNext()) 1234 { 1235 String nsp = (String )nspIterator.next(); 1236 String pref = def.getPrefix(nsp); 1237 if (pref == null) 1238 { 1239 def.addNamespace(namespaces.getCreatePrefix(nsp), nsp); 1240 } 1241 } 1242 } 1243 1244 1249 public void insertTypesFragment(Document doc) 1250 { 1251 updateNamespaces(); 1252 if (wsdlTypesElem != null) 1253 { 1254 org.w3c.dom.Node node = doc.importNode(wsdlTypesElem, true); 1256 doc.getDocumentElement(). 1258 insertBefore(node, 1259 doc.getDocumentElement().getFirstChild()); 1260 } 1261 } 1262 1263 1266 public List getStopClasses() 1267 { 1268 return stopClasses; 1269 } 1270 1271 1274 public Element createElement(String elementName) 1275 { 1276 return docHolder.createElement(elementName); 1277 } 1278 1279 1287 public Element createElementWithAnonymousType(String elementName, 1288 Class fieldType, 1289 boolean omittable, 1290 Document ownerDocument) throws AxisFault 1291 { 1292 Element element = docHolder.createElement("element"); 1293 element.setAttribute("name", elementName); 1294 if (isNullable(fieldType)) 1295 element.setAttribute("nillable", "true"); 1296 if (omittable) 1297 { 1298 element.setAttribute("minOccurs", "0"); 1299 element.setAttribute("maxOccurs", "1"); 1300 } 1301 1302 makeTypeElement(fieldType, null, element); 1303 1304 return element; 1305 } 1306 1307 1325 private boolean makeTypeElement(Class type, 1326 QName qName, 1327 Element containingElement) throws AxisFault 1328 { 1329 if (qName == null || 1331 Constants.equals(Constants.SOAP_ARRAY, qName)) 1332 { 1333 qName = getTypeQName(type); 1334 } 1335 1336 boolean anonymous = isAnonymousType(qName); 1337 1338 if (anonymous && containingElement == null) 1340 { 1341 throw new AxisFault(Messages.getMessage("noContainerForAnonymousType", 1342 qName.toString())); 1343 } 1344 1345 if (!addToTypesList(qName)) 1349 { 1350 if (containingElement != null) 1351 containingElement.setAttribute("type", getQNameString(qName)); 1352 return true; 1353 } 1354 1355 Serializer ser = null; 1357 SerializerFactory factory = null; 1358 if (tm != null) 1359 { 1360 factory = (SerializerFactory)tm.getSerializer(type); 1361 } 1362 else 1363 { 1364 factory = (SerializerFactory)defaultTM.getSerializer(type); 1365 } 1366 1367 if (factory == null) 1370 { 1371 if (isEnumClass(type)) 1372 { 1373 factory = new EnumSerializerFactory(type, qName); 1374 } 1375 else if (JavaUtils.isBeanCompatible(type)) 1376 { 1377 factory = new BeanSerializerFactory(type, qName); 1378 } 1379 else 1380 { 1381 return false; 1382 } 1383 } 1384 1385 if (factory != null) 1386 { 1387 ser = (Serializer)factory.getSerializerAs(Constants.AXIS_SAX); 1388 } 1389 1390 if (ser == null) 1392 { 1393 throw new AxisFault(Messages.getMessage("NoSerializer00", type.getName())); 1394 } 1395 1396 Element typeEl; 1397 try 1398 { 1399 typeEl = ser.writeSchema(type, this); 1400 } 1401 catch (Exception e) 1402 { 1403 throw AxisFault.makeFault(e); 1404 } 1405 1406 if (anonymous) 1411 { 1412 containingElement.appendChild(typeEl); 1413 } 1414 else 1415 { 1416 if (typeEl != null) 1417 { 1418 typeEl.setAttribute("name", qName.getLocalPart()); 1419 1420 writeSchemaElement(qName, typeEl); 1422 } 1423 1424 if (containingElement != null) 1425 containingElement.setAttribute("type", getQNameString(qName)); 1426 } 1427 return true; 1428 } 1429} 1430 | Popular Tags |