requestType.setName(opName + REQUEST_SUFFIX + TYPE_SUFFIX);
Sequence requestSequence = null;
if (op.getParameters().size() > 0) {
requestSequence = new Sequence();
for (Parameter p : op.getParameters()) {
Element arg = new Element();
arg.setName(p.getName());
if (THE_INSTANCE_NAME.equals(p.getName())) {
ComplexType nestedComplexType = new ComplexType();
Sequence nestedSequence = new Sequence();
nestedComplexType.setSequence(nestedSequence);
Element nestedElement = new Element();
nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + tableNameAlias);
nestedSequence.addElement(nestedElement);
arg.setComplexType(nestedComplexType);
}
else {
arg.setName(p.getName());
if (p.getType().getNamespaceURI().equals(W3C_XML_SCHEMA_NS_URI)) {
arg.setType(NS_SCHEMA_PREFIX + ":" + p.getType().getLocalPart());
}
else if (p.getType().getNamespaceURI().equals(importedSchemaNameSpace)) {
arg.setType(TARGET_NAMESPACE_PREFIX + ":" + p.getType().getLocalPart());
}
else {
arg.setType(p.getType().getLocalPart());
}
}
requestSequence.addElement(arg);
}
requestType.setSequence(requestSequence);
}
schema.addTopLevelComplexTypes(requestType);
Element requestElement = new Element();
requestElement.setName(op.getName());
requestElement.setType(NS_TNS_PREFIX + ":" + requestType.getName());
schema.addTopLevelElement(requestElement);
// build response message based on operation type
if (op instanceof QueryOperation) {
QueryOperation q = (QueryOperation) op;
ComplexType responseType = new ComplexType();
responseType.setName(op.getName() + RESPONSE_SUFFIX + TYPE_SUFFIX);
Sequence responseSequence = new Sequence();
Element result = new Element();
result.setName("result");
if (q.isAttachment()) {
result.setType(WSI_SWAREF_PREFIX + ":" + WSI_SWAREF);
}
else if (q.isSimpleXMLFormat() ||
q.getResultType().equals(new QName(W3C_XML_SCHEMA_NS_URI, "any"))) {
ComplexType anyType = new ComplexType();
Sequence anySequence = new Sequence();
anySequence.addAny(new Any());
anyType.setSequence(anySequence);
result.setComplexType(anyType);
}
else {
if (q.getResultType().getNamespaceURI().equals(W3C_XML_SCHEMA_NS_URI)) {
result.setType(NS_SCHEMA_PREFIX + ":" + q.getResultType().getLocalPart());
}
else {
ComplexType nestedComplexType = new ComplexType();
Sequence nestedSequence = new Sequence();
nestedComplexType.setSequence(nestedSequence);
Element nestedElement = new Element();
if (!q.isUserDefined()) {
nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + tableNameAlias);
}
else {
nestedElement.setRef(TARGET_NAMESPACE_PREFIX + ":" + q.getResultType().getLocalPart());
}
nestedElement.setMinOccurs("0");
if (q.isCollection()) {
nestedElement.setMaxOccurs("unbounded");
}
nestedSequence.addElement(nestedElement);
result.setComplexType(nestedComplexType);
}
}
responseSequence.addElement(result);
responseType.setSequence(responseSequence);
schema.addTopLevelComplexTypes(responseType);
Element responseElement = new Element();
responseElement.setName(op.getName() + RESPONSE_SUFFIX);
responseElement.setType(NS_TNS_PREFIX + ":" + responseType.getName());
schema.addTopLevelElement(responseElement);
}
else {
requireFaultTypeEmptyResponse = true;
}
}
if (requireFaultTypeEmptyResponse) {
// <element name="EmptyResponse">
// <xsd:complexType/>
// </element>
Element emptyResponseElement = new Element();
emptyResponseElement.setName(EMPTY_RESPONSE);
ComplexType emptyResponseComplexType = new ComplexType();
emptyResponseElement.setComplexType(emptyResponseComplexType);
schema.addTopLevelElement(emptyResponseElement);
// <xsd:element name="FaultType">
// <xsd:complexType>
// <xsd:sequence>
// <xsd:element name="faultCode" type="xsd:string"/>
// <xsd:element name="faultString" type="xsd:string"/>
// </xsd:sequence>
// </xsd:complexType>
// </element>
Element elementFaultType = new Element();
elementFaultType.setName(FAULT_SUFFIX + TYPE_SUFFIX);
ComplexType faultComplexType = new ComplexType();
elementFaultType.setComplexType(faultComplexType);
Sequence nestedSequence = new Sequence();
faultComplexType.setSequence(nestedSequence);
Element faultCodeElement = new Element();
faultCodeElement.setName("faultCode");
faultCodeElement.setMinOccurs("1");
faultCodeElement.setType(NS_SCHEMA_PREFIX + ":string");
nestedSequence.addElement(faultCodeElement);
Element faultStringElement = new Element();
faultStringElement.setMinOccurs("1");
faultStringElement.setName("faultString");
faultStringElement.setType(NS_SCHEMA_PREFIX + ":string");
nestedSequence.addElement(faultStringElement);
schema.addTopLevelElement(elementFaultType);
}
return marshaller.objectToXML(schema).getDocumentElement();
}