if (node == null) {
return null;
}
// If the node kind is an element, dive into it.
QName nodeKind = Utils.getNodeQName(node);
if (nodeKind != null &&
nodeKind.getLocalPart().equals("element") &&
Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
NodeList children = node.getChildNodes();
Node complexNode = null;
for (int j = 0; j < children.getLength() && complexNode == null; j++) {
QName complexKind = Utils.getNodeQName(children.item(j));
if (complexKind != null &&
complexKind.getLocalPart().equals("complexType") &&
Utils.isSchemaNS(complexKind.getNamespaceURI())) {
complexNode = children.item(j);
node = complexNode;
}
}
}
// Get the node kind, expecting a schema complexType
nodeKind = Utils.getNodeQName(node);
if (nodeKind != null &&
nodeKind.getLocalPart().equals("complexType") &&
Utils.isSchemaNS(nodeKind.getNamespaceURI())) {
// Under the complexType there should be a complexContent.
// (There may be other #text nodes, which we will ignore).
NodeList children = node.getChildNodes();
Node complexContentNode = null;
for (int j = 0; j < children.getLength() && complexContentNode == null; j++) {
QName complexContentKind = Utils.getNodeQName(children.item(j));
if (complexContentKind != null &&
complexContentKind.getLocalPart().equals("complexContent") &&
Utils.isSchemaNS(complexContentKind.getNamespaceURI()))
complexContentNode = children.item(j);
}
// Under the complexContent there should be a restriction.
// (There may be other #text nodes, which we will ignore).
Node restrictionNode = null;
if (complexContentNode != null) {
children = complexContentNode.getChildNodes();
for (int j = 0; j < children.getLength() && restrictionNode == null; j++) {
QName restrictionKind = Utils.getNodeQName(children.item(j));
if (restrictionKind != null &&
restrictionKind.getLocalPart().equals("restriction") &&
Utils.isSchemaNS(restrictionKind.getNamespaceURI()))
restrictionNode = children.item(j);
}
}
// The restriction node must have a base of soapenc:Array.
QName baseType = null;
if (restrictionNode != null) {
baseType = Utils.getNodeTypeRefQName(restrictionNode, "base");
if (baseType != null &&
baseType.getLocalPart().equals("Array") &&
Utils.isSoapEncodingNS(baseType.getNamespaceURI()))
; // Okay
else
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;
Node attributeNode = null;
if (baseType != null) {
children = restrictionNode.getChildNodes();
for (int j = 0;
j < children.getLength() && groupNode == null && attributeNode == null;
j++) {
QName kind = Utils.getNodeQName(children.item(j));
if (kind != null &&
(kind.getLocalPart().equals("sequence") ||
kind.getLocalPart().equals("all")) &&
Utils.isSchemaNS(kind.getNamespaceURI())) {
groupNode = children.item(j);
}
if (kind != null &&
kind.getLocalPart().equals("attribute") &&
Utils.isSchemaNS(kind.getNamespaceURI())) {
attributeNode = children.item(j);
}
}
}
// If there is an attribute node, it must have a ref of soapenc:array and
// a wsdl:arrayType attribute.
if (attributeNode != null) {
QName refQName = Utils.getNodeTypeRefQName(attributeNode, "ref");
if (refQName != null &&
refQName.getLocalPart().equals("arrayType") &&
Utils.isSoapEncodingNS(refQName.getNamespaceURI()))
; // Okay
else
refQName = null; // Did not find ref="soapenc:arrayType"
String wsdlArrayTypeValue = null;
if (refQName != null) {
Vector attrs = Utils.getAttributesWithLocalName(attributeNode, "arrayType");
for (int i=0; i < attrs.size() && wsdlArrayTypeValue == null; i++) {
Node attrNode = (Node) attrs.elementAt(i);
String attrName = attrNode.getNodeName();
QName attrQName = Utils.getQNameFromPrefixedName(attributeNode, attrName);
if (Utils.isWsdlNS(attrQName.getNamespaceURI())) {
wsdlArrayTypeValue = attrNode.getNodeValue();
}
}
}
// The value should have [] on the end, strip these off.
// The convert the prefixed name into a qname, and return
if (wsdlArrayTypeValue != null) {
int i = wsdlArrayTypeValue.indexOf("[");
if (i > 0) {
String prefixedName = wsdlArrayTypeValue.substring(0,i);
return Utils.getQNameFromPrefixedName(restrictionNode, prefixedName);
}
}
} else if (groupNode != null) {
// 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++) {
QName elementKind = Utils.getNodeQName(elements.item(i));
if (elementKind != null &&
elementKind.getLocalPart().equals("element") &&
Utils.isSchemaNS(elementKind.getNamespaceURI())) {
elementNode = elements.item(i);
}
}
// The element node should have maxOccurs="unbounded" and