package com.sun.tools.internal.ws.processor.modeler.wsdl;
import com.sun.codemodel.internal.JType;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.SAXParseException2;
import com.sun.tools.internal.ws.api.wsdl.TWSDLExtensible;
import com.sun.tools.internal.ws.processor.generator.Names;
import com.sun.tools.internal.ws.processor.model.*;
import com.sun.tools.internal.ws.processor.model.Fault;
import com.sun.tools.internal.ws.processor.model.Operation;
import com.sun.tools.internal.ws.processor.model.Port;
import com.sun.tools.internal.ws.processor.model.Service;
import com.sun.tools.internal.ws.processor.model.java.*;
import com.sun.tools.internal.ws.processor.model.jaxb.*;
import com.sun.tools.internal.ws.processor.modeler.JavaSimpleTypeCreator;
import com.sun.tools.internal.ws.processor.util.ClassNameCollector;
import com.sun.tools.internal.ws.resources.ModelerMessages;
import com.sun.tools.internal.ws.wscompile.ErrorReceiver;
import com.sun.tools.internal.ws.wscompile.WsimportOptions;
import com.sun.tools.internal.ws.wsdl.document.*;
import com.sun.tools.internal.ws.wsdl.document.Message;
import com.sun.tools.internal.ws.wsdl.document.jaxws.CustomName;
import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBinding;
import com.sun.tools.internal.ws.wsdl.document.mime.MIMEContent;
import com.sun.tools.internal.ws.wsdl.document.schema.SchemaKinds;
import com.sun.tools.internal.ws.wsdl.document.soap.*;
import com.sun.tools.internal.ws.wsdl.framework.*;
import com.sun.tools.internal.ws.wsdl.parser.MetadataFinder;
import com.sun.tools.internal.ws.wsdl.parser.WSDLParser;
import com.sun.tools.internal.xjc.api.S2JJAXBModel;
import com.sun.tools.internal.xjc.api.TypeAndAnnotation;
import com.sun.tools.internal.xjc.api.XJC;
import com.sun.xml.internal.ws.spi.db.BindingHelper;
import com.sun.xml.internal.ws.util.xml.XmlUtil;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.LocatorImpl;
import javax.jws.WebParam.Mode;
import javax.xml.namespace.QName;
import java.util.*;
import java.io.IOException;
public class WSDLModeler extends WSDLModelerBase {
private final Map<QName, Operation> uniqueBodyBlocks = new HashMap<QName, Operation>();
private final QName VOID_BODYBLOCK = new QName("");
private final ClassNameCollector classNameCollector;
private final String explicitDefaultPackage;
public WSDLModeler(WsimportOptions options, ErrorReceiver receiver, MetadataFinder forest) {
super(options, receiver,forest);
this.classNameCollector = new ClassNameCollector();
this.explicitDefaultPackage = options.defaultPackage;
}
protected enum StyleAndUse {
RPC_LITERAL, DOC_LITERAL
}
private JAXBModelBuilder jaxbModelBuilder;
@Override
public Model buildModel() {
try {
parser = new WSDLParser(options, errReceiver, forest);
parser.addParserListener(new ParserListener() {
@Override
public void ignoringExtension(Entity entity, QName name, QName parent) {
if (parent.equals(WSDLConstants.QNAME_TYPES)) {
if (name.getLocalPart().equals("schema")
&& !name.getNamespaceURI().equals("")) {
warning(entity, ModelerMessages.WSDLMODELER_WARNING_IGNORING_UNRECOGNIZED_SCHEMA_EXTENSION(name.getNamespaceURI()));
}
}
}
@Override
public void doneParsingEntity(QName element, Entity entity) {
}
});
document = parser.parse();
if (document == null || document.getDefinitions() == null) {
return null;
}
document.validateLocally();
Model model = internalBuildModel(document);
if (model == null || errReceiver.hadError()) {
return null;
}
classNameCollector.process(model);
if (classNameCollector.getConflictingClassNames().isEmpty()) {
if (errReceiver.hadError()) {
return null;
}
return model;
}
model = internalBuildModel(document);
classNameCollector.process(model);
if (classNameCollector.getConflictingClassNames().isEmpty()) {
if (errReceiver.hadError()) {
return null;
}
return model;
}
StringBuilder conflictList = new StringBuilder();
boolean first = true;
for (Iterator iter =
classNameCollector.getConflictingClassNames().iterator();
iter.hasNext();
) {
if (!first) {
conflictList.append(", ");
} else {
first = false;
}
conflictList.append((String) iter.next());
}
error(document.getDefinitions(), ModelerMessages.WSDLMODELER_UNSOLVABLE_NAMING_CONFLICTS(conflictList.toString()));
} catch (ModelException e) {
reportError(document.getDefinitions(), e.getMessage(), e);
} catch (ParseException e) {
errReceiver.error(e);
} catch (ValidationException e) {
errReceiver.error(e.getMessage(), e);
} catch (SAXException e) {
errReceiver.error(e);
} catch (IOException e) {
errReceiver.error(e);
}
return null;
}
private Model internalBuildModel(WSDLDocument document) {
numPasses++;
buildJAXBModel(document);
QName modelName =
new QName(
document.getDefinitions().getTargetNamespaceURI(),
document.getDefinitions().getName() == null
? "model"
: document.getDefinitions().getName());
Model model = new Model(modelName, document.getDefinitions());
model.setJAXBModel(getJAXBModelBuilder().getJAXBModel());
model.setProperty(
ModelProperties.PROPERTY_MODELER_NAME,
ModelProperties.WSDL_MODELER_NAME);
_javaExceptions = new HashMap<String, JavaException>();
_bindingNameToPortMap = new HashMap<QName, Port>();
model.setTargetNamespaceURI(document.getDefinitions().getTargetNamespaceURI());
setDocumentationIfPresent(model,
document.getDefinitions().getDocumentation());
boolean hasServices = document.getDefinitions().services().hasNext();
if (hasServices) {
for (Iterator iter = document.getDefinitions().services();
iter.hasNext();
) {
processService((com.sun.tools.internal.ws.wsdl.document.Service) iter.next(),
model, document);
}
} else {
warning(model.getEntity(), ModelerMessages.WSDLMODELER_WARNING_NO_SERVICE_DEFINITIONS_FOUND());
}
return model;
}
protected void processService(com.sun.tools.internal.ws.wsdl.document.Service wsdlService, Model model, WSDLDocument document) {
QName serviceQName = getQNameOf(wsdlService);
String serviceInterface = getServiceInterfaceName(serviceQName, wsdlService);
if (isConflictingServiceClassName(serviceInterface)) {
serviceInterface += "_Service";
}
Service service =
new Service(
serviceQName,
new JavaInterface(serviceInterface, serviceInterface + "Impl"), wsdlService);
setDocumentationIfPresent(service, wsdlService.getDocumentation());
boolean hasPorts = false;
for (Iterator iter = wsdlService.ports(); iter.hasNext();) {
boolean processed =
processPort(
(com.sun.tools.internal.ws.wsdl.document.Port) iter.next(),
service,
document);
hasPorts = hasPorts || processed;
}
if (!hasPorts) {
warning(wsdlService, ModelerMessages.WSDLMODELER_WARNING_NO_PORTS_IN_SERVICE(wsdlService.getName()));
} else {
model.addService(service);
}
}
protected boolean processPort(com.sun.tools.internal.ws.wsdl.document.Port wsdlPort,
Service service, WSDLDocument document) {
try {
uniqueBodyBlocks.clear();
QName portQName = getQNameOf(wsdlPort);
Port port = new Port(portQName, wsdlPort);
setDocumentationIfPresent(port, wsdlPort.getDocumentation());
SOAPAddress soapAddress =
(SOAPAddress) getExtensionOfType(wsdlPort, SOAPAddress.class);
if (soapAddress == null) {
if(options.isExtensionMode()){
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_SOAP_ADDRESS(wsdlPort.getName()));
}else{
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT_NO_ADDRESS(wsdlPort.getName()));
return false;
}
}
if (soapAddress != null) {
port.setAddress(soapAddress.getLocation());
}
Binding binding = wsdlPort.resolveBinding(document);
QName bindingName = getQNameOf(binding);
PortType portType = binding.resolvePortType(document);
port.setProperty(
ModelProperties.PROPERTY_WSDL_PORT_NAME,
getQNameOf(wsdlPort));
port.setProperty(
ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME,
getQNameOf(portType));
port.setProperty(
ModelProperties.PROPERTY_WSDL_BINDING_NAME,
bindingName);
boolean isProvider = isProvider(wsdlPort);
if (_bindingNameToPortMap.containsKey(bindingName) && !isProvider) {
Port existingPort =
_bindingNameToPortMap.get(bindingName);
port.setOperations(existingPort.getOperations());
port.setJavaInterface(existingPort.getJavaInterface());
port.setStyle(existingPort.getStyle());
port.setWrapped(existingPort.isWrapped());
} else {
SOAPBinding soapBinding =
(SOAPBinding) getExtensionOfType(binding, SOAPBinding.class);
if (soapBinding == null) {
soapBinding =
(SOAPBinding) getExtensionOfType(binding, SOAP12Binding.class);
if (soapBinding == null) {
if(!options.isExtensionMode()){
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_NON_SOAP_PORT(wsdlPort.getName()));
return false;
}else{
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NON_SOAP_PORT(wsdlPort.getName()));
}
}else{
if (options.isExtensionMode()) {
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_PORT_SOAP_BINDING_12(wsdlPort.getName()));
} else {
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_12(wsdlPort.getName()));
return false;
}
}
}
if (soapBinding != null && (soapBinding.getTransport() == null
|| (!soapBinding.getTransport().equals(
SOAPConstants.URI_SOAP_TRANSPORT_HTTP) && !soapBinding.getTransport().equals(
SOAP12Constants.URI_SOAP_TRANSPORT_HTTP)))) {
if (!options.isExtensionMode()) {
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_NON_HTTP_TRANSPORT(wsdlPort.getName()));
return false;
}
}
if (soapBinding != null && !validateWSDLBindingStyle(binding)) {
if (options.isExtensionMode()) {
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_PORT_SOAP_BINDING_MIXED_STYLE(wsdlPort.getName()));
} else {
error(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_IGNORING_SOAP_BINDING_MIXED_STYLE(wsdlPort.getName()));
}
}
if(soapBinding != null){
port.setStyle(soapBinding.getStyle());
}
boolean hasOverloadedOperations = false;
Set<String> operationNames = new HashSet<String>();
for (Iterator iter = portType.operations(); iter.hasNext();) {
com.sun.tools.internal.ws.wsdl.document.Operation operation =
(com.sun.tools.internal.ws.wsdl.document.Operation) iter.next();
if (operationNames.contains(operation.getName())) {
hasOverloadedOperations = true;
break;
}
operationNames.add(operation.getName());
for (Iterator itr = binding.operations();
iter.hasNext();
) {
BindingOperation bindingOperation =
(BindingOperation) itr.next();
if (operation
.getName()
.equals(bindingOperation.getName())) {
break;
} else if (!itr.hasNext()) {
error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(operation.getName(), bindingOperation.getName()));
}
}
}
Map headers = new HashMap();
boolean hasOperations = false;
for (Iterator iter = binding.operations(); iter.hasNext();) {
BindingOperation bindingOperation =
(BindingOperation) iter.next();
com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation =
null;
Set operations =
portType.getOperationsNamed(bindingOperation.getName());
if (operations.isEmpty()) {
error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_IN_PORT_TYPE(bindingOperation.getName(), binding.getName()));
} else if (operations.size() == 1) {
portTypeOperation =
(com.sun.tools.internal.ws.wsdl.document.Operation) operations
.iterator()
.next();
} else {
boolean found = false;
String expectedInputName =
bindingOperation.getInput().getName();
String expectedOutputName =
bindingOperation.getOutput().getName();
for (Iterator iter2 = operations.iterator(); iter2.hasNext();) {
com.sun.tools.internal.ws.wsdl.document.Operation candidateOperation =
(com.sun.tools.internal.ws.wsdl.document.Operation) iter2
.next();
if (expectedInputName == null) {
error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MISSING_INPUT_NAME(bindingOperation.getName()));
}
if (expectedOutputName == null) {
error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MISSING_OUTPUT_NAME(bindingOperation.getName()));
}
if (expectedInputName
.equals(candidateOperation.getInput().getName())
&& expectedOutputName.equals(
candidateOperation
.getOutput()
.getName())) {
if (found) {
error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_MATCHING_OPERATIONS(bindingOperation.getName(), bindingOperation.getName()));
}
found = true;
portTypeOperation = candidateOperation;
}
}
if (!found) {
error(bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_NOT_FOUND(bindingOperation.getName(), binding.getName()));
}
}
if (!isProvider) {
this.info =
new ProcessSOAPOperationInfo(
port,
wsdlPort,
portTypeOperation,
bindingOperation,
soapBinding,
document,
hasOverloadedOperations,
headers);
Operation operation;
if (soapBinding != null) {
operation = processSOAPOperation();
} else {
operation = processNonSOAPOperation();
}
if (operation != null) {
port.addOperation(operation);
hasOperations = true;
}
}
}
if (!isProvider && !hasOperations) {
warning(wsdlPort, ModelerMessages.WSDLMODELER_WARNING_NO_OPERATIONS_IN_PORT(wsdlPort.getName()));
return false;
}
createJavaInterfaceForPort(port, isProvider);
PortType pt = binding.resolvePortType(document);
String jd = (pt.getDocumentation() != null) ? pt.getDocumentation().getContent() : null;
port.getJavaInterface().setJavaDoc(jd);
_bindingNameToPortMap.put(bindingName, port);
}
service.addPort(port);
applyPortMethodCustomization(port, wsdlPort);
applyWrapperStyleCustomization(port, binding.resolvePortType(document));
return true;
} catch (NoSuchEntityException e) {
warning(document.getDefinitions(), e.getMessage());
return false;
}
}
private Operation processNonSOAPOperation() {
Operation operation =
new Operation(new QName(null, info.bindingOperation.getName()), info.bindingOperation);
setDocumentationIfPresent(
operation,
info.portTypeOperation.getDocumentation());
if (info.portTypeOperation.getStyle()
!= OperationStyle.REQUEST_RESPONSE
&& info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
if (options.isExtensionMode()) {
warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName()));
return null;
} else {
error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName(),
info.port.resolveBinding(document).resolvePortType(document).getName()));
}
}
boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
Message inputMessage = getInputMessage();
Request request = new Request(inputMessage, errReceiver);
request.setErrorReceiver(errReceiver);
info.operation = operation;
info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
Response response;
Message outputMessage = null;
if (isRequestResponse) {
outputMessage = getOutputMessage();
response = new Response(outputMessage, errReceiver);
}else{
response = new Response(null, errReceiver);
}
setNonSoapStyle(inputMessage, outputMessage);
List<MessagePart> parameterList = getParameterOrder();
boolean unwrappable = isUnwrappable();
info.operation.setWrapped(unwrappable);
List<Parameter> params = getDoclitParameters(request, response, parameterList);
if (!validateParameterName(params)) {
return null;
}
List<Parameter> definitiveParameterList = new ArrayList<Parameter>();
for (Parameter param : params) {
if (param.isReturn()) {
info.operation.setProperty(WSDL_RESULT_PARAMETER, param);
response.addParameter(param);
continue;
}
if (param.isIN()) {
request.addParameter(param);
} else if (param.isOUT()) {
response.addParameter(param);
} else if (param.isINOUT()) {
request.addParameter(param);
response.addParameter(param);
}
definitiveParameterList.add(param);
}
info.operation.setRequest(request);
if (isRequestResponse) {
info.operation.setResponse(response);
}
Set duplicateNames = getDuplicateFaultNames();
handleLiteralSOAPFault(response, duplicateNames);
info.operation.setProperty(
WSDL_PARAMETER_ORDER,
definitiveParameterList);
Binding binding = info.port.resolveBinding(document);
PortType portType = binding.resolvePortType(document);
if (isAsync(portType, info.portTypeOperation)) {
warning(portType, "Can not generate Async methods for non-soap binding!");
}
return info.operation;
}
private void setNonSoapStyle(Message inputMessage, Message outputMessage) {
SOAPStyle style = SOAPStyle.DOCUMENT;
for(MessagePart part:inputMessage.getParts()){
if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
style = SOAPStyle.RPC;
} else {
style = SOAPStyle.DOCUMENT;
}
}
if(outputMessage != null){
for(MessagePart part:outputMessage.getParts()){
if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
style = SOAPStyle.RPC;
} else {
style = SOAPStyle.DOCUMENT;
}
}
}
info.modelPort.setStyle(style);
}
protected Operation processSOAPOperation() {
Operation operation =
new Operation(new QName(null, info.bindingOperation.getName()), info.bindingOperation);
setDocumentationIfPresent(
operation,
info.portTypeOperation.getDocumentation());
if (info.portTypeOperation.getStyle()
!= OperationStyle.REQUEST_RESPONSE
&& info.portTypeOperation.getStyle() != OperationStyle.ONE_WAY) {
if (options.isExtensionMode()) {
warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName()));
return null;
} else {
error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_NOT_SUPPORTED_STYLE(info.portTypeOperation.getName(),
info.port.resolveBinding(document).resolvePortType(document).getName()));
}
}
SOAPStyle soapStyle = info.soapBinding.getStyle();
SOAPOperation soapOperation =
(SOAPOperation) getExtensionOfType(info.bindingOperation,
SOAPOperation.class);
if (soapOperation != null) {
if (soapOperation.getStyle() != null) {
soapStyle = soapOperation.getStyle();
}
if (soapOperation.getSOAPAction() != null) {
operation.setSOAPAction(soapOperation.getSOAPAction());
}
}
operation.setStyle(soapStyle);
String uniqueOperationName =
getUniqueName(info.portTypeOperation, info.hasOverloadedOperations);
if (info.hasOverloadedOperations) {
operation.setUniqueName(uniqueOperationName);
}
info.operation = operation;
SOAPBody soapRequestBody = getSOAPRequestBody();
if (soapRequestBody == null) {
error(info.bindingOperation, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_INPUT_MISSING_SOAP_BODY(info.bindingOperation.getName()));
}
if (soapStyle == SOAPStyle.RPC) {
if (soapRequestBody.isEncoded()) {
if(options.isExtensionMode()){
warning(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
processNonSOAPOperation();
}else{
error(soapRequestBody, ModelerMessages.WSDLMODELER_20_RPCENC_NOT_SUPPORTED());
}
}
return processLiteralSOAPOperation(StyleAndUse.RPC_LITERAL);
}
return processLiteralSOAPOperation(StyleAndUse.DOC_LITERAL);
}
protected Operation processLiteralSOAPOperation(StyleAndUse styleAndUse) {
if (!applyOperationNameCustomization()) {
return null;
}
boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
Message inputMessage = getInputMessage();
Request request = new Request(inputMessage, errReceiver);
request.setErrorReceiver(errReceiver);
info.operation.setUse(SOAPUse.LITERAL);
info.operation.setWSDLPortTypeOperation(info.portTypeOperation);
SOAPBody soapRequestBody = getSOAPRequestBody();
if ((StyleAndUse.DOC_LITERAL == styleAndUse) && (soapRequestBody.getNamespace() != null)) {
warning(soapRequestBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
}
Response response;
SOAPBody soapResponseBody = null;
Message outputMessage = null;
if (isRequestResponse) {
soapResponseBody = getSOAPResponseBody();
if (isOperationDocumentLiteral(styleAndUse) && (soapResponseBody.getNamespace() != null)) {
warning(soapResponseBody, ModelerMessages.WSDLMODELER_WARNING_R_2716("soapbind:body", info.bindingOperation.getName()));
}
outputMessage = getOutputMessage();
response = new Response(outputMessage, errReceiver);
}else{
response = new Response(null, errReceiver);
}
if (!validateMimeParts(getMimeParts(info.bindingOperation.getInput())) ||
!validateMimeParts(getMimeParts(info.bindingOperation.getOutput()))) {
return null;
}
if (!validateBodyParts(info.bindingOperation)) {
if (isOperationDocumentLiteral(styleAndUse)) {
if (options.isExtensionMode()) {
warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_TYPE_MESSAGE_PART(info.portTypeOperation.getName()));
} else {
error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_DOCLITOPERATION(info.portTypeOperation.getName()));
}
} else if (isOperationRpcLiteral(styleAndUse)) {
if (options.isExtensionMode()) {
warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_CANNOT_HANDLE_ELEMENT_MESSAGE_PART(info.portTypeOperation.getName()));
} else {
error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_RPCLITOPERATION(info.portTypeOperation.getName()));
}
}
return null;
}
List<MessagePart> parameterList = getParameterOrder();
if (!setMessagePartsBinding(styleAndUse)) {
return null;
}
List<Parameter> params = null;
boolean unwrappable = isUnwrappable();
info.operation.setWrapped(unwrappable);
if (isOperationDocumentLiteral(styleAndUse)) {
params = getDoclitParameters(request, response, parameterList);
} else if (isOperationRpcLiteral(styleAndUse)) {
String operationName = info.bindingOperation.getName();
Block reqBlock = null;
if (inputMessage != null) {
QName name = new QName(getRequestNamespaceURI(soapRequestBody), operationName);
RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
reqBlock = new Block(name, rpcStruct, inputMessage);
request.addBodyBlock(reqBlock);
}
Block resBlock = null;
if (isRequestResponse && outputMessage != null) {
QName name = new QName(getResponseNamespaceURI(soapResponseBody), operationName + "Response");
RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
resBlock = new Block(name, rpcStruct, outputMessage);
response.addBodyBlock(resBlock);
}
params = getRpcLitParameters(request, response, reqBlock, resBlock, parameterList);
}
if (!validateParameterName(params)) {
return null;
}
List<Parameter> definitiveParameterList = new ArrayList<Parameter>();
for (Parameter param : params) {
if (param.isReturn()) {
info.operation.setProperty(WSDL_RESULT_PARAMETER, param);
response.addParameter(param);
continue;
}
if (param.isIN()) {
request.addParameter(param);
} else if (param.isOUT()) {
response.addParameter(param);
} else if (param.isINOUT()) {
request.addParameter(param);
response.addParameter(param);
}
definitiveParameterList.add(param);
}
info.operation.setRequest(request);
if (isRequestResponse) {
info.operation.setResponse(response);
}
Iterator<Block> bb = request.getBodyBlocks();
QName body;
Operation thatOp;
if (bb.hasNext()) {
body = bb.next().getName();
thatOp = uniqueBodyBlocks.get(body);
} else {
body = VOID_BODYBLOCK;
thatOp = uniqueBodyBlocks.get(VOID_BODYBLOCK);
}
if(thatOp != null){
if(options.isExtensionMode()){
warning(info.port, ModelerMessages.WSDLMODELER_NON_UNIQUE_BODY_WARNING(info.port.getName(), info.operation.getName(), thatOp.getName(), body));
}else{
error(info.port, ModelerMessages.WSDLMODELER_NON_UNIQUE_BODY_ERROR(info.port.getName(), info.operation.getName(), thatOp.getName(), body));
}
}else{
uniqueBodyBlocks.put(body, info.operation);
}
if (options.additionalHeaders) {
List<Parameter> additionalHeaders = new ArrayList<Parameter>();
if (inputMessage != null) {
for (MessagePart part : getAdditionHeaderParts(info.bindingOperation, inputMessage, true)) {
QName name = part.getDescriptor();
JAXBType jaxbType = getJAXBType(part);
Block block = new Block(name, jaxbType, part);
Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
additionalHeaders.add(param);
request.addHeaderBlock(block);
request.addParameter(param);
definitiveParameterList.add(param);
}
}
if (isRequestResponse && outputMessage != null) {
List<Parameter> outParams = new ArrayList<Parameter>();
for (MessagePart part : getAdditionHeaderParts(info.bindingOperation,outputMessage, false)) {
QName name = part.getDescriptor();
JAXBType jaxbType = getJAXBType(part);
Block block = new Block(name, jaxbType, part);
Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
param.setMode(Mode.OUT);
outParams.add(param);
response.addHeaderBlock(block);
response.addParameter(param);
}
for (Parameter outParam : outParams) {
for (Parameter inParam : additionalHeaders) {
if (inParam.getName().equals(outParam.getName()) &&
inParam.getBlock().getName().equals(outParam.getBlock().getName())) {
inParam.setMode(Mode.INOUT);
outParam.setMode(Mode.INOUT);
break;
}
}
if (outParam.isOUT()) {
definitiveParameterList.add(outParam);
}
}
}
}
Set duplicateNames = getDuplicateFaultNames();
handleLiteralSOAPFault(response, duplicateNames);
info.operation.setProperty(
WSDL_PARAMETER_ORDER,
definitiveParameterList);
Binding binding = info.port.resolveBinding(document);
PortType portType = binding.resolvePortType(document);
if (isAsync(portType, info.portTypeOperation)) {
addAsyncOperations(info.operation, styleAndUse);
}
return info.operation;
}
private boolean validateParameterName(List<Parameter> params) {
if (options.isExtensionMode()) {
return true;
}
Message msg = getInputMessage();
for (Parameter param : params) {
if (param.isOUT()) {
continue;
}
if (param.getCustomName() != null) {
if (Names.isJavaReservedWord(param.getCustomName())) {
error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
return false;
}
return true;
}
if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
if (Names.isJavaReservedWord(param.getName())) {
error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
return false;
}
} else {
if (Names.isJavaReservedWord(param.getName())) {
error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
return false;
}
}
}
boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
if (isRequestResponse) {
msg = getOutputMessage();
for (Parameter param : params) {
if (param.isIN()) {
continue;
}
if (param.getCustomName() != null) {
if (Names.isJavaReservedWord(param.getCustomName())) {
error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOM_NAME(info.operation.getName(), param.getCustomName()));
return false;
}
return true;
}
if (param.isEmbedded() && !(param.getBlock().getType() instanceof RpcLitStructure)) {
if (param.isReturn()) {
continue;
}
if (!param.getName().equals("return") && Names.isJavaReservedWord(param.getName())) {
error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_WRAPPER_STYLE(info.operation.getName(), param.getName(), param.getBlock().getName()));
return false;
}
} else {
if (param.isReturn()) {
continue;
}
if (Names.isJavaReservedWord(param.getName())) {
error(param.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_NON_WRAPPER_STYLE(info.operation.getName(), msg.getName(), param.getName()));
return false;
}
}
}
}
return true;
}
private boolean enableMimeContent() {
JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.bindingOperation, JAXWSBinding.class);
Boolean mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
if (mimeContentMapping != null) {
return mimeContentMapping;
}
Binding binding = info.port.resolveBinding(info.document);
jaxwsCustomization = (JAXWSBinding) getExtensionOfType(binding, JAXWSBinding.class);
mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
if (mimeContentMapping != null) {
return mimeContentMapping;
}
jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.document.getDefinitions(), JAXWSBinding.class);
mimeContentMapping = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableMimeContentMapping() : null;
if (mimeContentMapping != null) {
return mimeContentMapping;
}
return false;
}
private boolean applyOperationNameCustomization() {
JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(info.portTypeOperation, JAXWSBinding.class);
String operationName = (jaxwsCustomization != null) ? ((jaxwsCustomization.getMethodName() != null) ? jaxwsCustomization.getMethodName().getName() : null) : null;
if (operationName != null) {
if (Names.isJavaReservedWord(operationName)) {
if (options.isExtensionMode()) {
warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));
} else {
error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_CUSTOMIZED_OPERATION_NAME(info.operation.getName(), operationName));
}
return false;
}
info.operation.setCustomizedName(operationName);
}
if (Names.isJavaReservedWord(info.operation.getJavaMethodName())) {
if (options.isExtensionMode()) {
warning(info.portTypeOperation, ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));
} else {
error(info.portTypeOperation, ModelerMessages.WSDLMODELER_INVALID_OPERATION_JAVA_RESERVED_WORD_NOT_ALLOWED_OPERATION_NAME(info.operation.getName()));
}
return false;
}
return true;
}
protected String getAsyncOperationName(Operation operation) {
String name = operation.getCustomizedName();
if (name == null) {
name = operation.getUniqueName();
}
return name;
}
private void addAsyncOperations(Operation syncOperation, StyleAndUse styleAndUse) {
Operation operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.POLLING);
if (operation != null) {
info.modelPort.addOperation(operation);
}
operation = createAsyncOperation(syncOperation, styleAndUse, AsyncOperationType.CALLBACK);
if (operation != null) {
info.modelPort.addOperation(operation);
}
}
private Operation createAsyncOperation(Operation syncOperation, StyleAndUse styleAndUse, AsyncOperationType asyncType) {
boolean isRequestResponse = info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
if (!isRequestResponse) {
return null;
}
AsyncOperation operation = new AsyncOperation(info.operation, info.bindingOperation);
if (asyncType.equals(AsyncOperationType.CALLBACK)) {
operation.setUniqueName(info.operation.getUniqueName() + "_async_callback");
} else if (asyncType.equals(AsyncOperationType.POLLING)) {
operation.setUniqueName(info.operation.getUniqueName() + "_async_polling");
}
setDocumentationIfPresent(
operation,
info.portTypeOperation.getDocumentation());
operation.setAsyncType(asyncType);
operation.setSOAPAction(info.operation.getSOAPAction());
boolean unwrappable = info.operation.isWrapped();
operation.setWrapped(unwrappable);
SOAPBody soapRequestBody = getSOAPRequestBody();
Message inputMessage = getInputMessage();
Request request = new Request(inputMessage, errReceiver);
SOAPBody soapResponseBody = getSOAPResponseBody();
Message outputMessage = getOutputMessage();
Response response = new Response(outputMessage, errReceiver);
java.util.List<String> parameterList = getAsynParameterOrder();
List<Parameter> inParameters = null;
if (isOperationDocumentLiteral(styleAndUse)) {
inParameters = getRequestParameters(request, parameterList);
if (unwrappable) {
List<String> unwrappedParameterList = new ArrayList<String>();
if (inputMessage != null) {
Iterator<MessagePart> parts = inputMessage.parts();
if (parts.hasNext()) {
MessagePart part = parts.next();
JAXBType jaxbType = getJAXBType(part);
List<JAXBProperty> memberList = jaxbType.getWrapperChildren();
Iterator<JAXBProperty> props = memberList.iterator();
while (props.hasNext()) {
JAXBProperty prop = props.next();
unwrappedParameterList.add(prop.getElementName().getLocalPart());
}
}
}
parameterList.clear();
parameterList.addAll(unwrappedParameterList);
}
} else if (isOperationRpcLiteral(styleAndUse)) {
String operationName = info.bindingOperation.getName();
Block reqBlock = null;
if (inputMessage != null) {
QName name = new QName(getRequestNamespaceURI(soapRequestBody), operationName);
RpcLitStructure rpcStruct = new RpcLitStructure(name, getJAXBModelBuilder().getJAXBModel());
rpcStruct.setJavaType(new JavaSimpleType("com.sun.xml.internal.ws.encoding.jaxb.RpcLitPayload", null));
reqBlock = new Block(name, rpcStruct, inputMessage);
request.addBodyBlock(reqBlock);
}
inParameters = createRpcLitRequestParameters(request, parameterList, reqBlock);
}
Iterator<Block> blocks = info.operation.getResponse().getBodyBlocks();
while (blocks.hasNext()) {
response.addBodyBlock(blocks.next());
}
blocks = info.operation.getResponse().getHeaderBlocks();
while (blocks.hasNext()) {
response.addHeaderBlock(blocks.next());
}
blocks = info.operation.getResponse().getAttachmentBlocks();
while (blocks.hasNext()) {
response.addAttachmentBlock(blocks.next());
}
List<MessagePart> outputParts = outputMessage.getParts();
int numOfOutMsgParts = outputParts.size();
if (numOfOutMsgParts == 1) {
MessagePart part = outputParts.get(0);
if (isOperationDocumentLiteral(styleAndUse)) {
JAXBType type = getJAXBType(part);
operation.setResponseBean(type);
} else if (isOperationRpcLiteral(styleAndUse)) {
String operationName = info.bindingOperation.getName();
Block resBlock = info.operation.getResponse().getBodyBlocksMap().get(new QName(getResponseNamespaceURI(soapResponseBody),
operationName + "Response"));
RpcLitStructure resBean = (RpcLitStructure) resBlock.getType();
List<RpcLitMember> members = resBean.getRpcLitMembers();
operation.setResponseBean(members.get(0));
}
} else {
String nspace = "";
QName responseBeanName = new QName(nspace, getAsyncOperationName(info.operation) + "Response");
JAXBType responseBeanType = getJAXBModelBuilder().getJAXBType(responseBeanName);
if (responseBeanType == null) {
error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_RESPONSEBEAN_NOTFOUND(info.operation.getName()));
}
operation.setResponseBean(responseBeanType);
}
QName respBeanName = new QName(soapResponseBody.getNamespace(), getAsyncOperationName(info.operation) + "Response");
Block block = new Block(respBeanName, operation.getResponseBeanType(), outputMessage);
JavaType respJavaType = operation.getResponseBeanJavaType();
JAXBType respType = new JAXBType(respBeanName, respJavaType);
Parameter respParam = ModelerUtils.createParameter(info.operation.getName() + "Response", respType, block);
respParam.setParameterIndex(-1);
response.addParameter(respParam);
operation.setProperty(WSDL_RESULT_PARAMETER, respParam.getName());
int parameterOrderPosition = 0;
for (String name : parameterList) {
Parameter inParameter = ModelerUtils.getParameter(name, inParameters);
if (inParameter == null) {
if (options.isExtensionMode()) {
warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_WARNING_IGNORING_OPERATION_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
} else {
error(info.operation.getEntity(), ModelerMessages.WSDLMODELER_ERROR_PART_NOT_FOUND(info.operation.getName().getLocalPart(), name));
}
return null;
}
request.addParameter(inParameter);
inParameter.setParameterIndex(parameterOrderPosition);
parameterOrderPosition++;
}
operation.setResponse(response);
if (operation.getAsyncType().equals(AsyncOperationType.CALLBACK)) {
JavaType cbJavaType = operation.getCallBackType();
JAXBType callbackType = new JAXBType(respBeanName, cbJavaType);
Parameter cbParam = ModelerUtils.createParameter("asyncHandler", callbackType, block);
request.addParameter(cbParam);
}
operation.setRequest(request);
return operation;
}
protected boolean isAsync(com.sun.tools.internal.ws.wsdl.document.PortType portType, com.sun.tools.internal.ws.wsdl.document.Operation wsdlOperation) {
JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(wsdlOperation, JAXWSBinding.class);
Boolean isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
if (isAsync != null) {
return isAsync;
}
jaxwsCustomization = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
if (isAsync != null) {
return isAsync;
}
jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
isAsync = (jaxwsCustomization != null) ? jaxwsCustomization.isEnableAsyncMapping() : null;
if (isAsync != null) {
return isAsync;
}
return false;
}
protected void handleLiteralSOAPHeaders(Request request, Response response, Iterator headerParts, Set duplicateNames, @NotNull List<String> definitiveParameterList, boolean processRequest) {
QName headerName;
Block headerBlock;
JAXBType jaxbType;
int parameterOrderPosition = definitiveParameterList.size();
while (headerParts.hasNext()) {
MessagePart part = (MessagePart) headerParts.next();
headerName = part.getDescriptor();
jaxbType = getJAXBType(part);
headerBlock = new Block(headerName, jaxbType, part);
TWSDLExtensible ext;
if (processRequest) {
ext = info.bindingOperation.getInput();
} else {
ext = info.bindingOperation.getOutput();
}
Message headerMessage = getHeaderMessage(part, ext);
if (processRequest) {
request.addHeaderBlock(headerBlock);
} else {
response.addHeaderBlock(headerBlock);
}
Parameter parameter = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
parameter.setParameterIndex(parameterOrderPosition);
setCustomizedParameterName(info.bindingOperation, headerMessage, part, parameter, false);
if (processRequest) {
request.addParameter(parameter);
definitiveParameterList.add(parameter.getName());
} else {
for (String inParamName : definitiveParameterList) {
if (inParamName.equals(parameter.getName())) {
Parameter inParam = request.getParameterByName(inParamName);
parameter.setLinkedParameter(inParam);
inParam.setLinkedParameter(parameter);
parameter.setParameterIndex(inParam.getParameterIndex());
}
}
if (!definitiveParameterList.contains(parameter.getName())) {
definitiveParameterList.add(parameter.getName());
}
response.addParameter(parameter);
}
parameterOrderPosition++;
}
}
protected void handleLiteralSOAPFault(Response response, Set duplicateNames) {
for (BindingFault bindingFault : info.bindingOperation.faults()) {
com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault = null;
for (com.sun.tools.internal.ws.wsdl.document.Fault aFault : info.portTypeOperation.faults()) {
if (aFault.getName().equals(bindingFault.getName())) {
if (portTypeFault != null) {
error(portTypeFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_UNIQUE(bindingFault.getName(), info.bindingOperation.getName()));
}
portTypeFault = aFault;
}
}
if (portTypeFault == null) {
error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NOT_FOUND(bindingFault.getName(), info.bindingOperation.getName()));
}
}
for ( com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault : info.portTypeOperation.faults()) {
BindingFault bindingFault = null ;
for(BindingFault bFault: info.bindingOperation.faults()) {
if (bFault.getName().equals(portTypeFault.getName())) {
bindingFault = bFault;
}
}
if(bindingFault == null) {
warning(portTypeFault,ModelerMessages.WSDLMODELER_INVALID_PORT_TYPE_FAULT_NOT_FOUND(portTypeFault.getName(),info.portTypeOperation.getName()));
}
String faultName = getFaultClassName(portTypeFault);
Fault fault = new Fault(faultName, portTypeFault);
fault.setWsdlFaultName(portTypeFault.getName());
setDocumentationIfPresent(fault, portTypeFault.getDocumentation());
if (bindingFault != null) {
SOAPFault soapFault = (SOAPFault) getExtensionOfType(bindingFault, SOAPFault.class);
if (soapFault == null) {
if (options.isExtensionMode()) {
warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
soapFault = new SOAPFault(new LocatorImpl());
} else {
error(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_OUTPUT_MISSING_SOAP_FAULT(bindingFault.getName(), info.bindingOperation.getName()));
}
}
if (!soapFault.isLiteral()) {
if (options.isExtensionMode()) {
warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_IGNORING_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
} else {
error(soapFault, ModelerMessages.WSDLMODELER_INVALID_OPERATION_FAULT_NOT_LITERAL(bindingFault.getName(), info.bindingOperation.getName()));
}
continue;
}
if (soapFault.getName() == null) {
warning(bindingFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_NO_SOAP_FAULT_NAME(bindingFault.getName(), info.bindingOperation.getName()));
} else if (!soapFault.getName().equals(bindingFault.getName())) {
warning(soapFault, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_WRONG_SOAP_FAULT_NAME(soapFault.getName(), bindingFault.getName(), info.bindingOperation.getName()));
} else if (soapFault.getNamespace() != null) {
warning(soapFault, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:fault", soapFault.getName()));
}
}
com.sun.tools.internal.ws.wsdl.document.Message faultMessage = portTypeFault.resolveMessage(info.document);
Iterator iter2 = faultMessage.parts();
if (!iter2.hasNext()) {
error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_EMPTY_MESSAGE(portTypeFault.getName(), faultMessage.getName()));
}
MessagePart faultPart = (MessagePart) iter2.next();
QName faultQName = faultPart.getDescriptor();
if (duplicateNames.contains(faultQName)) {
warning(faultPart, ModelerMessages.WSDLMODELER_DUPLICATE_FAULT_SOAP_NAME(portTypeFault.getName(), info.portTypeOperation.getName(), faultPart.getName()));
continue;
}
if (iter2.hasNext()) {
error(faultMessage, ModelerMessages.WSDLMODELER_INVALID_BINDING_FAULT_MESSAGE_HAS_MORE_THAN_ONE_PART(portTypeFault.getName(), faultMessage.getName()));
}
if (faultPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
if (options.isExtensionMode()) {
warning(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
} else {
error(faultPart, ModelerMessages.WSDLMODELER_INVALID_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(faultMessage.getName(), faultPart.getName()));
}
}
JAXBType jaxbType = getJAXBType(faultPart);
fault.setElementName(faultPart.getDescriptor());
fault.setJavaMemberName(Names.getExceptionClassMemberName());
Block faultBlock = new Block(faultQName, jaxbType, faultPart);
fault.setBlock(faultBlock);
if (!response.getFaultBlocksMap().containsKey(faultBlock.getName())) {
response.addFaultBlock(faultBlock);
}
info.operation.addFault(fault);
}
}
private String getFaultClassName(com.sun.tools.internal.ws.wsdl.document.Fault portTypeFault) {
JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeFault, JAXWSBinding.class);
if (jaxwsBinding != null) {
CustomName className = jaxwsBinding.getClassName();
if (className != null) {
return makePackageQualified(className.getName());
}
}
return makePackageQualified(BindingHelper.mangleNameToClassName(portTypeFault.getMessage().getLocalPart()));
}
protected boolean setMessagePartsBinding(StyleAndUse styleAndUse) {
SOAPBody inBody = getSOAPRequestBody();
Message inMessage = getInputMessage();
if (!setMessagePartsBinding(inBody, inMessage, styleAndUse, true)) {
return false;
}
if (isRequestResponse()) {
SOAPBody outBody = getSOAPResponseBody();
Message outMessage = getOutputMessage();
if (!setMessagePartsBinding(outBody, outMessage, styleAndUse, false)) {
return false;
}
}
return true;
}
protected boolean setMessagePartsBinding(SOAPBody body, Message message, StyleAndUse styleAndUse, boolean isInput) {
List<MessagePart> mimeParts;
List<MessagePart> headerParts;
List<MessagePart> bodyParts = getBodyParts(body, message);
if (isInput) {
headerParts = getHeaderPartsFromMessage(message, isInput);
mimeParts = getMimeContentParts(message, info.bindingOperation.getInput());
} else {
headerParts = getHeaderPartsFromMessage(message, isInput);
mimeParts = getMimeContentParts(message, info.bindingOperation.getOutput());
}
if (bodyParts == null) {
bodyParts = new ArrayList<MessagePart>();
for (Iterator<MessagePart> iter = message.parts(); iter.hasNext();) {
MessagePart mPart = iter.next();
if (mimeParts.contains(mPart) || headerParts.contains(mPart) || boundToFault(mPart.getName())) {
if (options.isExtensionMode()) {
warning(mPart, ModelerMessages.WSDLMODELER_WARNING_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
} else {
error(mPart, ModelerMessages.WSDLMODELER_INVALID_BINDING_OPERATION_MULTIPLE_PART_BINDING(info.bindingOperation.getName(), mPart.getName()));
}
}
bodyParts.add(mPart);
}
}
for (Iterator iter = message.parts(); iter.hasNext();) {
MessagePart mPart = (MessagePart) iter.next();
if (mimeParts.contains(mPart)) {
mPart.setBindingExtensibilityElementKind(MessagePart.WSDL_MIME_BINDING);
} else if (headerParts.contains(mPart)) {
mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
} else if (bodyParts.contains(mPart)) {
mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
} else {
mPart.setBindingExtensibilityElementKind(MessagePart.PART_NOT_BOUNDED);
}
}
if (isOperationDocumentLiteral(styleAndUse) && bodyParts.size() > 1) {
if (options.isExtensionMode()) {
warning(message, ModelerMessages.WSDLMODELER_WARNING_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));
} else {
error(message, ModelerMessages.WSDLMODELER_INVALID_OPERATION_MORE_THAN_ONE_PART_IN_MESSAGE(info.portTypeOperation.getName()));
}
return false;
}
return true;
}
private boolean boundToFault(String partName) {
for (BindingFault bindingFault : info.bindingOperation.faults()) {
if (partName.equals(bindingFault.getName())) {
return true;
}
}
return false;
}
private List<MessagePart> getBodyParts(SOAPBody body, Message message) {
String bodyParts = body.getParts();
if (bodyParts != null) {
List<MessagePart> partsList = new ArrayList<MessagePart>();
StringTokenizer in = new StringTokenizer(bodyParts.trim(), " ");
while (in.hasMoreTokens()) {
String part = in.nextToken();
MessagePart mPart = message.getPart(part);
if (null == mPart) {
error(message, ModelerMessages.WSDLMODELER_ERROR_PARTS_NOT_FOUND(part, message.getName()));
}
mPart.setBindingExtensibilityElementKind(MessagePart.SOAP_BODY_BINDING);
partsList.add(mPart);
}
return partsList;
}
return null;
}
List<MessagePart> (BindingOperation bindingOperation,Message message, boolean isInput){
List<MessagePart> headerParts = new ArrayList<MessagePart>();
List<MessagePart> parts = message.getParts();
List<MessagePart> headers = getHeaderParts(bindingOperation, isInput);
for(MessagePart part: headers){
if (parts.contains(part)) {
continue;
}
headerParts.add(part);
}
return headerParts;
}
private List<MessagePart> (Message message, boolean isInput) {
List<MessagePart> headerParts = new ArrayList<MessagePart>();
Iterator<MessagePart> parts = message.parts();
List<MessagePart> headers = getHeaderParts(info.bindingOperation, isInput);
while (parts.hasNext()) {
MessagePart part = parts.next();
if (headers.contains(part)) {
headerParts.add(part);
}
}
return headerParts;
}
private Message (MessagePart part, TWSDLExtensible ext) {
Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
while (headers.hasNext()) {
SOAPHeader header = headers.next();
if (!header.isLiteral()) {
continue;
}
com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(), document);
if (headerMessage == null) {
continue;
}
MessagePart headerPart = headerMessage.getPart(header.getPart());
if (headerPart == part) {
return headerMessage;
}
}
return null;
}
private List<MessagePart> (BindingOperation bindingOperation, boolean isInput) {
TWSDLExtensible ext;
if (isInput) {
ext = bindingOperation.getInput();
} else {
ext = bindingOperation.getOutput();
}
List<MessagePart> parts = new ArrayList<MessagePart>();
Iterator<SOAPHeader> headers = getHeaderExtensions(ext).iterator();
while (headers.hasNext()) {
SOAPHeader header = headers.next();
if (!header.isLiteral()) {
error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_LITERAL(header.getPart(), bindingOperation.getName()));
}
if (header.getNamespace() != null) {
warning(header, ModelerMessages.WSDLMODELER_WARNING_R_2716_R_2726("soapbind:header", bindingOperation.getName()));
}
com.sun.tools.internal.ws.wsdl.document.Message headerMessage = findMessage(header.getMessage(),document);
if (headerMessage == null) {
error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_CANT_RESOLVE_MESSAGE(header.getMessage(), bindingOperation.getName()));
}
MessagePart part = headerMessage.getPart(header.getPart());
if (part == null) {
error(header, ModelerMessages.WSDLMODELER_INVALID_HEADER_NOT_FOUND(header.getPart(), bindingOperation.getName()));
}
if (part.getDescriptorKind() != SchemaKinds.XSD_ELEMENT) {
if (options.isExtensionMode()) {
warning(part, ModelerMessages.WSDLMODELER_INVALID_HEADER_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(part.getName(), bindingOperation.getName()));
} else {
error(part, ModelerMessages.WSDLMODELER_INVALID_HEADER_MESSAGE_PART_MUST_HAVE_ELEMENT_DESCRIPTOR(part.getName(), bindingOperation.getName()));
}
}
part.setBindingExtensibilityElementKind(MessagePart.SOAP_HEADER_BINDING);
parts.add(part);
}
return parts;
}
private boolean isOperationDocumentLiteral(StyleAndUse styleAndUse) {
return StyleAndUse.DOC_LITERAL == styleAndUse;
}
private boolean isOperationRpcLiteral(StyleAndUse styleAndUse) {
return StyleAndUse.RPC_LITERAL == styleAndUse;
}
private JAXBType getJAXBType(MessagePart part) {
JAXBType type;
QName name = part.getDescriptor();
if (part.getDescriptorKind().equals(SchemaKinds.XSD_ELEMENT)) {
type = getJAXBModelBuilder().getJAXBType(name);
if(type == null){
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
}
} else {
S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
TypeAndAnnotation typeAnno = jaxbModel.getJavaType(name);
if (typeAnno == null) {
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(name, part.getName()));
}
JavaType javaType = new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno));
type = new JAXBType(new QName("", part.getName()), javaType);
}
return type;
}
private List<Parameter> getDoclitParameters(Request req, Response res, List<MessagePart> parameterList) {
if (parameterList.isEmpty()) {
return new ArrayList<Parameter>();
}
List<Parameter> params = new ArrayList<Parameter>();
Message inMsg = getInputMessage();
Message outMsg = getOutputMessage();
boolean unwrappable = isUnwrappable();
List<Parameter> outParams = null;
int pIndex = 0;
for (MessagePart part : parameterList) {
QName reqBodyName = part.getDescriptor();
JAXBType jaxbType = getJAXBType(part);
Block block = new Block(reqBodyName, jaxbType, part);
if (unwrappable) {
JAXBStructuredType jaxbStructType = ModelerUtils.createJAXBStructureType(jaxbType);
block = new Block(reqBodyName, jaxbStructType, part);
if (ModelerUtils.isBoundToSOAPBody(part)) {
if (part.isIN()) {
req.addBodyBlock(block);
} else if (part.isOUT()) {
res.addBodyBlock(block);
} else if (part.isINOUT()) {
req.addBodyBlock(block);
res.addBodyBlock(block);
}
} else if (ModelerUtils.isUnbound(part)) {
if (part.isIN()) {
req.addUnboundBlock(block);
} else if (part.isOUT()) {
res.addUnboundBlock(block);
} else if (part.isINOUT()) {
req.addUnboundBlock(block);
res.addUnboundBlock(block);
}
}
if (part.isIN() || part.isINOUT()) {
params = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
int index = 0;
Mode mode = part.isINOUT() ? Mode.INOUT : Mode.IN;
for (Parameter param : params) {
param.setParameterIndex(index++);
param.setMode(mode);
setCustomizedParameterName(info.portTypeOperation, inMsg, part, param, unwrappable);
}
} else if (part.isOUT()) {
outParams = ModelerUtils.createUnwrappedParameters(jaxbStructType, block);
for (Parameter param : outParams) {
param.setMode(Mode.OUT);
setCustomizedParameterName(info.portTypeOperation, outMsg, part, param, unwrappable);
}
}
} else {
if (ModelerUtils.isBoundToSOAPBody(part)) {
if (part.isIN()) {
req.addBodyBlock(block);
} else if (part.isOUT()) {
res.addBodyBlock(block);
} else if (part.isINOUT()) {
req.addBodyBlock(block);
res.addBodyBlock(block);
}
} else if (ModelerUtils.isBoundToSOAPHeader(part)) {
if (part.isIN()) {
req.addHeaderBlock(block);
} else if (part.isOUT()) {
res.addHeaderBlock(block);
} else if (part.isINOUT()) {
req.addHeaderBlock(block);
res.addHeaderBlock(block);
}
} else if (ModelerUtils.isBoundToMimeContent(part)) {
List<MIMEContent> mimeContents;
if (part.isIN()) {
mimeContents = getMimeContents(info.bindingOperation.getInput(),
getInputMessage(), part.getName());
jaxbType = getAttachmentType(mimeContents, part);
block = new Block(jaxbType.getName(), jaxbType, part);
req.addAttachmentBlock(block);
} else if (part.isOUT()) {
mimeContents = getMimeContents(info.bindingOperation.getOutput(),
getOutputMessage(), part.getName());
jaxbType = getAttachmentType(mimeContents, part);
block = new Block(jaxbType.getName(), jaxbType, part);
res.addAttachmentBlock(block);
} else if (part.isINOUT()) {
mimeContents = getMimeContents(info.bindingOperation.getInput(),
getInputMessage(), part.getName());
jaxbType = getAttachmentType(mimeContents, part);
block = new Block(jaxbType.getName(), jaxbType, part);
req.addAttachmentBlock(block);
res.addAttachmentBlock(block);
mimeContents = getMimeContents(info.bindingOperation.getOutput(),
getOutputMessage(), part.getName());
JAXBType outJaxbType = getAttachmentType(mimeContents, part);
String inType = jaxbType.getJavaType().getType().getName();
String outType = outJaxbType.getJavaType().getType().getName();
TypeAndAnnotation inTa = jaxbType.getJavaType().getType().getTypeAnn();
TypeAndAnnotation outTa = outJaxbType.getJavaType().getType().getTypeAnn();
if ((((inTa != null) && (outTa != null) && inTa.equals(outTa))) && !inType.equals(outType)) {
String javaType = "javax.activation.DataHandler";
JType jt = options.getCodeModel().ref(javaType);
JAXBTypeAndAnnotation jaxbTa = jaxbType.getJavaType().getType();
jaxbTa.setType(jt);
}
}
} else if (ModelerUtils.isUnbound(part)) {
if (part.isIN()) {
req.addUnboundBlock(block);
} else if (part.isOUT()) {
res.addUnboundBlock(block);
} else if (part.isINOUT()) {
req.addUnboundBlock(block);
res.addUnboundBlock(block);
}
}
Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, block);
param.setMode(part.getMode());
if (part.isReturn()) {
param.setParameterIndex(-1);
} else {
param.setParameterIndex(pIndex++);
}
if (part.isIN()) {
setCustomizedParameterName(info.bindingOperation, inMsg, part, param, false);
} else if (outMsg != null) {
setCustomizedParameterName(info.bindingOperation, outMsg, part, param, false);
}
params.add(param);
}
}
if (unwrappable && (outParams != null)) {
int index = params.size();
for (Parameter param : outParams) {
if (BindingHelper.mangleNameToVariableName(param.getName()).equals("return")) {
param.setParameterIndex(-1);
} else {
Parameter inParam = ModelerUtils.getParameter(param.getName(), params);
if ((inParam != null) && inParam.isIN()) {
QName inElementName = inParam.getType().getName();
QName outElementName = param.getType().getName();
String inJavaType = inParam.getTypeName();
String outJavaType = param.getTypeName();
TypeAndAnnotation inTa = inParam.getType().getJavaType().getType().getTypeAnn();
TypeAndAnnotation outTa = param.getType().getJavaType().getType().getTypeAnn();
QName inRawTypeName = ModelerUtils.getRawTypeName(inParam);
QName outRawTypeName = ModelerUtils.getRawTypeName(param);
if (inElementName.getLocalPart().equals(outElementName.getLocalPart()) &&
inJavaType.equals(outJavaType) &&
(inTa == null || outTa == null || inTa.equals(outTa)) &&
(inRawTypeName == null || outRawTypeName == null || inRawTypeName.equals(outRawTypeName))) {
inParam.setMode(Mode.INOUT);
continue;
}
}
if (outParams.size() == 1) {
param.setParameterIndex(-1);
} else {
param.setParameterIndex(index++);
}
}
params.add(param);
}
}
return params;
}
private List<Parameter> getRpcLitParameters(Request req, Response res, Block reqBlock, Block resBlock, List<MessagePart> paramList) {
List<Parameter> params = new ArrayList<Parameter>();
Message inMsg = getInputMessage();
Message outMsg = getOutputMessage();
S2JJAXBModel jaxbModel = ((RpcLitStructure) reqBlock.getType()).getJaxbModel().getS2JJAXBModel();
List<Parameter> inParams = ModelerUtils.createRpcLitParameters(inMsg, reqBlock, jaxbModel, errReceiver);
List<Parameter> outParams = null;
if (outMsg != null) {
outParams = ModelerUtils.createRpcLitParameters(outMsg, resBlock, jaxbModel, errReceiver);
}
int index = 0;
for (MessagePart part : paramList) {
Parameter param = null;
if (ModelerUtils.isBoundToSOAPBody(part)) {
if (part.isIN()) {
param = ModelerUtils.getParameter(part.getName(), inParams);
} else if (outParams != null) {
param = ModelerUtils.getParameter(part.getName(), outParams);
}
} else if (ModelerUtils.isBoundToSOAPHeader(part)) {
QName headerName = part.getDescriptor();
JAXBType jaxbType = getJAXBType(part);
Block headerBlock = new Block(headerName, jaxbType, part);
param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
if (part.isIN()) {
req.addHeaderBlock(headerBlock);
} else if (part.isOUT()) {
res.addHeaderBlock(headerBlock);
} else if (part.isINOUT()) {
req.addHeaderBlock(headerBlock);
res.addHeaderBlock(headerBlock);
}
} else if (ModelerUtils.isBoundToMimeContent(part)) {
List<MIMEContent> mimeContents;
if (part.isIN() || part.isINOUT()) {
mimeContents = getMimeContents(info.bindingOperation.getInput(),
getInputMessage(), part.getName());
} else {
mimeContents = getMimeContents(info.bindingOperation.getOutput(),
getOutputMessage(), part.getName());
}
JAXBType type = getAttachmentType(mimeContents, part);
Block mimeBlock = new Block(type.getName(), type, part);
param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
if (part.isIN()) {
req.addAttachmentBlock(mimeBlock);
} else if (part.isOUT()) {
res.addAttachmentBlock(mimeBlock);
} else if (part.isINOUT()) {
mimeContents = getMimeContents(info.bindingOperation.getOutput(),
getOutputMessage(), part.getName());
JAXBType outJaxbType = getAttachmentType(mimeContents, part);
String inType = type.getJavaType().getType().getName();
String outType = outJaxbType.getJavaType().getType().getName();
if (!inType.equals(outType)) {
String javaType = "javax.activation.DataHandler";
JType jt = options.getCodeModel().ref(javaType);
JAXBTypeAndAnnotation jaxbTa = type.getJavaType().getType();
jaxbTa.setType(jt);
}
req.addAttachmentBlock(mimeBlock);
res.addAttachmentBlock(mimeBlock);
}
} else if (ModelerUtils.isUnbound(part)) {
QName name = part.getDescriptor();
JAXBType type = getJAXBType(part);
Block unboundBlock = new Block(name, type, part);
if (part.isIN()) {
req.addUnboundBlock(unboundBlock);
} else if (part.isOUT()) {
res.addUnboundBlock(unboundBlock);
} else if (part.isINOUT()) {
req.addUnboundBlock(unboundBlock);
res.addUnboundBlock(unboundBlock);
}
param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
}
if (param != null) {
if (part.isReturn()) {
param.setParameterIndex(-1);
} else {
param.setParameterIndex(index++);
}
param.setMode(part.getMode());
params.add(param);
}
}
for (Parameter param : params) {
if (param.isIN()) {
setCustomizedParameterName(info.portTypeOperation, inMsg, inMsg.getPart(param.getName()), param, false);
} else if (outMsg != null) {
setCustomizedParameterName(info.portTypeOperation, outMsg, outMsg.getPart(param.getName()), param, false);
}
}
return params;
}
private List<Parameter> getRequestParameters(Request request, List<String> parameterList) {
Message inputMessage = getInputMessage();
if (inputMessage != null && !inputMessage.parts().hasNext()) {
return new ArrayList<Parameter>();
}
List<Parameter> inParameters = null;
QName reqBodyName;
Block reqBlock;
JAXBType jaxbReqType;
boolean unwrappable = isUnwrappable();
boolean doneSOAPBody = false;
for (String inParamName : parameterList) {
MessagePart part = inputMessage.getPart(inParamName);
if (part == null) {
continue;
}
reqBodyName = part.getDescriptor();
jaxbReqType = getJAXBType(part);
if (unwrappable) {
JAXBStructuredType jaxbRequestType = ModelerUtils.createJAXBStructureType(jaxbReqType);
reqBlock = new Block(reqBodyName, jaxbRequestType, part);
if (ModelerUtils.isBoundToSOAPBody(part)) {
request.addBodyBlock(reqBlock);
} else if (ModelerUtils.isUnbound(part)) {
request.addUnboundBlock(reqBlock);
}
inParameters = ModelerUtils.createUnwrappedParameters(jaxbRequestType, reqBlock);
for (Parameter param : inParameters) {
setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, unwrappable);
}
} else {
reqBlock = new Block(reqBodyName, jaxbReqType, part);
if (ModelerUtils.isBoundToSOAPBody(part) && !doneSOAPBody) {
doneSOAPBody = true;
request.addBodyBlock(reqBlock);
} else if (ModelerUtils.isBoundToSOAPHeader(part)) {
request.addHeaderBlock(reqBlock);
} else if (ModelerUtils.isBoundToMimeContent(part)) {
List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
getInputMessage(), part.getName());
jaxbReqType = getAttachmentType(mimeContents, part);
reqBlock = new Block(jaxbReqType.getName(), jaxbReqType, part);
request.addAttachmentBlock(reqBlock);
} else if (ModelerUtils.isUnbound(part)) {
request.addUnboundBlock(reqBlock);
}
if (inParameters == null) {
inParameters = new ArrayList<Parameter>();
}
Parameter param = ModelerUtils.createParameter(part.getName(), jaxbReqType, reqBlock);
setCustomizedParameterName(info.portTypeOperation, inputMessage, part, param, false);
inParameters.add(param);
}
}
return inParameters;
}
private void setCustomizedParameterName(TWSDLExtensible extension, Message msg, MessagePart part, Parameter param, boolean wrapperStyle) {
JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(extension, JAXWSBinding.class);
if (jaxwsBinding == null) {
return;
}
String paramName = part.getName();
QName elementName = part.getDescriptor();
if (wrapperStyle) {
elementName = param.getType().getName();
}
String customName = jaxwsBinding.getParameterName(msg.getName(), paramName, elementName, wrapperStyle);
if (customName != null && !customName.equals("")) {
param.setCustomName(customName);
}
}
@Override
protected boolean isConflictingPortClassName(String name) {
return false;
}
protected boolean isUnwrappable() {
if (!getWrapperStyleCustomization()) {
return false;
}
com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
com.sun.tools.internal.ws.wsdl.document.Message outputMessage = getOutputMessage();
if ((inputMessage != null && inputMessage.numParts() != 1)
|| (outputMessage != null && outputMessage.numParts() != 1)) {
return false;
}
MessagePart inputPart = inputMessage != null
? inputMessage.parts().next() : null;
MessagePart outputPart = outputMessage != null
? outputMessage.parts().next() : null;
String operationName = info.portTypeOperation.getName();
if ((inputPart != null && !inputPart.getDescriptor().getLocalPart().equals(operationName)) ||
(outputPart != null && outputPart.getDescriptorKind() != SchemaKinds.XSD_ELEMENT)) {
return false;
}
if (((inputPart != null) && (inputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING)) ||
((outputPart != null) && (outputPart.getBindingExtensibilityElementKind() != MessagePart.SOAP_BODY_BINDING))) {
return false;
}
if (inputPart != null) {
boolean inputWrappable = false;
JAXBType inputType = getJAXBType(inputPart);
if (inputType != null) {
inputWrappable = inputType.isUnwrappable();
}
if (outputPart == null) {
return inputWrappable;
}
JAXBType outputType = getJAXBType(outputPart);
if ((inputType != null) && (outputType != null)) {
return inputType.isUnwrappable() && outputType.isUnwrappable();
}
}
return false;
}
private boolean getWrapperStyleCustomization() {
com.sun.tools.internal.ws.wsdl.document.Operation portTypeOperation = info.portTypeOperation;
JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portTypeOperation, JAXWSBinding.class);
if (jaxwsBinding != null) {
Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
if (isWrappable != null) {
return isWrappable;
}
}
PortType portType = info.port.resolveBinding(document).resolvePortType(document);
jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
if (jaxwsBinding != null) {
Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
if (isWrappable != null) {
return isWrappable;
}
}
jaxwsBinding = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
if (jaxwsBinding != null) {
Boolean isWrappable = jaxwsBinding.isEnableWrapperStyle();
if (isWrappable != null) {
return isWrappable;
}
}
return true;
}
protected boolean isSingleInOutPart(Set inputParameterNames,
MessagePart outputPart) {
SOAPOperation soapOperation =
(SOAPOperation) getExtensionOfType(info.bindingOperation,
SOAPOperation.class);
if ((soapOperation != null) && (soapOperation.isDocument() || info.soapBinding.isDocument())) {
Iterator iter = getInputMessage().parts();
while (iter.hasNext()) {
MessagePart part = (MessagePart) iter.next();
if (outputPart.getName().equals(part.getName()) && outputPart.getDescriptor().equals(part.getDescriptor())) {
return true;
}
}
} else if (soapOperation != null && soapOperation.isRPC() || info.soapBinding.isRPC()) {
com.sun.tools.internal.ws.wsdl.document.Message inputMessage = getInputMessage();
if (inputParameterNames.contains(outputPart.getName())) {
if (inputMessage.getPart(outputPart.getName()).getDescriptor().equals(outputPart.getDescriptor())) {
return true;
}
}
}
return false;
}
private List<Parameter> createRpcLitRequestParameters(Request request, List<String> parameterList, Block block) {
Message message = getInputMessage();
S2JJAXBModel jaxbModel = ((RpcLitStructure) block.getType()).getJaxbModel().getS2JJAXBModel();
List<Parameter> parameters = ModelerUtils.createRpcLitParameters(message, block, jaxbModel, errReceiver);
for (String paramName : parameterList) {
MessagePart part = message.getPart(paramName);
if (part == null) {
continue;
}
if (ModelerUtils.isBoundToSOAPHeader(part)) {
if (parameters == null) {
parameters = new ArrayList<Parameter>();
}
QName headerName = part.getDescriptor();
JAXBType jaxbType = getJAXBType(part);
Block headerBlock = new Block(headerName, jaxbType, part);
request.addHeaderBlock(headerBlock);
Parameter param = ModelerUtils.createParameter(part.getName(), jaxbType, headerBlock);
if (param != null) {
parameters.add(param);
}
} else if (ModelerUtils.isBoundToMimeContent(part)) {
if (parameters == null) {
parameters = new ArrayList<Parameter>();
}
List<MIMEContent> mimeContents = getMimeContents(info.bindingOperation.getInput(),
getInputMessage(), paramName);
JAXBType type = getAttachmentType(mimeContents, part);
Block mimeBlock = new Block(type.getName(), type, part);
request.addAttachmentBlock(mimeBlock);
Parameter param = ModelerUtils.createParameter(part.getName(), type, mimeBlock);
if (param != null) {
parameters.add(param);
}
} else if (ModelerUtils.isUnbound(part)) {
if (parameters == null) {
parameters = new ArrayList<Parameter>();
}
QName name = part.getDescriptor();
JAXBType type = getJAXBType(part);
Block unboundBlock = new Block(name, type, part);
request.addUnboundBlock(unboundBlock);
Parameter param = ModelerUtils.createParameter(part.getName(), type, unboundBlock);
if (param != null) {
parameters.add(param);
}
}
}
for (Parameter param : parameters) {
setCustomizedParameterName(info.portTypeOperation, message, message.getPart(param.getName()), param, false);
}
return parameters;
}
private String getJavaTypeForMimeType(String mimeType) {
if (mimeType.equals("image/jpeg") || mimeType.equals("image/gif")) {
return "java.awt.Image";
} else if (mimeType.equals("text/xml") || mimeType.equals("application/xml")) {
return "javax.xml.transform.Source";
}
return "javax.activation.DataHandler";
}
private JAXBType getAttachmentType(List<MIMEContent> mimeContents, MessagePart part) {
if (!enableMimeContent()) {
return getJAXBType(part);
}
String javaType;
List<String> mimeTypes = getAlternateMimeTypes(mimeContents);
if (mimeTypes.size() > 1) {
javaType = "javax.activation.DataHandler";
} else {
javaType = getJavaTypeForMimeType(mimeTypes.get(0));
}
S2JJAXBModel jaxbModel = getJAXBModelBuilder().getJAXBModel().getS2JJAXBModel();
JType jt = options.getCodeModel().ref(javaType);
QName desc = part.getDescriptor();
TypeAndAnnotation typeAnno = null;
if (part.getDescriptorKind() == SchemaKinds.XSD_TYPE) {
typeAnno = jaxbModel.getJavaType(desc);
desc = new QName("", part.getName());
} else if (part.getDescriptorKind() == SchemaKinds.XSD_ELEMENT) {
typeAnno = getJAXBModelBuilder().getElementTypeAndAnn(desc);
if(typeAnno == null){
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(part.getDescriptor(), part.getName()));
}
for (String mimeType : mimeTypes) {
if ((!mimeType.equals("text/xml") && !mimeType.equals("application/xml"))) {
warning(part, ModelerMessages.MIMEMODELER_ELEMENT_PART_INVALID_ELEMENT_MIME_TYPE(part.getName(), mimeType));
}
}
}
if (typeAnno == null) {
error(part, ModelerMessages.WSDLMODELER_JAXB_JAVATYPE_NOTFOUND(desc, part.getName()));
}
return new JAXBType(desc, new JavaSimpleType(new JAXBTypeAndAnnotation(typeAnno, jt)),
null, getJAXBModelBuilder().getJAXBModel());
}
protected void buildJAXBModel(WSDLDocument wsdlDocument) {
JAXBModelBuilder tempJaxbModelBuilder = new JAXBModelBuilder(options, classNameCollector, forest, errReceiver);
if (explicitDefaultPackage != null) {
tempJaxbModelBuilder.getJAXBSchemaCompiler().forcePackageName(options.defaultPackage);
} else {
options.defaultPackage = getJavaPackage();
}
List<InputSource> schemas = PseudoSchemaBuilder.build(this, options, errReceiver);
for (InputSource schema : schemas) {
tempJaxbModelBuilder.getJAXBSchemaCompiler().parseSchema(schema);
}
tempJaxbModelBuilder.bind();
this.jaxbModelBuilder = tempJaxbModelBuilder;
}
protected String getJavaPackage() {
String jaxwsPackage = null;
JAXWSBinding jaxwsCustomization = (JAXWSBinding) getExtensionOfType(document.getDefinitions(), JAXWSBinding.class);
if (jaxwsCustomization != null && jaxwsCustomization.getJaxwsPackage() != null) {
jaxwsPackage = jaxwsCustomization.getJaxwsPackage().getName();
}
if (jaxwsPackage != null) {
return jaxwsPackage;
}
String wsdlUri = document.getDefinitions().getTargetNamespaceURI();
return XJC.getDefaultPackageName(wsdlUri);
}
protected void createJavaInterfaceForProviderPort(Port port) {
String interfaceName = "javax.xml.ws.Provider";
JavaInterface intf = new JavaInterface(interfaceName);
port.setJavaInterface(intf);
}
protected void createJavaInterfaceForPort(Port port, boolean isProvider) {
if (isProvider) {
createJavaInterfaceForProviderPort(port);
return;
}
String interfaceName = getJavaNameOfSEI(port);
if (isConflictingPortClassName(interfaceName)) {
interfaceName += "_PortType";
}
JavaInterface intf = new JavaInterface(interfaceName);
for (Operation operation : port.getOperations()) {
createJavaMethodForOperation(
port,
operation,
intf);
for (JavaParameter jParam : operation.getJavaMethod().getParametersList()) {
Parameter param = jParam.getParameter();
if (param.getCustomName() != null) {
jParam.setName(param.getCustomName());
}
}
}
port.setJavaInterface(intf);
}
protected String getServiceInterfaceName(QName serviceQName, com.sun.tools.internal.ws.wsdl.document.Service wsdlService) {
String serviceName = wsdlService.getName();
JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(wsdlService, JAXWSBinding.class);
if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
CustomName name = jaxwsCust.getClassName();
if (name != null && !name.getName().equals("")) {
return makePackageQualified(name.getName());
}
}
return makePackageQualified(BindingHelper.mangleNameToClassName(serviceName));
}
protected String getJavaNameOfSEI(Port port) {
QName portTypeName =
(QName) port.getProperty(
ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
PortType pt = (PortType) document.find(Kinds.PORT_TYPE, portTypeName);
port.portTypes.put(portTypeName, pt);
JAXWSBinding jaxwsCust = (JAXWSBinding) getExtensionOfType(pt, JAXWSBinding.class);
if (jaxwsCust != null && jaxwsCust.getClassName() != null) {
CustomName name = jaxwsCust.getClassName();
if (name != null && !name.getName().equals("")) {
return makePackageQualified(name.getName());
}
}
String interfaceName;
if (portTypeName != null) {
interfaceName =
makePackageQualified(BindingHelper.mangleNameToClassName(portTypeName.getLocalPart()));
} else {
interfaceName =
makePackageQualified(BindingHelper.mangleNameToClassName(port.getName().getLocalPart()));
}
return interfaceName;
}
private void createJavaMethodForAsyncOperation(Port port, Operation operation,
JavaInterface intf) {
String candidateName = getJavaNameForOperation(operation);
JavaMethod method = new JavaMethod(candidateName, options, errReceiver);
assert (operation.getRequest() != null);
Response response = operation.getResponse();
for (Iterator iter = operation.getRequest().getParameters(); iter.hasNext();) {
Parameter parameter = (Parameter) iter.next();
if (parameter.getJavaParameter() != null) {
error(operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_OPERATION(operation.getName().getLocalPart()));
}
JavaType parameterType = parameter.getType().getJavaType();
JavaParameter javaParameter =
new JavaParameter(
BindingHelper.mangleNameToVariableName(parameter.getName()),
parameterType,
parameter,
parameter.getLinkedParameter() != null);
if (javaParameter.isHolder()) {
javaParameter.setHolderName(javax.xml.ws.Holder.class.getName());
}
method.addParameter(javaParameter);
parameter.setJavaParameter(javaParameter);
}
if (response != null) {
String resultParameterName =
(String) operation.getProperty(WSDL_RESULT_PARAMETER);
Parameter resultParameter =
response.getParameterByName(resultParameterName);
JavaType returnType = resultParameter.getType().getJavaType();
method.setReturnType(returnType);
}
operation.setJavaMethod(method);
intf.addMethod(method);
}
protected void createJavaMethodForOperation(Port port, Operation operation, JavaInterface intf) {
if ((operation instanceof AsyncOperation)) {
createJavaMethodForAsyncOperation(port, operation, intf);
return;
}
String candidateName = getJavaNameForOperation(operation);
JavaMethod method = new JavaMethod(candidateName, options, errReceiver);
Parameter returnParam = (Parameter) operation.getProperty(WSDL_RESULT_PARAMETER);
if (returnParam != null) {
JavaType parameterType = returnParam.getType().getJavaType();
method.setReturnType(parameterType);
} else {
method.setReturnType(JavaSimpleTypeCreator.VOID_JAVATYPE);
}
List<Parameter> parameterOrder = (List<Parameter>) operation.getProperty(WSDL_PARAMETER_ORDER);
for (Parameter param : parameterOrder) {
JavaType parameterType = param.getType().getJavaType();
String name = (param.getCustomName() != null) ? param.getCustomName() : param.getName();
name = BindingHelper.mangleNameToVariableName(name);
if(Names.isJavaReservedWord(name)){
name = "_"+name;
}
JavaParameter javaParameter =
new JavaParameter(
name,
parameterType,
param,
param.isINOUT() || param.isOUT());
if (javaParameter.isHolder()) {
javaParameter.setHolderName(javax.xml.ws.Holder.class.getName());
}
method.addParameter(javaParameter);
param.setJavaParameter(javaParameter);
}
operation.setJavaMethod(method);
intf.addMethod(method);
String opName = BindingHelper.mangleNameToVariableName(operation.getName().getLocalPart());
for (Iterator iter = operation.getFaults();
iter != null && iter.hasNext();
) {
Fault fault = (Fault) iter.next();
createJavaExceptionFromLiteralType(fault, port, opName);
}
JavaException javaException;
Fault fault;
for (Iterator iter = operation.getFaults(); iter.hasNext();) {
fault = (Fault) iter.next();
javaException = fault.getJavaException();
method.addException(javaException.getName());
}
}
protected boolean createJavaExceptionFromLiteralType(Fault fault, com.sun.tools.internal.ws.processor.model.Port port, String operationName) {
JAXBType faultType = (JAXBType) fault.getBlock().getType();
String exceptionName = fault.getName();
JAXBStructuredType jaxbStruct = new JAXBStructuredType(new QName(
fault.getBlock().getName().getNamespaceURI(),
fault.getName()));
QName memberName = fault.getElementName();
JAXBElementMember jaxbMember =
new JAXBElementMember(memberName, faultType);
String javaMemberName = getLiteralJavaMemberName(fault);
JavaStructureMember javaMember = new JavaStructureMember(
javaMemberName,
faultType.getJavaType(),
jaxbMember);
jaxbMember.setJavaStructureMember(javaMember);
javaMember.setReadMethod(Names.getJavaMemberReadMethod(javaMember));
javaMember.setInherited(false);
jaxbMember.setJavaStructureMember(javaMember);
jaxbStruct.add(jaxbMember);
if (isConflictingExceptionClassName(exceptionName)) {
exceptionName += "_Exception";
}
JavaException existingJavaException = _javaExceptions.get(exceptionName);
if (existingJavaException != null) {
if (existingJavaException.getName().equals(exceptionName)) {
if (((JAXBType) existingJavaException.getOwner()).getName().equals(jaxbStruct.getName())
|| ModelerUtils.isEquivalentLiteralStructures(jaxbStruct, (JAXBStructuredType) existingJavaException.getOwner())) {
if (faultType instanceof JAXBStructuredType) {
fault.getBlock().setType((JAXBType) existingJavaException.getOwner());
}
fault.setJavaException(existingJavaException);
return false;
}
}
}
JavaException javaException = new JavaException(exceptionName, false, jaxbStruct);
javaException.add(javaMember);
jaxbStruct.setJavaType(javaException);
_javaExceptions.put(javaException.getName(), javaException);
fault.setJavaException(javaException);
return true;
}
protected boolean isRequestResponse() {
return info.portTypeOperation.getStyle() == OperationStyle.REQUEST_RESPONSE;
}
protected java.util.List<String> getAsynParameterOrder() {
java.util.List<String> parameterList = new ArrayList<String>();
Message inputMessage = getInputMessage();
List<MessagePart> inputParts = inputMessage.getParts();
for (MessagePart part : inputParts) {
parameterList.add(part.getName());
}
return parameterList;
}
protected List<MessagePart> getParameterOrder() {
List<MessagePart> params = new ArrayList<MessagePart>();
String parameterOrder = info.portTypeOperation.getParameterOrder();
java.util.List<String> parameterList;
boolean parameterOrderPresent = false;
if ((parameterOrder != null) && !(parameterOrder.trim().equals(""))) {
parameterList = XmlUtil.parseTokenList(parameterOrder);
parameterOrderPresent = true;
} else {
parameterList = new ArrayList<String>();
}
Message inputMessage = getInputMessage();
Message outputMessage = getOutputMessage();
List<MessagePart> outputParts = null;
List<MessagePart> inputParts = inputMessage.getParts();
for (MessagePart part : inputParts) {
part.setMode(Mode.IN);
part.setReturn(false);
}
if (isRequestResponse()) {
outputParts = outputMessage.getParts();
for (MessagePart part : outputParts) {
part.setMode(Mode.OUT);
part.setReturn(false);
}
}
if (parameterOrderPresent) {
boolean validParameterOrder = true;
Iterator<String> paramOrders = parameterList.iterator();
while (paramOrders.hasNext()) {
String param = paramOrders.next();
boolean partFound = false;
for (MessagePart part : inputParts) {
if (param.equals(part.getName())) {
partFound = true;
break;
}
}
if (!partFound) {
for (MessagePart part : outputParts) {
if (param.equals(part.getName())) {
partFound = true;
break;
}
}
}
if (!partFound) {
warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_PARAMETERORDER_PARAMETER(param, info.operation.getName().getLocalPart()));
validParameterOrder = false;
}
}
List<MessagePart> inputUnlistedParts = new ArrayList<MessagePart>();
List<MessagePart> outputUnlistedParts = new ArrayList<MessagePart>();
if (validParameterOrder) {
for (String param : parameterList) {
MessagePart part = inputMessage.getPart(param);
if (part != null) {
params.add(part);
continue;
}
if (isRequestResponse()) {
MessagePart outPart = outputMessage.getPart(param);
if (outPart != null) {
params.add(outPart);
}
}
}
for (MessagePart part : inputParts) {
if (!parameterList.contains(part.getName())) {
inputUnlistedParts.add(part);
}
}
if (isRequestResponse()) {
for (MessagePart part : outputParts) {
if (!parameterList.contains(part.getName())) {
MessagePart inPart = inputMessage.getPart(part.getName());
if ((inPart != null) && inPart.getDescriptor().equals(part.getDescriptor())) {
inPart.setMode(Mode.INOUT);
} else {
outputUnlistedParts.add(part);
}
} else {
MessagePart inPart = inputMessage.getPart(part.getName());
if ((inPart != null) && inPart.getDescriptor().equals(part.getDescriptor())) {
inPart.setMode(Mode.INOUT);
} else if (!params.contains(part)) {
params.add(part);
}
}
}
if (outputUnlistedParts.size() == 1) {
MessagePart resultPart = outputUnlistedParts.get(0);
resultPart.setReturn(true);
params.add(resultPart);
outputUnlistedParts.clear();
}
}
for (MessagePart part : inputUnlistedParts) {
params.add(part);
}
for (MessagePart part : outputUnlistedParts) {
params.add(part);
}
return params;
}
warning(info.operation.getEntity(), ModelerMessages.WSDLMODELER_INVALID_PARAMETER_ORDER_INVALID_PARAMETER_ORDER(info.operation.getName().getLocalPart()));
parameterList.clear();
}
List<MessagePart> outParts = new ArrayList<MessagePart>();
for (MessagePart part : inputParts) {
params.add(part);
}
if (isRequestResponse()) {
for (MessagePart part : outputParts) {
MessagePart inPart = inputMessage.getPart(part.getName());
if (inPart != null && part.getDescriptorKind() == inPart.getDescriptorKind() &&
part.getDescriptor().equals(inPart.getDescriptor())) {
inPart.setMode(Mode.INOUT);
continue;
}
outParts.add(part);
}
for (MessagePart part : outParts) {
if (outParts.size() == 1) {
part.setReturn(true);
}
params.add(part);
}
}
return params;
}
protected String getClassName(Port port, String suffix) {
String prefix = BindingHelper.mangleNameToClassName((port.getName().getLocalPart()));
return options.defaultPackage + "." + prefix + suffix;
}
@Override
protected boolean isConflictingServiceClassName(String name) {
return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name) || conflictsWithExceptionClass(name);
}
private boolean conflictsWithSEIClass(String name) {
Set<String> seiNames = classNameCollector.getSeiClassNames();
return seiNames != null && seiNames.contains(name);
}
private boolean conflictsWithJAXBClass(String name) {
Set<String> jaxbNames = classNameCollector.getJaxbGeneratedClassNames();
return jaxbNames != null && jaxbNames.contains(name);
}
private boolean conflictsWithExceptionClass(String name) {
Set<String> exceptionNames = classNameCollector.getExceptionClassNames();
return exceptionNames != null && exceptionNames.contains(name);
}
@Override
protected boolean isConflictingExceptionClassName(String name) {
return conflictsWithSEIClass(name) || conflictsWithJAXBClass(name);
}
protected JAXBModelBuilder getJAXBModelBuilder() {
return jaxbModelBuilder;
}
protected boolean validateWSDLBindingStyle(Binding binding) {
SOAPBinding soapBinding =
(SOAPBinding) getExtensionOfType(binding, SOAPBinding.class);
if (soapBinding == null) {
soapBinding = (SOAPBinding) getExtensionOfType(binding, SOAP12Binding.class);
}
if (soapBinding == null) {
return false;
}
if (soapBinding.getStyle() == null) {
soapBinding.setStyle(SOAPStyle.DOCUMENT);
}
SOAPStyle opStyle = soapBinding.getStyle();
for (Iterator iter = binding.operations(); iter.hasNext();) {
BindingOperation bindingOperation =
(BindingOperation) iter.next();
SOAPOperation soapOperation =
(SOAPOperation) getExtensionOfType(bindingOperation,
SOAPOperation.class);
if (soapOperation != null) {
SOAPStyle currOpStyle = (soapOperation.getStyle() != null) ? soapOperation.getStyle() : soapBinding.getStyle();
if (!currOpStyle.equals(opStyle)) {
return false;
}
}
}
return true;
}
private void applyWrapperStyleCustomization(Port port, PortType portType) {
JAXWSBinding jaxwsBinding = (JAXWSBinding) getExtensionOfType(portType, JAXWSBinding.class);
Boolean wrapperStyle = (jaxwsBinding != null) ? jaxwsBinding.isEnableWrapperStyle() : null;
if (wrapperStyle != null) {
port.setWrapped(wrapperStyle);
}
}
protected static void setDocumentationIfPresent(
ModelObject obj,
Documentation documentation) {
if (documentation != null && documentation.getContent() != null) {
obj.setJavaDoc(documentation.getContent());
}
}
protected String getJavaNameForOperation(Operation operation) {
String name = operation.getJavaMethodName();
if (Names.isJavaReservedWord(name)) {
name = "_" + name;
}
return name;
}
private void reportError(Entity entity,
String formattedMsg, Exception nestedException ) {
Locator locator = (entity == null)?null:entity.getLocator();
SAXParseException e = new SAXParseException2( formattedMsg,
locator,
nestedException );
errReceiver.error(e);
}
}