Attached is a patch that adds some support for xsd:choice elements. Currently, that just means creating getters and setters for everything that may be present. It does not do the ChoiceCompositor stuff that James Yegerlehner proposed, but it does create a base onto which that could be added.
David Altenburg
[EMAIL PROTECTED]
--- SchemaUtils.java.orig Tue Feb 12 15:25:30 2002 +++ SchemaUtils.java Tue Feb 12 15:23:48 2002 @@ -168,29 +168,14 @@ for (int i=0; i < elements.getLength(); i++) { QName elementKind = Utils.getNodeQName(elements.item(i)); if (elementKind != null && - elementKind.getLocalPart().equals("element") && Constants.isSchemaXSD(elementKind.getNamespaceURI())) { - - // Get the name and type qnames. - // The name of the element is the local part of the name's qname. - // The type qname is used to locate the TypeEntry, which is then - // used to retrieve the proper java name of the type. - Node elementNode = elements.item(i); - QName nodeName = Utils.getNodeNameQName(elementNode); - BooleanHolder forElement = new BooleanHolder(); - QName nodeType = Utils.getNodeTypeRefQName(elementNode, forElement); - if (nodeType == null) { // The element may use an anonymous type - nodeType = nodeName; - forElement.value = false; + if ( elementKind.getLocalPart().equals("element")) { + v.addAll(processElementNode(elements.item(i), +symbolTable)); + } else if (elementKind.getLocalPart().equals("choice")) { + Vector choiceElems = processChoiceNode(elements.item(i), +symbolTable); + v.addAll(choiceElems); } - - TypeEntry type = (TypeEntry) symbolTable.getTypeEntry(nodeType, - forElement.value); - if (type != null) { - v.add(type); - v.add(nodeName.getLocalPart()); - } - } + } } return v; } @@ -198,6 +183,106 @@ return null; } + + private static Vector processChoiceNode(Node choiceNode, SymbolTable symbolTable) +{ + Vector v = new Vector(); + NodeList children = choiceNode.getChildNodes(); + for (int j = 0; j < children.getLength(); j++) { + QName subNodeKind = Utils.getNodeQName(children.item(j)); + if (subNodeKind != null && + Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) { + if (subNodeKind.getLocalPart().equals("choice")) { + v.addAll(processChoiceNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("sequence")) { + v.addAll(processSequenceNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("group")) { + v.addAll(processGroupNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("element")) { + v.addAll(processElementNode(children.item(j), symbolTable)); + } + } + } + return v; + } + + private static Vector processSequenceNode(Node sequenceNode, SymbolTable +symbolTable) { + Vector v = new Vector(); + NodeList children = sequenceNode.getChildNodes(); + for (int j = 0; j < children.getLength(); j++) { + QName subNodeKind = Utils.getNodeQName(children.item(j)); + if (subNodeKind != null && + Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) { + if (subNodeKind.getLocalPart().equals("choice")) { + v.addAll(processChoiceNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("sequence")) { + v.addAll(processSequenceNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("group")) { + v.addAll(processGroupNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("element")) { + v.addAll(processElementNode(children.item(j), symbolTable)); + } + } + } + return v; + } + + private static Vector processGroupNode(Node groupNode, SymbolTable symbolTable) { + Vector v = new Vector(); + NodeList children = groupNode.getChildNodes(); + for (int j = 0; j < children.getLength(); j++) { + QName subNodeKind = Utils.getNodeQName(children.item(j)); + if (subNodeKind != null && + Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) { + if (subNodeKind.getLocalPart().equals("choice")) { + v.addAll(processChoiceNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("sequence")) { + v.addAll(processSequenceNode(children.item(j), symbolTable)); + } else if (subNodeKind.getLocalPart().equals("all")) { + v.addAll(processAllNode(children.item(j), symbolTable)); + } + } + } + return v; + } + + private static Vector processAllNode(Node allNode, SymbolTable symbolTable) { + Vector v = new Vector(); + NodeList children = allNode.getChildNodes(); + for (int j = 0; j < children.getLength(); j++) { + QName subNodeKind = Utils.getNodeQName(children.item(j)); + if (subNodeKind != null && + Constants.isSchemaXSD(subNodeKind.getNamespaceURI())) { + if (subNodeKind.getLocalPart().equals("element")) { + v.addAll(processElementNode(children.item(j), symbolTable)); + } + } + } + return v; + } + + + private static Vector processElementNode(Node elementNode, SymbolTable +symbolTable) { + Vector v = new Vector(); + // Get the name and type qnames. + // The name of the element is the local part of the name's qname. + // The type qname is used to locate the TypeEntry, which is then + // used to retrieve the proper java name of the type. + QName nodeName = Utils.getNodeNameQName(elementNode); + BooleanHolder forElement = new BooleanHolder(); + QName nodeType = Utils.getNodeTypeRefQName(elementNode, forElement); + if (nodeType == null) { // The element may use an anonymous type + nodeType = nodeName; + forElement.value = false; + } + + TypeEntry type = (TypeEntry) symbolTable.getTypeEntry(nodeType, +forElement.value); + if (type != null) { + v.add(type); + v.add(nodeName.getLocalPart()); + } + return v; + } + /** * If the specified node represents a supported JAX-RPC complexType/element * which extends another complexType. The Type of the base is returned. @@ -232,7 +317,7 @@ Constants.isSchemaXSD(nodeKind.getNamespaceURI())) { // Under the complexType there could be should be a complexContent & - // extension elements if this is a derived type. + // extension elements if this is a derived type. NodeList children = node.getChildNodes(); Node complexContent = null; Node extension = null; @@ -254,7 +339,7 @@ } } if (extension == null) { - return null; // No extension + return null; // No extension } // Get the QName of the extension base @@ -411,11 +496,11 @@ // The restriction node indicates the type being restricted // (the base attribute contains this type). - + if (restrictionNode != null) { baseQName = Utils.getNodeTypeRefQName(restrictionNode, "base"); } - + // Look for enumeration elements underneath the restriction node if (baseQName != null && restrictionNode != null) { NodeList enums = restrictionNode.getChildNodes(); @@ -424,8 +509,8 @@ if (enumKind != null && enumKind.getLocalPart().equals("enumeration") && Constants.isSchemaXSD(enumKind.getNamespaceURI())) { - - // Found an enumeration, this isn't a + + // Found an enumeration, this isn't a // 'normal' simple type. return null; } @@ -497,7 +582,7 @@ } } } - + return re; } @@ -625,7 +710,7 @@ } } - // The restriction node must have a base of soapenc:Array. + // The restriction node must have a base of soapenc:Array. QName baseType = null; if (restrictionNode != null) { baseType = Utils.getNodeTypeRefQName(restrictionNode, "base"); @@ -637,7 +722,7 @@ baseType = null; // Did not find base=soapenc:Array } - + // Under the restriction there should be an attribute OR a sequence/all group node. // (There may be other #text nodes, which we will ignore). Node groupNode = null; @@ -685,7 +770,7 @@ } } } - + // The value should have [] on the end, strip these off. // The convert the prefixed name into a qname, and return if (wsdlArrayTypeValue != null) { @@ -697,7 +782,7 @@ } } else if (groupNode != null) { - // Get the first element node under the group node. + // Get the first element node under the group node. NodeList elements = groupNode.getChildNodes(); Node elementNode = null; for (int i=0; i < elements.getLength() && elementNode == null; i++) { @@ -708,7 +793,7 @@ elementNode = elements.item(i); } } - + // The element node should have maxOccurs="unbounded" and // a type if (elementNode != null) { @@ -720,7 +805,7 @@ } } } - + } return null; } @@ -791,7 +876,7 @@ children = groupNode.getChildNodes(); } - // Now get the element node. There can only be one element node. + // Now get the element node. There can only be one element node. Node elementNode = null; int elementNodeCount = 0; for (int i=0; i < children.getLength(); i++) {