[jbosstools-commits] JBoss Tools SVN: r22526 - in trunk/ws/plugins/org.jboss.tools.ws.ui: src/org/jboss/tools/ws/ui/messages and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Jun 3 17:38:40 EDT 2010


Author: bfitzpat
Date: 2010-06-03 17:38:40 -0400 (Thu, 03 Jun 2010)
New Revision: 22526

Added:
   trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/TesterWSDLUtils.java
   trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/WSDLBrowseDialog.java
Modified:
   trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
   trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties
   trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java
   trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java
Log:
JBIDE-6323 - adding support for reading web service test properties from a WSDL

Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF	2010-06-03 21:38:29 UTC (rev 22525)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF	2010-06-03 21:38:40 UTC (rev 22526)
@@ -27,7 +27,9 @@
  javax.xml.soap,
  javax.xml.rpc,
  org.eclipse.wst.internet.monitor.core,
- org.eclipse.wst.internet.monitor.ui
+ org.eclipse.wst.internet.monitor.ui,
+ javax.wsdl,
+ org.jdom
 Bundle-ActivationPolicy: lazy
 Export-Package: org.jboss.tools.ws.ui,
  org.jboss.tools.ws.ui.messages,

Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties	2010-06-03 21:38:29 UTC (rev 22525)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties	2010-06-03 21:38:40 UTC (rev 22526)
@@ -82,6 +82,7 @@
 JBossWS_DelimitedStringList_EditValue_Dialog_Message=Specify the updated value below.
 
 JAXRSWSTestView_Action_URL_Label=Action URL:
+JAXRSWSTestView_Button_Get_From_WSDL=Get from WSDL...
 JAXRSWSTestView_Configure_Monitor_Button=Configure Monitor
 JAXRSWSTestView_CopyResultsMenu=&Copy
 JAXRSWSTestView_Error_Msg_Starting_Monitor=Encountered an error starting the new TCP/IP monitor. Open the TCP/IP Monitor view and edit the monitor definition to correct the error.
@@ -104,3 +105,21 @@
 JAXRSWSTestView_Set_Sample_Data_Label=Set Sample Data
 JAXRSWSTestView_Web_Service_Type_Label=Web Service Type:
 ResultsXMLStorageInput_WS_Invocation_Results_Prefix=Web Service Invocation Results\: 
+WSDLBrowseDialog_Dialog_Title=Select WSDL
+WSDLBrowseDialog_FS_Browse=File system...
+WSDLBrowseDialog_Group_Title=Select the service operation:
+WSDLBrowseDialog_Message=Select the source WSDL in the workspace or file system, or provide a URL from which to download the WSDL.
+WSDLBrowseDialog_Operation_Field=Operation:
+WSDLBrowseDialog_Port_Field=Port:
+WSDLBrowseDialog_Service_Field=Service:
+WSDLBrowseDialog_Status_Invalid_URL=Invalid URL
+WSDLBrowseDialog_Status_WSDL_Unavailable=WSDL unavailable
+WSDLBrowseDialog_Title=Specify the Source WSDL for the Web Service
+WSDLBrowseDialog_URL_Browse=URL...
+WSDLBrowseDialog_WS_Browse=Workspace...
+WSDLBrowseDialog_WS_Browse_Msg=Select a WSDL file in the workspace.
+WSDLBrowseDialog_WS_Browse_Select_WSDL_Msg=Please select a WSDL file.
+WSDLBrowseDialog_WS_Browse_Select_WSDL_Title=Select a WSDL from a Project
+WSDLBrowseDialog_WSDL_URI_Field=WSDL URI:
+WSDLBrowseDialog_WSDL_URL_Dialog_Title=WSDL URL
+WSDLBrowseDialog_WSDL_URL_Prompt=Type the URL for the WSDL:

Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java	2010-06-03 21:38:29 UTC (rev 22525)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java	2010-06-03 21:38:40 UTC (rev 22526)
@@ -105,6 +105,7 @@
 	public static String JBossWS_DelimitedStringList_EditValue_Dialog_Title;
 	public static String JBossWS_DelimitedStringList_EditValue_Dialog_Message;
 	public static String JAXRSWSTestView_Action_URL_Label;
+	public static String JAXRSWSTestView_Button_Get_From_WSDL;
 	public static String JAXRSWSTestView_Configure_Monitor_Button;
 	public static String JAXRSWSTestView_CopyResultsMenu;
 	public static String JAXRSWSTestView_Error_Msg_Starting_Monitor;
@@ -128,6 +129,25 @@
 	public static String JAXRSWSTestView_Web_Service_Type_Label;
 	public static String ResultsXMLStorageInput_WS_Invocation_Results_Prefix;
 
+	public static String WSDLBrowseDialog_Dialog_Title;
+	public static String WSDLBrowseDialog_FS_Browse;
+	public static String WSDLBrowseDialog_Group_Title;
+	public static String WSDLBrowseDialog_Message;
+	public static String WSDLBrowseDialog_Operation_Field;
+	public static String WSDLBrowseDialog_Port_Field;
+	public static String WSDLBrowseDialog_Service_Field;
+	public static String WSDLBrowseDialog_Status_Invalid_URL;
+	public static String WSDLBrowseDialog_Status_WSDL_Unavailable;
+	public static String WSDLBrowseDialog_Title;
+	public static String WSDLBrowseDialog_URL_Browse;
+	public static String WSDLBrowseDialog_WS_Browse;
+	public static String WSDLBrowseDialog_WS_Browse_Msg;
+	public static String WSDLBrowseDialog_WS_Browse_Select_WSDL_Msg;
+	public static String WSDLBrowseDialog_WS_Browse_Select_WSDL_Title;
+	public static String WSDLBrowseDialog_WSDL_URI_Field;
+	public static String WSDLBrowseDialog_WSDL_URL_Dialog_Title;
+	public static String WSDLBrowseDialog_WSDL_URL_Prompt;
+
 	static {
 		NLS.initializeMessages(BUNDLE_NAME, JBossWSUIMessages.class);
 	}

