Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   * 
  *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.    
  */
 
 package org.apache.tuscany.sca.binding.ws.wsdlgen;
 
 
 

Version:
$Rev: 1023951 $ $Date: 2010-10-18 20:04:02 +0100 (Mon, 18 Oct 2010) $
 
 public class WSDLDefinitionGenerator {
     private static final String SOAP_NS = "http://schemas.xmlsoap.org/wsdl/soap/";
     public static final QName SOAP_ADDRESS = new QName("address");
     private static final QName SOAP_BINDING = new QName("binding");
     private static final QName SOAP_BODY = new QName("body");
     private static final QName SOAP_FAULT = new QName("fault");
     private static final QName SOAP_OPERATION = new QName("operation");
     private static final String SOAP12_NS = "http://schemas.xmlsoap.org/wsdl/soap12/";
     public static final QName SOAP12_ADDRESS = new QName("address");
     private static final QName SOAP12_BINDING = new QName("binding");
     private static final QName SOAP12_BODY = new QName("body");
     private static final QName SOAP12_FAULT = new QName("fault");
     private static final QName SOAP12_OPERATION = new QName("operation");
 
     private static final String BINDING_SUFFIX = "Binding";
     private static final String SERVICE_SUFFIX = "Service";
     private static final String PORT_SUFFIX = "Port";
 
     private boolean requiresSOAP12;
     private QName soapAddress;
     private QName soapBinding;
     private QName soapBody;
     private QName soapFault;
     private QName soapOperation;
     private String wsBindingName;
     
     public WSDLDefinitionGenerator(WebServiceBinding wsBinding) {
     	this(BindingWSDLGenerator.requiresSOAP12(wsBinding));
     	 = wsBinding.getName();
     }
     
     public WSDLDefinitionGenerator(boolean isSOAP12) {
         super();
         this. = isSOAP12;
          =  ?  : ;
          =  ?  : ;
    }
    public Definition cloneDefinition(WSDLFactory factoryDefinition definitionthrows WSDLException {
        Element root = definition.getDocumentationElement();
        root = (Element)root.cloneNode(true);
        WSDLReader reader = factory.newWSDLReader();
        return reader.readWSDL(definition.getDocumentBaseURI(), root);
    }
    
    public Types createTypes(Definition definition) {
        Types types = definition.createTypes();
        definition.setTypes(types);
        return types;
    }
    public Binding createBinding(Definition definitionPortType portType) {
        try {
            Binding binding = definition.createBinding();
            binding.setPortType(portType);
            configureBinding(definitionbindingportType);
            ExtensibilityElement bindingExtension =
                definition.getExtensionRegistry().createExtension(Binding.class);
            if () {
                ((SOAP12Binding)bindingExtension).setStyle("document");
                ((SOAP12Binding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/http");
            } else {
                ((SOAPBinding)bindingExtension).setStyle("document");
                ((SOAPBinding)bindingExtension).setTransportURI("http://schemas.xmlsoap.org/soap/http");
            }
            binding.addExtensibilityElement(bindingExtension);
            return binding;
        } catch (WSDLException e) {
            throw new WSDLGenerationException(e);
        }
    }
    protected void configureBinding(Definition definitionBinding bindingPortType portTypethrows WSDLException {
    	if (  != null ) {
    		QName name = new QName(definition.getTargetNamespace(),  + getSOAPVersionString() + );
    		if ( definition.getBinding(name) == null ) {
    			binding.setQName(name);
    			return;
    		}
    	}
    	
        QName portTypeName = portType.getQName();
        if (portTypeName != null) {
            // Choose <porttype>Binding if available.  If this name is in use, insert
            // separating underscores until there is no clash.
            for (String suffix = ; ; suffix = "_" + suffix) { 
                QName name = new QName(definition.getTargetNamespace(), portTypeName.getLocalPart() + suffix);
                if (definition.getBinding(name) == null) {
                    binding.setQName(name);
                    break;
                }
            }
        }
    }
    @SuppressWarnings("unchecked")
    public void createBindingOperations(Definition definitionBinding bindingPortType portType) {
        try {
            for (Iterator oi = portType.getOperations().iterator(); oi.hasNext();) {
                Operation operation = (Operation)oi.next();
                BindingOperation bindingOperation =
                    createBindingOperation(definitionoperation"urn:" + operation.getName());
                binding.addBindingOperation(bindingOperation);
            }
        } catch (WSDLException e) {
            throw new WSDLGenerationException(e);
        }
    }
    @SuppressWarnings("unchecked")
    public BindingOperation createBindingOperation(Definition definitionOperation operationString action)
        throws WSDLException {
        BindingOperation bindingOperation = definition.createBindingOperation();
        bindingOperation.setOperation(operation);
        configureBindingOperation(bindingOperationoperation);
        ExtensibilityElement operationExtension =
            definition.getExtensionRegistry().createExtension(BindingOperation.class);
        if () {
            ((SOAP12Operation)operationExtension).setSoapActionURI(action);
        } else {
            ((SOAPOperation)operationExtension).setSoapActionURI(action);
        }
        bindingOperation.addExtensibilityElement(operationExtension);
        if (operation.getInput() != null) {
            BindingInput bindingInput = definition.createBindingInput();
            configureBindingInput(bindingInputoperation.getInput());
            ExtensibilityElement inputExtension =
                definition.getExtensionRegistry().createExtension(BindingInput.class);
            if () {
                ((SOAP12Body)inputExtension).setUse("literal");
            } else {
                ((SOAPBody)inputExtension).setUse("literal");
            }
            bindingInput.addExtensibilityElement(inputExtension);
            bindingOperation.setBindingInput(bindingInput);
        }
        if (operation.getOutput() != null) {
            BindingOutput bindingOutput = definition.createBindingOutput();
            configureBindingOutput(bindingOutputoperation.getOutput());
            ExtensibilityElement outputExtension =
                definition.getExtensionRegistry().createExtension(BindingOutput.class);
            if () {
                ((SOAP12Body)outputExtension).setUse("literal");
            } else {
                ((SOAPBody)outputExtension).setUse("literal");
            }
            bindingOutput.addExtensibilityElement(outputExtension);
            bindingOperation.setBindingOutput(bindingOutput);
        }
        for (Iterator fi = operation.getFaults().values().iterator(); fi.hasNext();) {
            Fault fault = (Fault)fi.next();
            BindingFault bindingFault = definition.createBindingFault();
            ExtensibilityElement faultExtension =
                definition.getExtensionRegistry().createExtension(BindingFault.class);
            configureBindingFault(bindingFaultfaultExtensionfault);
            bindingFault.addExtensibilityElement(faultExtension);
            bindingOperation.addBindingFault(bindingFault);
        }
        return bindingOperation;
    }
    protected void configureBindingOperation(BindingOperation bindingOperationOperation operation)
        throws WSDLException {
        bindingOperation.setName(operation.getName());
    }
    protected void configureBindingInput(BindingInput bindingInputInput inputthrows WSDLException {
        bindingInput.setName(input.getName());
    }
    protected void configureBindingOutput(BindingOutput bindingOutputOutput outputthrows WSDLException {
        bindingOutput.setName(output.getName());
    }
    protected void configureBindingFault(BindingFault bindingFault,
                                         ExtensibilityElement faultExtension,
                                         Fault fault)
                                     throws WSDLException {
        String faultName = fault.getName();
        bindingFault.setName(faultName);
        if () {
            ((SOAP12Fault)faultExtension).setName(faultName);
            ((SOAP12Fault)faultExtension).setUse("literal");
        } else {
            ((SOAPFault)faultExtension).setName(faultName);
            ((SOAPFault)faultExtension).setUse("literal");
        }
    }
    public Service createService(Definition definitionPortType portTypeString serviceName) {
        try {
            Service service = definition.createService();
            configureService(definitionserviceportTypeserviceName);
            definition.addService(service);
            return service;
        } catch (WSDLException e) {
            throw new WSDLGenerationException(e);
        }
    }
    public Service createService(Definition definitionBinding bindingString serviceName) {
        try {
            Service service = definition.createService();
            configureService(definitionservicebinding.getPortType(), serviceName);
            definition.addService(service);
            return service;
        } catch (WSDLException e) {
            throw new WSDLGenerationException(e);
        }
    }
    protected void configureService(Definition definitionService servicePortType portTypeString serviceNamethrows WSDLException {
    	if ( serviceName != null ) {
    		QName name = new QName(definition.getTargetNamespace(), serviceName);
    		if ( definition.getService(name) == null ) {
    			service.setQName(name);
    			return;
    		}
    	}
    	
        QName portTypeName = portType.getQName();
        if (portTypeName != null) {
            // Choose <porttype>Service if available.  If this name is in use, insert
            // separating underscores until there is no clash.
            for (String suffix = ; ; suffix = "_" + suffix) {
                QName name = new QName(definition.getTargetNamespace(), portTypeName.getLocalPart() + suffix);
                if (definition.getService(name) == null) {
                    service.setQName(name);
                    break;
                }
            }
        }
    }
    public Port createPort(Definition definitionBinding bindingService serviceString uri) {
        try {
            Port port = definition.createPort();
            port.setBinding(binding);
            configurePort(portbinding);
            if (uri != null) {
                ExtensibilityElement portExtension =
                    definition.getExtensionRegistry().createExtension(Port.class);
                if () {
                    ((SOAP12Address)portExtension).setLocationURI(uri);
                } else {
                    ((SOAPAddress)portExtension).setLocationURI(uri);
                }
                port.addExtensibilityElement(portExtension);
            }
            service.addPort(port);
            return port;
        } catch (WSDLException e) {
            throw new WSDLGenerationException(e);
        }
    }
    protected void configurePort(Port portBinding bindingthrows WSDLException {
    	if (  != null ) {
    	} else if (binding.getPortType() != null && binding.getPortType().getQName() != null) {
            port.setName(binding.getPortType().getQName().getLocalPart() + );
        }
    }
    
    private String getSOAPVersionString() {
    	if (  ) {
    		return "SOAP12";
    	} else {
    		return "SOAP11";
    	}
    }
New to GrepCode? Check out our FAQ X