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") &&
Constants.isSchemaXSD(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") &&
Constants.isSchemaXSD(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") &&
Constants.isSchemaXSD(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") ||
complexContentKind.getLocalPart().equals("simpleContent")) &&
Constants.isSchemaXSD(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") &&
Constants.isSchemaXSD(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") &&
Constants.isSOAP_ENC(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")) &&
Constants.isSchemaXSD(kind.getNamespaceURI())) {
groupNode = children.item(j);
}
if (kind != null &&
kind.getLocalPart().equals("attribute") &&
Constants.isSchemaXSD(kind.getNamespaceURI())) {
// If the attribute node does not have ref="soapenc:arrayType"
// then keep looking.
QName refQName = Utils.getNodeTypeRefQName(children.item(j), "ref");
if (refQName != null &&
refQName.getLocalPart().equals("arrayType") &&
Constants.isSOAP_ENC(refQName.getNamespaceURI())) {
attributeNode = children.item(j);
}
}
}
}
// If there is an attribute node, look at wsdl:arrayType to get the element type
if (attributeNode != null) {
String wsdlArrayTypeValue = 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 (Constants.isWSDL(attrQName.getNamespaceURI())) {
wsdlArrayTypeValue = attrNode.getNodeValue();
}
}
// The value could have any number of [] or [,] on the end
// Strip these off to get the prefixed name.
// The convert the prefixed name into a qname.
// Count the number of [ and , to get the dim information.
if (wsdlArrayTypeValue != null) {
int i = wsdlArrayTypeValue.indexOf('[');
if (i > 0) {
String prefixedName = wsdlArrayTypeValue.substring(0,i);
String mangledString = wsdlArrayTypeValue.replace(',', '[');
dims.value = 0;
int index = mangledString.indexOf('[');
while (index > 0) {
dims.value++;
index = mangledString.indexOf('[',index+1);
}
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") &&
Constants.isSchemaXSD(elementKind.getNamespaceURI())) {
elementNode = elements.item(i);
}
}
// The element node should have maxOccurs="unbounded" and