Added: trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/TesterWSDLUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/TesterWSDLUtils.java	                        (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/TesterWSDLUtils.java	2010-06-03 21:38:40 UTC (rev 22526)
@@ -0,0 +1,564 @@
+/******************************************************************************* 
+ * Copyright (c) 2010 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.utils;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.Import;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Part;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.Types;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaImport;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.extensions.soap12.SOAP12Address;
+import javax.wsdl.extensions.soap12.SOAP12Operation;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
+//import org.jdom.Attribute;
+import org.jdom.input.DOMBuilder;
+
+import com.ibm.wsdl.Constants;
+
+/**
+ * @author bfitzpat
+ *
+ */
+public class TesterWSDLUtils {
+	private static final String IMPORT_TAG = "import"; //$NON-NLS-1$
+	private static final String VALUE_ATTR = "value"; //$NON-NLS-1$
+	private static final String SEQUENCE_NAME = "sequence"; //$NON-NLS-1$
+	private static final String COMPLEX_TYPE_NAME = "complexType"; //$NON-NLS-1$
+	private static final String ENUMERATION_NAME = "enumeration"; //$NON-NLS-1$
+	private static final String RESTRICTION_NAME = "restriction"; //$NON-NLS-1$
+	private static final String SIMPLE_TYPE_NAME = "simpleType"; //$NON-NLS-1$
+	private static final String INT_TYPE_NAME = "int"; //$NON-NLS-1$
+	private static final String STRING_TYPE_NAME = "string"; //$NON-NLS-1$
+	private static final String MIN_OCCURS_ATTR = "minOccurs"; //$NON-NLS-1$
+	private static final String TYPE_ATTR = "type"; //$NON-NLS-1$
+	private static final String NAME_ATTR = "name"; //$NON-NLS-1$
+	
+	private final static String DEF_FACTORY_PROPERTY_NAME =
+		"javax.wsdl.factory.DefinitionFactory"; //$NON-NLS-1$
+	private final static String PRIVATE_DEF_FACTORY_CLASS =
+		"org.apache.wsif.wsdl.WSIFWSDLFactoryImpl"; //$NON-NLS-1$
+
+	public static Definition readWSDLURL(URL contextURL, String wsdlLoc) throws WSDLException {
+		Properties props = System.getProperties();
+		String oldPropValue = props.getProperty(DEF_FACTORY_PROPERTY_NAME);
+
+		props.setProperty(DEF_FACTORY_PROPERTY_NAME, PRIVATE_DEF_FACTORY_CLASS);
+
+		WSDLFactory factory = WSDLFactory.newInstance();
+		WSDLReader wsdlReader = factory.newWSDLReader();
+		wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
+		wsdlReader.setFeature("javax.wsdl.importDocuments", true); //$NON-NLS-1$
+		String context = null;
+		if (contextURL != null)
+			context = contextURL.toString();
+		Definition def = wsdlReader.readWSDL(context, wsdlLoc);
+
+		if (oldPropValue != null) {
+			props.setProperty(DEF_FACTORY_PROPERTY_NAME, oldPropValue);
+		} else {
+			props.remove(DEF_FACTORY_PROPERTY_NAME);
+		}
+		return def;
+	}
+
+	public static Definition readWSDLURL(URL contextURL) throws WSDLException {
+		Properties props = System.getProperties();
+		String oldPropValue = props.getProperty(DEF_FACTORY_PROPERTY_NAME);
+
+		props.setProperty(DEF_FACTORY_PROPERTY_NAME, PRIVATE_DEF_FACTORY_CLASS);
+
+		WSDLFactory factory = WSDLFactory.newInstance();
+		WSDLReader wsdlReader = factory.newWSDLReader();
+		wsdlReader.setFeature(Constants.FEATURE_VERBOSE, false);
+		wsdlReader.setFeature("javax.wsdl.importDocuments", true); //$NON-NLS-1$
+		String context = null;
+		if (contextURL != null)
+			context = contextURL.toString();
+		Definition def = wsdlReader.readWSDL(context);
+
+		if (oldPropValue != null) {
+			props.setProperty(DEF_FACTORY_PROPERTY_NAME, oldPropValue);
+		} else {
+			props.remove(DEF_FACTORY_PROPERTY_NAME);
+		}
+		return def;
+	}
+
+	public static String getSampleSOAPInputMessage ( Definition wsdlDefinition, String serviceName, String portName, String bindingName, String opName ) {
+		Map<?, ?> services = wsdlDefinition.getServices();
+		Set<?> serviceKeys = services.keySet();
+		for( Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
+			QName serviceKey = (QName) it.next();
+			if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
+				Service service = (Service) services.get( serviceKey );
+				Map<?, ?> ports = service.getPorts();
+				Set<?> portKeys = ports.keySet();
+				for( Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
+					String portKey = (String) it2.next();
+					if (portName != null && portKey.contentEquals(portName)) {
+						Port port = (Port) ports.get( portKey );
+						Binding wsdlBinding = port.getBinding();
+						PortType portType = wsdlBinding.getPortType();
+						List<?> operations = portType.getOperations();
+						for (Iterator<?> it3 = operations.iterator(); it3.hasNext();){
+							Operation operation = (Operation) it3.next();
+							if (opName != null && operation.getName().contentEquals(opName)) {
+								Message inputMsg = operation.getInput().getMessage();
+								Collection<?> parts = inputMsg.getParts().values();
+								for( Iterator<?> it4 = parts.iterator(); it4.hasNext(); ) {
+									Part part = (Part) it4.next();
+									String schemaName = null;
+									if (part.getElementName() != null) {
+										schemaName = part.getElementName().getLocalPart();
+									} else {
+										schemaName = part.getName();
+									}
+									String out = createMessageForSchemaElement(wsdlDefinition, schemaName);
+									return out;
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
+	public static String getEndpointURL ( Definition wsdlDefinition, String serviceName, String portName, String bindingName, String opName ) {
+		Map<?, ?> services = wsdlDefinition.getServices();
+		Set<?> serviceKeys = services.keySet();
+		for( Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
+			QName serviceKey = (QName) it.next();
+			if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
+				Service service = (Service) services.get( serviceKey );
+				Map<?, ?> ports = service.getPorts();
+				Set<?> portKeys = ports.keySet();
+				for( Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
+					String portKey = (String) it2.next();
+					if (portName != null && portKey.contentEquals(portName)) {
+						Port port = (Port) ports.get( portKey );
+						List<?> elements = port.getExtensibilityElements();
+						for (Iterator<?> it3 = elements.iterator(); it3.hasNext();){
+							Object element = it3.next();
+							if (element instanceof SOAPAddress) {
+								SOAPAddress address = (SOAPAddress) element;
+								return address.getLocationURI();
+							} else if (element instanceof SOAP12Address) {
+								SOAP12Address address = (SOAP12Address) element;
+								return address.getLocationURI();
+							}
+						}
+					}
+				}
+			}
+		}
+		return null;
+	}
+
+	public static String getActionURL ( Definition wsdlDefinition, String serviceName, String portName, String bindingName, String opName ) {
+		Map<?, ?> services = wsdlDefinition.getServices();
+		Set<?> serviceKeys = services.keySet();
+		for( Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
+			QName serviceKey = (QName) it.next();
+			if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
+				Service service = (Service) services.get( serviceKey );
+				Map<?, ?> ports = service.getPorts();
+				Set<?> portKeys = ports.keySet();
+				for( Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
+					String portKey = (String) it2.next();
+					if (portName != null && portKey.contentEquals(portName)) {
+						Port port = (Port) ports.get( portKey );
+						Binding wsdlBinding = port.getBinding();
+						List<?> operations = wsdlBinding.getBindingOperations();
+						for (Iterator<?> it3 = operations.iterator(); it3.hasNext();){
+							BindingOperation operation = (BindingOperation) it3.next();
+							if (opName != null && operation.getName().contentEquals(opName)) {
+								List<?> attributesList = operation.getExtensibilityElements();
+								for (Iterator<?> it4 = attributesList.iterator(); it4.hasNext();){
+									Object test = it4.next();
+									if (test instanceof SOAPOperation) {
+										SOAPOperation soapOp = (SOAPOperation) test;
+										return soapOp.getSoapActionURI();
+									} else if (test instanceof SOAP12Operation) {
+										SOAP12Operation soapOp = (SOAP12Operation) test;
+										return soapOp.getSoapActionURI();
+									}
+								}
+							}
+						}
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
+	private static org.jdom.Element getNamedSchemaElement (Definition wsdlDefinition, Types types, String elementName) {
+		if (types != null &&types.getExtensibilityElements().size() > 0) {
+			Schema schema = (Schema) types.getExtensibilityElements().get(0);
+			DOMBuilder domBuilder = new DOMBuilder();
+			org.jdom.Element jdomSchemaElement = domBuilder.build(schema.getElement());
+			if (elementName.indexOf(":") > 0 ) { //$NON-NLS-1$
+				elementName = elementName.substring(elementName.indexOf(":") + 1, elementName.length()); //$NON-NLS-1$
+			}
+			List<?> list = jdomSchemaElement.getChildren();
+			if (list.size() > 0) {
+				org.jdom.Element checkForImport = (org.jdom.Element) list.get(0);
+				if (checkForImport.getName().equals(IMPORT_TAG)) {
+					Map<?, ?> imports = schema.getImports();
+					Iterator<?> importIter = imports.values().iterator();
+					while (importIter.hasNext()) {
+						Object obj = importIter.next();
+						Vector<?> schemaImportVector = (Vector<?>) obj;
+						Iterator<?> vectorIter = schemaImportVector.iterator();
+						while (vectorIter.hasNext()) {
+							SchemaImport schemaImport = (SchemaImport) vectorIter.next();
+							org.jdom.Element jdomSchemaImportElement = domBuilder.build(schemaImport.getReferencedSchema().getElement());
+							List<?> innerList = jdomSchemaImportElement.getChildren();
+							for (int i = 0; i < innerList.size(); i++){
+								org.jdom.Element temp = (org.jdom.Element) innerList.get(i);
+								String rootName = null;
+								if (temp.getAttribute(NAME_ATTR) != null) 
+									rootName = temp.getAttribute(NAME_ATTR).getValue();
+								String tempName = temp.getNamespacePrefix() + ":" + rootName; //$NON-NLS-1$
+								if (rootName.equalsIgnoreCase(elementName)) {
+									return temp;
+								} else if (tempName.equalsIgnoreCase(elementName) ) {
+									return temp;
+								}
+							}
+						}
+					}
+				} else {
+					for (int i = 0; i < list.size(); i++){
+						org.jdom.Element temp = (org.jdom.Element) list.get(i);
+						String rootName = null;
+						if (temp.getAttribute(NAME_ATTR) != null) 
+							rootName = temp.getAttribute(NAME_ATTR).getValue();
+						String tempName = temp.getNamespacePrefix() + ":" + rootName; //$NON-NLS-1$
+						if (rootName.equalsIgnoreCase(elementName)) {
+							return temp;
+						} else if (tempName.equalsIgnoreCase(elementName) ) {
+							return temp;
+						}
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
+	private static org.jdom.Element getNamedSchemaElement ( Definition wsdlDefinition, String messageName ) {
+		Types types = wsdlDefinition.getTypes();
+		
+		if (types == null) {
+			Map<?, ?> imports = wsdlDefinition.getImports();
+			Set<?> importKeys = imports.keySet();
+			for( Iterator<?> it2 = importKeys.iterator(); it2.hasNext(); ) {
+				String importKey = (String) it2.next();
+				Vector<?> importVector = (Vector<?>) imports.get(importKey); 
+				Iterator<?> iter = importVector.iterator();
+				while (iter.hasNext()) {
+					Import importInstance = (Import) iter.next();
+					if (importInstance.getDefinition().getTypes() != null) {
+						types = importInstance.getDefinition().getTypes();
+						org.jdom.Element attempt = getNamedSchemaElement(wsdlDefinition, types, messageName);
+						if (attempt != null)
+							return attempt;
+					} else if (importInstance.getDefinition().getImports() != null) {
+						org.jdom.Element attempt = getNamedSchemaElement(importInstance.getDefinition(), messageName);
+						if (attempt != null)
+							return attempt;
+					}
+				}
+			}
+		} else {
+			org.jdom.Element attempt = getNamedSchemaElement(wsdlDefinition, types, messageName);
+			if (attempt != null)
+				return attempt;
+		}
+		return null;
+	}
+	
+	private static String createMessageForSchemaElementFromTypes ( Definition wsdlDefinition, Types types, String messageName ) {
+		if (types != null &&types.getExtensibilityElements().size() > 0) {
+			Schema schema = (Schema) types.getExtensibilityElements().get(0);
+			DOMBuilder domBuilder = new DOMBuilder();
+			org.jdom.Element jdomSchemaElement = domBuilder.build(schema.getElement());
+
+			List<?> list = jdomSchemaElement.getChildren();
+			if (list.size() > 0) {
+				org.jdom.Element checkForImport = (org.jdom.Element) list.get(0);
+				if (checkForImport.getName().equals(IMPORT_TAG)) {
+					Map<?, ?> imports = schema.getImports();
+					Iterator<?> importIter = imports.values().iterator();
+					while (importIter.hasNext()) {
+						Object obj = importIter.next();
+						Vector<?> schemaImportVector = (Vector<?>) obj;
+						Iterator<?> vectorIter = schemaImportVector.iterator();
+						while (vectorIter.hasNext()) {
+							SchemaImport schemaImport = (SchemaImport) vectorIter.next();
+							org.jdom.Element jdomSchemaImportElement = domBuilder.build(schemaImport.getReferencedSchema().getElement());
+							List<?> innerList = jdomSchemaImportElement.getChildren();
+							
+							for (int i = 0; i < innerList.size(); i++){
+								org.jdom.Element temp = (org.jdom.Element) innerList.get(i);
+								String rootName = null;
+								if (temp.getAttribute(NAME_ATTR) != null) 
+									rootName = temp.getAttribute(NAME_ATTR).getValue();
+								
+								if (rootName.equalsIgnoreCase(messageName)) {
+									StringBuffer buf = new StringBuffer();
+									buf.append('<' + rootName);
+									buf.append(" xmlns = \"" + wsdlDefinition.getTargetNamespace() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+									buf.append(">\n"); //$NON-NLS-1$
+									if (!temp.getChildren().isEmpty()){
+										org.jdom.Element temp2 = (org.jdom.Element)temp.getChildren().get(0);
+										if (temp2.getName().contains(COMPLEX_TYPE_NAME)) {
+											String elementStr = processComplexType(wsdlDefinition, temp2);
+											buf.append(elementStr);
+										} else if (temp2.getName().contains(RESTRICTION_NAME)){
+											String elementStr = processType(wsdlDefinition, temp2, RESTRICTION_NAME, false);
+											buf.append(elementStr);
+										} else {
+											String elementStr = processChild(wsdlDefinition, temp2);
+											buf.append(elementStr);
+										}
+									}
+									buf.append("</" + rootName + ">\n");//$NON-NLS-1$//$NON-NLS-2$
+									return buf.toString();
+								}
+							}
+						}
+					}
+				} else {
+					for (int i = 0; i < list.size(); i++){
+						org.jdom.Element temp = (org.jdom.Element) list.get(i);
+						String rootName = null;
+						if (temp.getAttribute(NAME_ATTR) != null) 
+							rootName = temp.getAttribute(NAME_ATTR).getValue();
+						
+						if (rootName.equalsIgnoreCase(messageName)) {
+							StringBuffer buf = new StringBuffer();
+							buf.append('<' + rootName);
+							buf.append(" xmlns = \"" + wsdlDefinition.getTargetNamespace() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+							buf.append(">\n"); //$NON-NLS-1$
+							if (!temp.getChildren().isEmpty()){
+								org.jdom.Element temp2 = (org.jdom.Element)temp.getChildren().get(0);
+								if (temp2.getName().contains(COMPLEX_TYPE_NAME)) {
+									String elementStr = processComplexType(wsdlDefinition, temp2);
+									buf.append(elementStr);
+								} else {
+									String elementStr = processChild(wsdlDefinition, temp2);
+									buf.append(elementStr);
+								}
+							}
+							buf.append("</" + rootName + ">\n");//$NON-NLS-1$//$NON-NLS-2$
+							return buf.toString();
+						}
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
+	private static String processComplexType (Definition wsdlDefinition, org.jdom.Element childEl ) {
+        StringBuffer buf = new StringBuffer();
+		if (!childEl.getChildren().isEmpty()) {
+			org.jdom.Element temp3 = (org.jdom.Element)childEl.getChildren().get(0);
+			if (temp3.getName().contains(SEQUENCE_NAME)) {
+				for (int j = 0; j < temp3.getChildren().size(); j++) {
+					org.jdom.Element tempEl = (org.jdom.Element) temp3.getChildren().get(j); 
+					String elementStr = processChild(wsdlDefinition, tempEl);
+					buf.append(elementStr);
+				}
+			} else {
+				String elementStr = processChild(wsdlDefinition, temp3);
+				buf.append(elementStr);
+			}
+		}
+		return buf.toString();
+	}
+		
+	private static String processType (Definition wsdlDefinition, org.jdom.Element childEl, String type, boolean isOptional) {
+        StringBuffer buf = new StringBuffer();
+		if (type.contains(STRING_TYPE_NAME)) {
+			buf.append("?"); //$NON-NLS-1$
+		} else if (type.contains(INT_TYPE_NAME)) {
+			buf.append("?"); //$NON-NLS-1$
+		} else if (type.contains(SIMPLE_TYPE_NAME)) {
+			buf.append("?"); //$NON-NLS-1$
+//			for (int j = 0; j < childEl.getChildren().size(); j++) {
+//				org.jdom.Element tempEl = (org.jdom.Element) childEl.getChildren().get(j); 
+//				String elementStr = processChild(wsdlDefinition, tempEl);
+//				buf.append(elementStr);
+//			}
+		} else if (type.contains(RESTRICTION_NAME)) {
+			for (int j = 0; j < childEl.getChildren().size(); j++) {
+				org.jdom.Element tempEl = (org.jdom.Element) childEl.getChildren().get(j); 
+				String innerType = tempEl.getName();
+				String elementStr = processType(wsdlDefinition, tempEl, innerType, isOptional );
+				buf.append(elementStr);
+			}
+		} else if (type.contains(ENUMERATION_NAME)) {
+			String enumerationType = null;
+			if (childEl.getAttribute(VALUE_ATTR) != null) {
+				enumerationType = childEl.getAttribute(VALUE_ATTR).getValue();
+				buf.append(enumerationType + " | "); //$NON-NLS-1$
+			}
+		} else {
+			org.jdom.Element typeEl = getNamedSchemaElement(wsdlDefinition, type);
+			if (typeEl != null) {
+				if (typeEl.getName().contains(COMPLEX_TYPE_NAME) || typeEl.getName().contains(SEQUENCE_NAME)) {
+					String elementStr = processComplexType(wsdlDefinition, typeEl);
+					buf.append(elementStr);
+				} else {
+					String elementStr = processChild(wsdlDefinition, typeEl);
+					buf.append(elementStr);
+				}
+			} else {
+				buf.append("?"); //$NON-NLS-1$
+			}
+		}
+		return buf.toString();
+	}
+	
+	private static String processChild ( Definition wsdlDefinition, org.jdom.Element childEl ) {
+        StringBuffer buf = new StringBuffer();
+		String innerChildName = null;
+		if (childEl.getAttribute(NAME_ATTR) != null) {
+			innerChildName = childEl.getAttribute(NAME_ATTR).getValue();
+		}
+		String innerChildType = null;
+		if (childEl.getAttribute(TYPE_ATTR) != null) {
+			innerChildType = childEl.getAttribute(TYPE_ATTR).getValue();
+		}
+		String innerMinOccurs = null;
+		Integer innerMinOccursNum = null;
+		if (childEl.getAttribute(MIN_OCCURS_ATTR) != null) {
+			innerMinOccurs = childEl.getAttribute(MIN_OCCURS_ATTR).getValue();
+			innerMinOccursNum = Integer.decode(innerMinOccurs);
+		}
+		if (innerChildName != null && !childEl.getName().contains(SIMPLE_TYPE_NAME)){
+			buf.append('<' + innerChildName);
+			buf.append(">"); //$NON-NLS-1$
+		}
+		
+		if (childEl.getChildren().size() > 0) {
+			if (childEl.getName().contains(SIMPLE_TYPE_NAME)) {
+				String elementStr = processType(wsdlDefinition, childEl, SIMPLE_TYPE_NAME, (innerMinOccursNum == null || innerMinOccursNum.intValue() == 0));
+				buf.append(elementStr);
+			} else {
+				for (int j = 0; j < childEl.getChildren().size(); j++) {
+					org.jdom.Element tempEl = (org.jdom.Element) childEl.getChildren().get(j); 
+					if (tempEl.getName().contains(COMPLEX_TYPE_NAME)) {
+						String elementStr = processComplexType(wsdlDefinition, tempEl);
+						buf.append(elementStr);
+					} else {
+						String elementStr = processChild(wsdlDefinition, tempEl);
+						buf.append(elementStr);
+					}
+				}
+			}
+		} else if ((innerMinOccursNum == null || innerMinOccursNum.intValue() == 0) && (innerChildType != null)) {
+			String elementStr = processType(wsdlDefinition, childEl, innerChildType, true);
+			buf.append(elementStr);
+		} else if (innerChildType != null){
+			String elementStr = processType(wsdlDefinition, childEl, innerChildType, false);
+			buf.append(elementStr);
+		}
+		if (innerChildName != null && !childEl.getName().contains(SIMPLE_TYPE_NAME))
+			buf.append("</" + innerChildName + ">\n");  //$NON-NLS-1$//$NON-NLS-2$
+		return buf.toString();
+	}
+
+	public static String createMessageForSchemaElement ( Definition wsdlDefinition, String messageName ) {
+		Types types = wsdlDefinition.getTypes();
+		if (types == null) {
+			Map<?, ?> imports = wsdlDefinition.getImports();
+			Set<?> importKeys = imports.keySet();
+			for( Iterator<?> it2 = importKeys.iterator(); it2.hasNext(); ) {
+				String importKey = (String) it2.next();
+				Vector<?> importVector = (Vector<?>) imports.get(importKey); 
+				Iterator<?> iter = importVector.iterator();
+				while (iter.hasNext()) {
+					Import importInstance = (Import) iter.next();
+					if (importInstance.getDefinition().getTypes() != null) {
+						types = importInstance.getDefinition().getTypes();
+						String attempt = createMessageForSchemaElementFromTypes(wsdlDefinition, types, messageName);
+						if (attempt != null)
+							return attempt;
+					} else if (importInstance.getDefinition().getImports() != null) {
+						String attempt = createMessageForSchemaElement(importInstance.getDefinition(), messageName);
+						if (attempt != null)
+							return attempt;
+					}
+				}
+			}
+		} else {
+			String attempt = createMessageForSchemaElementFromTypes(wsdlDefinition, types, messageName);
+			if (attempt != null)
+				return attempt;
+		}
+		return null;
+	}
+	
+	public static String getFileContents (URL inURL){
+		try {
+			BufferedReader in = new BufferedReader(
+					new InputStreamReader(
+							inURL.openStream()));
+	
+			String inputLine;
+			StringBuffer buffer = new StringBuffer();
+		
+			while ((inputLine = in.readLine()) != null) {
+				buffer.append(inputLine + '\n');
+			}
+			in.close();
+			return buffer.toString();
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+}


Property changes on: trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/TesterWSDLUtils.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java	2010-06-03 21:38:29 UTC (rev 22525)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java	2010-06-03 21:38:40 UTC (rev 22526)
@@ -17,6 +17,7 @@
 import java.util.Iterator;
 import java.util.Map.Entry;
 
+import javax.wsdl.Definition;
 import javax.xml.soap.SOAPEnvelope;
 import javax.xml.soap.SOAPException;
 
@@ -66,6 +67,7 @@
 import org.jboss.tools.ws.ui.utils.JAXWSTester;
 import org.jboss.tools.ws.ui.utils.ResultsXMLStorage;
 import org.jboss.tools.ws.ui.utils.ResultsXMLStorageInput;
+import org.jboss.tools.ws.ui.utils.TesterWSDLUtils;
 import org.jboss.tools.ws.ui.utils.WSTestUtils;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -97,6 +99,7 @@
 
 	/* UI controls */
 	private Button testButton = null;
+	private Button wsdlButton = null;
 	private Text actionText;
 	private Text resultsText;
 	private Combo urlCombo;
@@ -124,7 +127,7 @@
 	private Menu resultsTextMenu;
 	private MenuItem copyMenuAction;
 	
-	private boolean showSampleButton = true;
+	private boolean showSampleButton = false;
 
 	/**
 	 * The constructor.
@@ -268,6 +271,44 @@
 			}
 		});
 
+		wsdlButton = new Button (buttonBar, SWT.PUSH);
+		wsdlButton.setText(JBossWSUIMessages.JAXRSWSTestView_Button_Get_From_WSDL);
+
+		wsdlButton.addSelectionListener(new SelectionListener() {
+			public void widgetSelected(SelectionEvent e) {
+				WSDLBrowseDialog wbDialog =  new WSDLBrowseDialog(getSite().getShell());
+				int rtnCode = wbDialog.open();
+				if (rtnCode == Window.OK){
+					Definition wsdlDef = wbDialog.getWSDLDefinition();
+					String output = TesterWSDLUtils.getSampleSOAPInputMessage(wsdlDef, 
+							wbDialog.getServiceTextValue(), 
+							wbDialog.getPortTextValue(), 
+							wbDialog.getBindingValue(), 
+							wbDialog.getOperationTextValue());
+					String endpointURL = TesterWSDLUtils.getEndpointURL(wsdlDef, 
+							wbDialog.getServiceTextValue(), 
+							wbDialog.getPortTextValue(), 
+							wbDialog.getBindingValue(), 
+							wbDialog.getOperationTextValue());
+					String actionURL = TesterWSDLUtils.getActionURL(wsdlDef, 
+							wbDialog.getServiceTextValue(), 
+							wbDialog.getPortTextValue(), 
+							wbDialog.getBindingValue(), 
+							wbDialog.getOperationTextValue());
+					String soapIn = generateSampleSOAP(output);
+					bodyText.setText(soapIn);
+					urlCombo.setText(endpointURL);
+					actionText.setText(actionURL);
+					setControlsForWSType(wsTypeCombo.getText());
+					setControlsForMethodType(methodCombo.getText());
+					setControlsForSelectedURL();
+				}
+			}
+			public void widgetDefaultSelected(SelectionEvent e) {
+				widgetSelected(e);
+			}
+		});
+
 		addTCPIPMonitorButton = new Button(buttonBar, SWT.PUSH);
 		addTCPIPMonitorButton.setText(JBossWSUIMessages.JAXRSWSTestView_Configure_Monitor_Button);
 
@@ -383,7 +424,7 @@
 							openXMLEditor(string);
 						}
 					} catch (SOAPException e) {
-						e.printStackTrace();
+						JBossWSUIPlugin.log(e);
 					}
 				}
 			}
@@ -422,6 +463,21 @@
 		setMenusForCurrentState();
 	}
 	
+	private String generateSampleSOAP ( String innerText ) {
+		String soapIn = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n" + //$NON-NLS-1$
+			"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + //$NON-NLS-1$
+			"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +  //$NON-NLS-1$
+			"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +  //$NON-NLS-1$
+			">\n" + //$NON-NLS-1$
+			"<soap:Body>\n";//$NON-NLS-1$
+		if (innerText != null)
+			soapIn = soapIn + innerText;
+		soapIn = soapIn +
+			"</soap:Body>\n" + //$NON-NLS-1$
+			"</soap:Envelope>";	 //$NON-NLS-1$
+		return soapIn;
+	}
+	
 	private void setMenusForCurrentState() {
 		if (resultsText!= null && !resultsText.isDisposed()){
 			boolean enabled = resultsText.getText().trim().length() > 0; 
@@ -448,7 +504,7 @@
 					page.openEditor(input, DEFAULT_TEXT_EDITOR_ID);
 				}
 			} catch (PartInitException e) {
-				e.printStackTrace();
+				JBossWSUIPlugin.log(e);
 			}			
 		}
 	}
@@ -471,7 +527,7 @@
 			PlatformUI.getWorkbench().getActiveWorkbenchWindow().
 			getActivePage().showView(TCPIP_VIEW_ID);
 		} catch (PartInitException e) {
-			e.printStackTrace();
+			JBossWSUIPlugin.log(e);
 		}
 	}
 
@@ -588,6 +644,7 @@
 			if (bodyText.getText().trim().length() == 0) {
 				bodyText.setText(emptySOAP);
 			}
+			wsdlButton.setEnabled(true);
 		}
 		else if (wsType.equalsIgnoreCase(JAX_RS)) {
 			actionText.setEnabled(false);
@@ -598,6 +655,7 @@
 			parmsTab.getControl().setEnabled(true);
 			headerTab.getControl().setEnabled(true);
 			methodCombo.setText(GET);
+			wsdlButton.setEnabled(false);
 		}
 		setMenusForCurrentState();
 	}
@@ -679,7 +737,6 @@
 		};
 		// true to indicate that this job was initiated by a UI end user
 		aJob.setUser(true);		
-		aJob.schedule();
 		aJob.addJobChangeListener(new IJobChangeListener() {
 
 			public void sleeping(IJobChangeEvent event) {};
@@ -707,6 +764,7 @@
 			public void awake(IJobChangeEvent event) {};
 			public void aboutToRun(IJobChangeEvent event) {};
 		});
+		aJob.schedule();
 
 		setMenusForCurrentState();
 	}
@@ -756,7 +814,7 @@
 					JBossWSUIPlugin.PLUGIN_ID, 
 					JBossWSUIMessages.JAXRSWSTestView_Exception_Status + e.getLocalizedMessage());
 			status.setResultsText(e.toString());
-			e.printStackTrace();
+			JBossWSUIPlugin.log(e);
 			return status;
 		}
 	}
@@ -840,7 +898,6 @@
 				}
 			}
 
-			System.out.println(listText);
 			status.setHeadersList(listText);
 			monitor.worked(10);
 			return status;
@@ -873,16 +930,9 @@
 				}
 			}
 
-			System.out.println(listText);
 			status.setHeadersList(listText);
 			monitor.worked(10);
 			return status;
-			//			WSTestStatus status = new WSTestStatus(IStatus.ERROR, 
-			//					JBossWSUIPlugin.PLUGIN_ID, 
-			//					JBossWSUIMessages.JAXRSWSTestView_Exception_Status + e.getLocalizedMessage());
-			//			status.setResultsText(e.toString());
-			//			e.printStackTrace();
-			//			return status;
 		}
 	}
 

Added: trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/WSDLBrowseDialog.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/WSDLBrowseDialog.java	                        (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/WSDLBrowseDialog.java	2010-06-03 21:38:40 UTC (rev 22526)
@@ -0,0 +1,503 @@
+/******************************************************************************* 
+ * Copyright (c) 2010 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.views;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap12.SOAP12Binding;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.jboss.tools.ws.core.utils.StatusUtils;
+import org.jboss.tools.ws.ui.JBossWSUIPlugin;
+import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
+import org.jboss.tools.ws.ui.utils.TesterWSDLUtils;
+
+/**
+ * @author bfitzpat
+ *
+ */
+public class WSDLBrowseDialog extends TitleAreaDialog {
+
+	private Label locationLabel = null;
+	private Combo locationCombo = null;
+	private Button workspaceBrowseButton = null;
+	private Button fsBrowseButton = null;
+	private Button urlBrowseButton = null;
+	
+	private static String wsdlTextValue = null;
+	private static String[] oldValues = null;
+	private String serviceTextValue = null;
+	private String portTextValue = null;
+	private String operationTextValue = null;
+	private String bindingValue = null;
+	
+	private Definition wsdlDefinition = null;
+	private Label serviceLabel;
+	private Combo serviceCombo;
+	private Combo portCombo;
+	private Label operationLabel;
+	private List opList;
+	private Group group;
+	private Label portLabel;
+
+	public WSDLBrowseDialog(Shell parentShell) {
+		super(parentShell);
+		setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE );
+	}
+	
+	public String getWSDLText(){
+		return WSDLBrowseDialog.wsdlTextValue;
+	}
+	
+	public String getBindingValue() {
+		return bindingValue;
+	}
+
+	public String getServiceTextValue() {
+		return serviceTextValue;
+	}
+
+	public String getPortTextValue() {
+		return portTextValue;
+	}
+
+	public String getOperationTextValue() {
+		return operationTextValue;
+	}
+
+	public Definition getWSDLDefinition(){
+		return this.wsdlDefinition;
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	protected void okPressed() {
+		WSDLBrowseDialog.wsdlTextValue = locationCombo.getText();
+		
+		ArrayList<String> uriList = new ArrayList<String>();
+		if (WSDLBrowseDialog.oldValues != null) {
+			@SuppressWarnings("rawtypes")
+			java.util.List tempList = (java.util.List) Arrays.asList(WSDLBrowseDialog.oldValues);
+			uriList.addAll(tempList);
+		}
+		if (!uriList.contains(locationCombo.getText())) {
+			uriList.add(locationCombo.getText());
+		}
+		WSDLBrowseDialog.oldValues = uriList.toArray(new String[uriList.size()]);
+		
+		super.okPressed();
+	}
+
+	@Override
+	protected Control createDialogArea(Composite parent) {
+		setTitle(JBossWSUIMessages.WSDLBrowseDialog_Title);
+		setMessage(JBossWSUIMessages.WSDLBrowseDialog_Message);
+
+		Composite mainComposite = new Composite (parent,SWT.NONE);
+		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+		gridData.horizontalSpan = 2;
+		mainComposite.setLayoutData(gridData);
+		GridLayout gridLayout = new GridLayout(2, false);
+		mainComposite.setLayout(gridLayout);
+
+		locationLabel = new Label(mainComposite, SWT.NONE);
+		locationLabel.setText(JBossWSUIMessages.WSDLBrowseDialog_WSDL_URI_Field);
+
+		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+		locationCombo = new Combo(mainComposite, SWT.BORDER | SWT.DROP_DOWN );
+		locationCombo.setLayoutData(gridData);
+		locationCombo.addModifyListener(new ModifyListener() {
+			public void modifyText(ModifyEvent arg0) {
+				IStatus status = validate();
+				if (status != Status.OK_STATUS) {
+					setGroupEnabled(false);
+				} else {
+					setGroupEnabled(true);
+				}
+			}
+		});
+		if (WSDLBrowseDialog.oldValues != null && WSDLBrowseDialog.oldValues.length > 0) {
+			for (int i = 0; i < oldValues.length; i++) {
+				locationCombo.add(WSDLBrowseDialog.oldValues[i]);
+			}
+		}
+
+		Composite buttonBar = new Composite ( mainComposite, SWT.NONE);
+		GridData buttonBarGD = new GridData(SWT.END, SWT.NONE, true, false);
+		buttonBarGD.horizontalSpan = 2;
+		buttonBar.setLayoutData(buttonBarGD);
+		buttonBar.setLayout(new RowLayout());
+
+		workspaceBrowseButton = new Button(buttonBar, SWT.NONE);
+		workspaceBrowseButton.setText(JBossWSUIMessages.WSDLBrowseDialog_WS_Browse);
+		workspaceBrowseButton.addSelectionListener(new SelectionListener() {
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				ElementTreeSelectionDialog dialog =
+					new ElementTreeSelectionDialog(getShell(),
+							new WorkbenchLabelProvider(),
+							new WorkbenchContentProvider());
+				dialog.setTitle(JBossWSUIMessages.WSDLBrowseDialog_WS_Browse_Select_WSDL_Title);
+				dialog.setMessage(JBossWSUIMessages.WSDLBrowseDialog_WS_Browse_Msg);
+				dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+				dialog.setAllowMultiple(false);
+				dialog.setEmptyListMessage(JBossWSUIMessages.WSDLBrowseDialog_WS_Browse_Select_WSDL_Msg);
+				dialog.setStatusLineAboveButtons(true);
+				dialog.setValidator(new ISelectionStatusValidator() {
+					
+					public IStatus validate(Object[] arg0) {
+						if (arg0.length > 0 && arg0[0] instanceof IFile) {
+							IFile resource = (IFile) arg0[0];
+							if (resource.getFileExtension().equals("wsdl")) { //$NON-NLS-1$
+								return Status.OK_STATUS;
+							}
+						}
+						return StatusUtils.errorStatus(JBossWSUIMessages.WSDLBrowseDialog_WS_Browse_Select_WSDL_Msg);
+					}
+				});
+				int rtnCode = dialog.open();
+				if (rtnCode == Window.OK) {
+					Object[] objects = dialog.getResult(); //fileDialog.getResult();
+					if (objects != null && objects.length > 0){
+						if (objects[0] instanceof IFile) {
+							IFile resource = (IFile) objects[0];
+							File tempFile = new File(resource.getRawLocationURI());
+							try {
+								URL testURL = tempFile.toURL();
+								locationCombo.setText(testURL.toExternalForm());
+								wsdlDefinition =
+									TesterWSDLUtils.readWSDLURL(testURL);
+								updateServiceCombo();
+							} catch (MalformedURLException e) {
+								e.printStackTrace();
+							} catch (WSDLException e) {
+								e.printStackTrace();
+							}
+						}
+					}
+				}
+			}
+			public void widgetSelected(SelectionEvent arg0) {
+				widgetDefaultSelected(arg0);
+			}
+		});
+		
+		fsBrowseButton = new Button(buttonBar, SWT.NONE);
+		fsBrowseButton.setText(JBossWSUIMessages.WSDLBrowseDialog_FS_Browse);
+		fsBrowseButton.addSelectionListener(new SelectionListener() {
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				FileDialog fileDialog = new FileDialog(getShell());
+				 String[] filterExt = { "*.wsdl", "*.xml", "*.*" };  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+				 fileDialog.setFilterExtensions(filterExt);				
+			     if (locationCombo.getText().trim().length() > 0) {
+			    	 try {
+						URI uri = new URI(locationCombo.getText());
+						File temp = new File(uri);
+						String parentPath = temp.getParent();
+						fileDialog.setFilterPath(parentPath);
+						fileDialog.setFileName(temp.getName());
+					} catch (URISyntaxException e1) {
+					} catch (IllegalArgumentException e2) {
+					}
+				}
+				String fileText = fileDialog.open();
+				if (fileText != null){
+					File tempFile = new File(fileText);
+					try {
+						URL testURL = tempFile.toURL();
+						locationCombo.setText(testURL.toExternalForm());
+						wsdlDefinition =
+							TesterWSDLUtils.readWSDLURL(testURL);
+						updateServiceCombo();
+					} catch (MalformedURLException e) {
+						JBossWSUIPlugin.log(e);
+					} catch (WSDLException e) {
+						JBossWSUIPlugin.log(e);
+					}
+				}
+			}
+			public void widgetSelected(SelectionEvent arg0) {
+				widgetDefaultSelected(arg0);
+			}
+		});
+		
+		urlBrowseButton = new Button(buttonBar, SWT.NONE);
+		urlBrowseButton.setText(JBossWSUIMessages.WSDLBrowseDialog_URL_Browse);
+		
+		urlBrowseButton.addSelectionListener(new SelectionListener() {
+			public void widgetSelected(SelectionEvent arg0) {
+				widgetDefaultSelected(arg0);
+			}
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				InputDialog inDialog = null;
+				if (locationCombo.getText().trim().length() > 0) {
+					inDialog = new InputDialog (getShell(), 
+							JBossWSUIMessages.WSDLBrowseDialog_WSDL_URL_Dialog_Title, 
+							JBossWSUIMessages.WSDLBrowseDialog_WSDL_URL_Prompt, locationCombo.getText(), null);
+				} else {
+					inDialog = new InputDialog (getShell(), 
+							JBossWSUIMessages.WSDLBrowseDialog_WSDL_URL_Dialog_Title, 
+							JBossWSUIMessages.WSDLBrowseDialog_WSDL_URL_Prompt, "", null); //$NON-NLS-1$
+				}
+				int rtnCode = inDialog.open();
+				if (rtnCode == Window.OK) {
+					locationCombo.setText(inDialog.getValue());
+					try {
+						URL testURL = new URL(inDialog.getValue());
+						locationCombo.setText(testURL.toExternalForm());
+						wsdlDefinition =
+							TesterWSDLUtils.readWSDLURL(testURL);
+						updateServiceCombo();
+					} catch (MalformedURLException e) {
+						JBossWSUIPlugin.log(e);
+					} catch (WSDLException e) {
+						JBossWSUIPlugin.log(e);
+					}
+				}
+			}
+		});
+		
+		group = new Group(mainComposite, SWT.NONE);
+		group.setText(JBossWSUIMessages.WSDLBrowseDialog_Group_Title);
+		gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+		gridData.horizontalSpan = 2;
+		group.setLayoutData(gridData);
+		group.setLayout(new GridLayout(2, false));
+		
+		serviceLabel = new Label(group, SWT.NONE);
+		serviceLabel.setText(JBossWSUIMessages.WSDLBrowseDialog_Service_Field);
+
+		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+		serviceCombo = new Combo(group, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY );
+		serviceCombo.setLayoutData(gridData);
+		serviceCombo.addSelectionListener(new SelectionListener(){
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				updatePortCombo();
+			}
+			public void widgetSelected(SelectionEvent arg0) {
+				widgetDefaultSelected(arg0);
+			}
+		});
+		
+		portLabel = new Label(group, SWT.NONE);
+		portLabel.setText(JBossWSUIMessages.WSDLBrowseDialog_Port_Field);
+
+		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
+		portCombo = new Combo(group, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
+		portCombo.setLayoutData(gridData);
+		portCombo.addSelectionListener(new SelectionListener(){
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				updateOperationList();
+			}
+			public void widgetSelected(SelectionEvent arg0) {
+				widgetDefaultSelected(arg0);
+			}
+		});
+
+		operationLabel = new Label(group, SWT.NONE);
+		operationLabel.setText(JBossWSUIMessages.WSDLBrowseDialog_Operation_Field);
+
+		gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+		gridData.verticalSpan = 3;
+		gridData.heightHint = 50;
+		opList = new List(group, SWT.BORDER | SWT.V_SCROLL );
+		opList.setLayoutData(gridData);
+		opList.addSelectionListener(new SelectionListener(){
+			public void widgetDefaultSelected(SelectionEvent arg0) {
+				WSDLBrowseDialog.this.operationTextValue = opList.getSelection()[0];
+			}
+			public void widgetSelected(SelectionEvent arg0) {
+				widgetDefaultSelected(arg0);
+			}
+		});
+
+		return mainComposite;
+	}
+
+	private void updateOperationList(){
+		if (portCombo.getSelectionIndex() > -1) {
+			String text = portCombo.getItem(portCombo.getSelectionIndex());
+			portTextValue = text;
+			Port port = (Port) portCombo.getData(text);
+
+			opList.removeAll();
+			
+			Binding wsdlBinding = port.getBinding();
+			this.bindingValue = wsdlBinding.getQName().getLocalPart();
+			PortType portType = wsdlBinding.getPortType();
+			@SuppressWarnings("rawtypes")
+			java.util.List operations = portType.getOperations();
+
+			Iterator<?> iter = operations.iterator();
+			while (iter.hasNext()) {
+				Operation operation = (Operation) iter.next();
+				opList.add(operation.getName());
+				opList.setData(operation.getName(), operation);
+			}
+			if (opList.getItemCount() > 0) {
+				opList.select(0);
+				this.operationTextValue = opList.getSelection()[0];
+			}
+		}
+	}
+
+	private void updatePortCombo(){
+		if (serviceCombo.getSelectionIndex() > -1) {
+			String text = serviceCombo.getItem(serviceCombo.getSelectionIndex());
+			serviceTextValue = text;
+			Service service = (Service) serviceCombo.getData(text);
+
+			portCombo.removeAll();
+			opList.removeAll();
+			
+			Iterator<?> iter = service.getPorts().values().iterator();
+			while (iter.hasNext()) {
+				Port port = (Port) iter.next();
+				if (port.getBinding() != null && port.getBinding().getExtensibilityElements() != null) {
+					@SuppressWarnings("rawtypes")
+					java.util.List elements = port.getBinding().getExtensibilityElements();
+					for (int i = 0; i < elements.size(); i++) {
+						if (elements.get(i) instanceof SOAPBinding || elements.get(i) instanceof SOAP12Binding ) {
+							portCombo.add(port.getName());
+							portCombo.setData(port.getName(), port);
+						}
+					}
+				}
+			}
+			if (portCombo.getItemCount() > 0) {
+				portCombo.select(0);
+				portTextValue = portCombo.getText();
+			}
+			updateOperationList();
+		}
+	}
+	
+	private void updateServiceCombo () {
+		serviceCombo.removeAll();
+		portCombo.removeAll();
+		opList.removeAll();
+		
+		Iterator<?> iter = wsdlDefinition.getServices().values().iterator();
+		while (iter.hasNext()) {
+			Service service = (Service) iter.next();
+			serviceCombo.add(service.getQName().getLocalPart());
+			serviceCombo.setData(service.getQName().getLocalPart(), service);
+		}
+		if (serviceCombo.getItemCount() > 0) {
+			serviceCombo.select(0);
+			serviceTextValue = serviceCombo.getText();
+		}
+		updatePortCombo();
+	}
+	
+	@Override
+	protected void configureShell(Shell newShell) {
+		super.configureShell(newShell);
+		newShell.setText(JBossWSUIMessages.WSDLBrowseDialog_Dialog_Title);
+	}
+	
+	private void setGroupEnabled ( boolean flag ) {
+		group.setEnabled(flag);
+		operationLabel.setEnabled(flag);
+		opList.setEnabled(flag);
+		portCombo.setEnabled(flag);
+		portLabel.setEnabled(flag);
+		serviceCombo.setEnabled(flag);
+		serviceLabel.setEnabled(flag);
+		if (getButton(IDialogConstants.OK_ID) != null) {
+			getButton(IDialogConstants.OK_ID).setEnabled(flag);
+		}
+		
+		if (!flag) {
+			opList.removeAll();
+			portCombo.removeAll();
+			portCombo.setText(""); //$NON-NLS-1$
+			serviceCombo.removeAll();
+			serviceCombo.setText(""); //$NON-NLS-1$
+		}
+	}
+	
+	private IStatus validate(){
+		String urlText = locationCombo.getText();
+		try {
+			URL testURL = new URL(urlText);
+			wsdlDefinition =
+				TesterWSDLUtils.readWSDLURL(testURL);
+			updateServiceCombo();
+		} catch (MalformedURLException e) {
+			return StatusUtils.errorStatus(JBossWSUIMessages.WSDLBrowseDialog_Status_Invalid_URL, e);
+		} catch (WSDLException e) {
+			return StatusUtils.errorStatus(JBossWSUIMessages.WSDLBrowseDialog_Status_WSDL_Unavailable, e);
+		}
+		return Status.OK_STATUS;
+	}
+
+	@Override
+	protected Control createContents(Composite parent) {
+		Control control = super.createContents(parent);
+
+		setGroupEnabled(false);
+
+		if (WSDLBrowseDialog.wsdlTextValue != null) {
+			this.locationCombo.setText(wsdlTextValue);
+			IStatus status = validate();
+			if (status != Status.OK_STATUS) {
+				setGroupEnabled(false);
+			} else {
+				setGroupEnabled(true);
+			}
+		}
+		return control;
+	}
+	
+}


Property changes on: trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/WSDLBrowseDialog.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list