private void parseType(String typeName, List<WSComponentPort> parts) throws ComponentException {
XmlElement typesElement = this.wsdl.getTypes();
if (typesElement == null) {
throw new ComponentException("No types is defined.");
}
if (typesElement.element(null, WSConstants.SCHEMA_TAG) == null) {
throw new ComponentException("No schema is defined.");
}
XmlElement elementElement = null;
XmlElement schemaElement = null;
Iterable<XmlElement> schemaElements = typesElement.elements(null, WSConstants.SCHEMA_TAG);
for (XmlElement elemt : schemaElements) {
schemaElement = elemt;
elementElement = findElementElement(typeName, elemt);
if (null != elementElement) {
break;
}
}
if (elementElement == null) {
throw new ComponentException("No element is defined for " + typeName);
}
String typesTargetNamespace = schemaElement.attributeValue(WSConstants.TARGET_NAMESPACE_ATTRIBUTE);
String elementType = elementElement.attributeValue(WSConstants.TYPE_ATTRIBUTE);
XmlElement sequenceElement;
if (elementType == null) {
// anonymous type
XmlElement complexElement = elementElement.element(null, WSConstants.COMPLEX_TYPE_TAG);
if (complexElement == null) {
throw new ComponentException("We only support complexType as annonymous type: "
+ XMLUtil.xmlElementToString(elementElement));
}
sequenceElement = complexElement.element(null, WSConstants.SEQUENCE_TAG);
// TODO Check if there is any other defined.
} else {
// named complexType
String elementTypeName = XMLUtil.getLocalPartOfQName(elementType);
XmlElement typeElement = findTypeElement(elementTypeName, schemaElement);
sequenceElement = typeElement.element(null, WSConstants.SEQUENCE_TAG);
// TODO Check if there is any other defined.
}
if (sequenceElement == null) {
// Assume that there is no input/output.
logger.debug("There is no sequence defined.");
} else {
// Only supports elements in the sequence now.
for (XmlElement element : sequenceElement.elements(null, WSConstants.ELEMENT_TAG)) {
WSComponentPort componentPort = new WSComponentPort(element, typesTargetNamespace, this);
// Check if the type is defined in types
QName paramType = componentPort.getType();
if (!(WSConstants.XSD_NS_URI.equalsIgnoreCase(paramType.getNamespaceURI()))) {
XmlElement typeDefinition = null;
try {
typeDefinition = WSDLUtil.getTypeDefinition(this.wsdl, paramType);
} catch (UtilsException e) {
e.printStackTrace();
}
if (typeDefinition == null) {
throw new ComponentException("could not find definition for type " + paramType + " in "
+ this.wsdlQName);
}
}
parts.add(componentPort);
}