001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.support.soap;
014:
015: import java.text.Collator;
016: import java.util.Collections;
017: import java.util.Comparator;
018: import java.util.Iterator;
019: import java.util.List;
020:
021: import javax.wsdl.Binding;
022: import javax.wsdl.BindingOperation;
023: import javax.wsdl.extensions.soap.SOAPBinding;
024:
025: import org.apache.log4j.Logger;
026:
027: import com.eviware.soapui.impl.wsdl.WsdlInterface;
028: import com.eviware.soapui.impl.wsdl.WsdlProject;
029: import com.eviware.soapui.impl.wsdl.support.BindingImporter;
030: import com.eviware.soapui.impl.wsdl.support.Constants;
031: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext;
032: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
033: import com.eviware.soapui.settings.WsdlSettings;
034:
035: /**
036: * BindingImporter that can import a WsdlInterface from an SOAP 1.1/HTTP binding
037: *
038: * @author Ole.Matzura
039: */
040:
041: public class Soap11HttpBindingImporter implements BindingImporter {
042: private final static Logger log = Logger
043: .getLogger(Soap11HttpBindingImporter.class);
044:
045: public boolean canImport(Binding binding) {
046: List list = binding.getExtensibilityElements();
047: SOAPBinding soapBinding = (SOAPBinding) WsdlUtils
048: .getExtensiblityElement(list, SOAPBinding.class);
049: return soapBinding == null ? false : soapBinding
050: .getTransportURI().startsWith(
051: Constants.SOAP_HTTP_BINDING_NS);
052: }
053:
054: public WsdlInterface importBinding(WsdlProject project,
055: WsdlContext wsdlContext, Binding binding) throws Exception {
056: String name = project.getSettings().getBoolean(
057: WsdlSettings.NAME_WITH_BINDING) ? binding.getQName()
058: .getLocalPart() : binding.getPortType().getQName()
059: .getLocalPart();
060:
061: WsdlInterface iface = project.addNewInterface(name);
062: iface.setBindingName(binding.getQName());
063: iface.setSoapVersion(SoapVersion.Soap11);
064:
065: String[] endpoints = WsdlUtils.getEndpointsForBinding(
066: wsdlContext.getDefinition(), binding);
067: for (int i = 0; i < endpoints.length; i++) {
068: log.info("importing endpoint " + endpoints[i]);
069: iface.addEndpoint(endpoints[i]);
070: }
071:
072: List<BindingOperation> list = binding.getBindingOperations();
073: Collections.sort(list, new BindingOperationComparator());
074:
075: for (Iterator iter = list.iterator(); iter.hasNext();) {
076: BindingOperation operation = (BindingOperation) iter.next();
077:
078: // sanity check
079: if (operation.getOperation() == null
080: || operation.getOperation().isUndefined()) {
081: log
082: .error("BindingOperation ["
083: + operation.getName()
084: + "] is missing or referring to an invalid operation");
085: } else {
086: log.info("importing operation " + operation.getName());
087: iface.addNewOperation(operation);
088: }
089: }
090:
091: return iface;
092: }
093:
094: private static final class BindingOperationComparator implements
095: Comparator<BindingOperation> {
096: public int compare(BindingOperation o1, BindingOperation o2) {
097: return Collator.getInstance().compare(
098: o1.getOperation().getName(),
099: o2.getOperation().getName());
100: }
101: }
102: }
|