Author: bfitzpat
Date: 2011-05-10 13:05:54 -0400 (Tue, 10 May 2011)
New Revision: 31192
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/FragmentConstants.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/NetUtils.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/SchemaUtils.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URIEncoder.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URLUtils.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/Validator.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSDLPartsToXSDTypeMapper.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/AddMonitorDialog.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/.classpath
trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.ui/pom.xml
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/JAXRSWSTestView2.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/TestHistoryEntry.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/WSDLBrowseDialog.java
Log:
OPEN - issue JBDS-1602: Web Service Tester generates SOAP bodies that cause marshaling
issues
https://issues.jboss.org/browse/JBDS-1602
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/.classpath
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/.classpath 2011-05-10 16:55:18 UTC (rev 31191)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/.classpath 2011-05-10 17:05:54 UTC (rev 31192)
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry exported="true" kind="lib"
path="lib/axis.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/jaxrpc.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/jaxrs-api.jar"/>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib"
path="lib/axis.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/jaxrpc.jar"/>
+ <classpathentry exported="true" kind="lib"
path="lib/jaxrs-api.jar"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
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 2011-05-10 16:55:18 UTC
(rev 31191)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF 2011-05-10 17:05:54 UTC
(rev 31192)
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %PLUGIN_NAME
Bundle-SymbolicName: org.jboss.tools.ws.ui;singleton:=true
-Bundle-Version: 1.2.1.qualifier
+Bundle-Version: 1.2.2.qualifier
Bundle-Activator: org.jboss.tools.ws.ui.JBossWSUIPlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
@@ -33,7 +33,8 @@
org.eclipse.osgi,
org.eclipse.jst.ws.annotations.core,
org.apache.commons.codec,
- org.apache.commons.discovery;bundle-version="[0.2.0,1.0.0)"
+ org.apache.commons.discovery;bundle-version="[0.2.0,1.0.0)",
+ org.eclipse.xsd
Bundle-ActivationPolicy: lazy
Export-Package: javax.ws.rs,
javax.ws.rs.core,
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/pom.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/pom.xml 2011-05-10 16:55:18 UTC (rev 31191)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/pom.xml 2011-05-10 17:05:54 UTC (rev 31192)
@@ -8,6 +8,6 @@
</parent>
<groupId>org.jboss.tools.ws.plugins</groupId>
<artifactId>org.jboss.tools.ws.ui</artifactId>
- <version>1.2.1-SNAPSHOT</version>
+ <version>1.2.2-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
\ No newline at end of file
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/FragmentConstants.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/FragmentConstants.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/FragmentConstants.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ * yyyymmdd bug Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20070305 117034 makandre(a)ca.ibm.com - Andrew Mak, Web Services Explorer should
support SOAP Headers
+ *******************************************************************************/
+package org.jboss.tools.ws.ui.utils;
+
+public class FragmentConstants
+{
+ // XSD minOccurs and maxOccurs
+ public static final int DEFAULT_MIN_OCCURS = 1;
+ public static final int DEFAULT_MAX_OCCURS = 1;
+ public static final int UNBOUNDED = -1;
+
+ // WSDL style
+ public static final int STYLE_DOCUMENT = 0;
+ public static final int STYLE_RPC = 1;
+
+ // WSDL Encoding styles
+ public static final int ENCODING_LITERAL = 0;
+ public static final int ENCODING_SOAP = 1;
+ public static final int ENCODING_URL = 2; // HTTP Get/Post
+
+ // IDs used by the fragment model
+ public static final String ID_SEPERATOR = "::"; //$NON-NLS-1$
+ public static final String INPUT_ID = "::input"; //$NON-NLS-1$
+ public static final String OUTPUT_ID = "::output"; //$NON-NLS-1$
+ public static final String TABLE_ID = "::tableID"; //$NON-NLS-1$
+ public static final String FRAGMENT_ID = "::fragmentID"; //$NON-NLS-1$
+ public static final String NAME_ANCHOR_ID = "::nameAnchorID"; //$NON-NLS-1$
+ public static final String FRAGMENT_VIEW_ID = "::fragmentViewID";
//$NON-NLS-1$
+ public static final String XSD_ATOMIC_ENUM_ID = "::xsdAtomicEnumID";
//$NON-NLS-1$
+ public static final String XSD_ALL_GROUP_ID = "::xsdAllGroupID";
//$NON-NLS-1$
+ public static final String PART_TOKEN = "^"; //$NON-NLS-1$
+
+ // Fragment view IDs
+ public static final String FRAGMENT_VIEW_SWITCH_FORM_TO_SOURCE =
"::fragmentViewSwitchFormToSource"; //$NON-NLS-1$
+ public static final String FRAGMENT_VIEW_SWITCH_SOURCE_TO_FORM =
"::fragmentViewSwitchSourceToForm"; //$NON-NLS-1$
+ public static final String SOURCE_CONTENT_HEADER = "::sourceContentHeader";
//$NON-NLS-1$
+ public static final String SOURCE_CONTENT = "::sourceContent"; //$NON-NLS-1$
+ public static final String SOURCE_CONTENT_NAMESPACE = "::sourceContentNS";
//$NON-NLS-1$
+
+ // Action input constants
+ public static final String NAME_ANCHOR = "nameAnchor"; //$NON-NLS-1$
+
+ // Namespaces contants
+ public static final String URI_XSD = "http://www.w3.org/2001/XMLSchema";
//$NON-NLS-1$
+ public static final String URI_SOAP =
"http://schemas.xmlsoap.org/soap/encoding/"; //$NON-NLS-1$
+ public static final String URI_SOAP_ENV =
"http://schemas.xmlsoap.org/soap/envelope/"; //$NON-NLS-1$
+ public static final String URI_WSDL = "http://schemas.xmlsoap.org/wsdl/";
//$NON-NLS-1$
+ public static final String URI_XSI =
"http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$
+ public static final String SOAP_ENC_ARRAY_TYPE = "arrayType"; //$NON-NLS-1$
+ public static final String XSI_TYPE = "type"; //$NON-NLS-1$
+ public static final String QNAME_PREFIX = "q"; //$NON-NLS-1$
+ public static final String QNAME_LOCAL_NAME_ARRAY_TYPE = "arrayType";
//$NON-NLS-1$
+ public static final String QNAME_LOCAL_NAME_ARRAY = "Array"; //$NON-NLS-1$
+ public static final String COLON = ":"; //$NON-NLS-1$
+ public static final String QNAME_LOCAL_NAME_HEADER = "Header";
//$NON-NLS-1$
+ public static final String QNAME_LOCAL_NAME_BODY = "Body"; //$NON-NLS-1$
+ public static final String QNAME_LOCAL_NAME_FAULT = "Fault"; //$NON-NLS-1$
+
+ // List
+ public static final String LIST_SEPERATOR = " "; //$NON-NLS-1$
+
+ // SOAP-ENC:Array
+ public static final String LEFT_SQUARE_BRACKET = "["; //$NON-NLS-1$
+ public static final String RIGHT_SQUARE_BRACKET = "]"; //$NON-NLS-1$
+
+ // XSDDefaultFragment
+ public static final String ROOT_ELEMENT_START_TAG = "<root>";
//$NON-NLS-1$
+ public static final String ROOT_ELEMENT_END_TAG = "</root>";
//$NON-NLS-1$
+
+ // Namespace URIs.
+ public static final String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
//$NON-NLS-1$
+ public static final String NS_URI_SOAP_ENV =
"http://schemas.xmlsoap.org/soap/envelope/"; //$NON-NLS-1$
+ public static final String NS_URI_SOAP_ENC =
"http://schemas.xmlsoap.org/soap/encoding/"; //$NON-NLS-1$
+ public static final String NS_URI_1999_SCHEMA_XSI =
"http://www.w3.org/1999/XMLSchema-instance"; //$NON-NLS-1$
+ public static final String NS_URI_1999_SCHEMA_XSD =
"http://www.w3.org/1999/XMLSchema"; //$NON-NLS-1$
+ public static final String NS_URI_2000_SCHEMA_XSI =
"http://www.w3.org/2000/10/XMLSchema-instance"; //$NON-NLS-1$
+ public static final String NS_URI_2000_SCHEMA_XSD =
"http://www.w3.org/2000/10/XMLSchema"; //$NON-NLS-1$
+ public static final String NS_URI_2001_SCHEMA_XSI =
"http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$
+ public static final String NS_URI_2001_SCHEMA_XSD =
"http://www.w3.org/2001/XMLSchema"; //$NON-NLS-1$
+ public static final String NS_URI_CURRENT_SCHEMA_XSI = NS_URI_2001_SCHEMA_XSI;
+ public static final String NS_URI_CURRENT_SCHEMA_XSD = NS_URI_2001_SCHEMA_XSD;
+ public static final String NS_URI_XML_SOAP =
"http://xml.apache.org/xml-soap"; //$NON-NLS-1$
+ public static final String NS_URI_XML_SOAP_DEPLOYMENT =
"http://xml.apache.org/xml-soap/deployment"; //$NON-NLS-1$
+ public static final String NS_URI_LITERAL_XML =
"http://xml.apache.org/xml-soap/literalxml"; //$NON-NLS-1$
+ public static final String NS_URI_XMI_ENC =
"http://www.ibm.com/namespaces/xmi"; //$NON-NLS-1$
+}
\ No newline at end of file
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/FragmentConstants.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester.java 2011-05-10
16:55:18 UTC (rev 31191)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * 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.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.soap.MimeHeader;
-import javax.xml.soap.MimeHeaders;
-import javax.xml.soap.SOAPMessage;
-
-import org.apache.axis.AxisFault;
-import org.apache.axis.Message;
-import org.apache.axis.MessageContext;
-import org.apache.axis.client.Call;
-import org.apache.axis.client.Service;
-import org.apache.axis.message.SOAPEnvelope;
-import org.apache.axis.transport.http.HTTPConstants;
-
-/**
- * Tester class for JAX-WS services
- * @author bfitzpat
- *
- */
-public class JAXWSTester {
-
- // the response message to pass back
- private String resultBody;
-
- private SOAPEnvelope resultSOAP;
-
- // the result HTTP headers to pass back
- private HashMap<String, String> resultHeaders;
-
- // utility constant
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
- /**
- * Constructor
- */
- public JAXWSTester() {
- // empty
- }
-
- /**
- * Return the response message
- * @return
- */
- public String getResultBody() {
- return this.resultBody;
- }
-
- /**
- * Return a map of HTTP headers from the response
- * @return
- */
- public Map<String, String> getResultHeaders() {
- return this.resultHeaders;
- }
-
- public SOAPEnvelope getResultSOAP(){
- return this.resultSOAP;
- }
-
- /**
- * Invoke the JAX-WS service
- * @param endpointurl
- * @param actionurl
- * @param body
- * @throws Exception
- */
- public void doTest( String endpointurl, String actionurl, String body ) throws Exception
{
- /*
- * the endpoint & action urls + the soap in are what we
- * need to invoke the WS
- */
- String endpoint = endpointurl;
- String action = actionurl;
- String soapIn = body;
-
- /* Use AXIS to call the WS */
- String document = WSTestUtils.stripNLsFromXML(soapIn);
- Service service = new Service();
- Call call= (Call) service.createCall();
- call.setTargetEndpointAddress( new java.net.URL(endpoint) );
- call.setOperationStyle( org.apache.axis.constants.Style.MESSAGE );
- if ( action != null ) {
- call.setProperty(Call.SOAPACTION_USE_PROPERTY,Boolean.TRUE);
- call.setProperty(Call.SOAPACTION_URI_PROPERTY,action);
- }
- Message message = new Message(document);
-
- resultSOAP = null;
-
- this.resultBody = EMPTY_STRING;
-
- try {
- resultSOAP = call.invoke( message );
-
- // Get back the response message
- if (resultSOAP != null && resultSOAP.getBody() != null) {
- this.resultBody = resultSOAP.getBody().toString();
- }
-
- // Get back the response HTTP headers and pass back as a Map
- if (call != null && call.getMessageContext() != null) {
- MessageContext mc = call.getMessageContext();
- if (mc != null){
- String statusCode = mc.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE).toString();
- String statusMessage =
mc.getProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE).toString();
- String protocol = mc.getTransportName();
- resultHeaders = new HashMap<String, String>();
- resultHeaders.put(null, protocol + " " + statusCode + " " +
statusMessage); //$NON-NLS-1$//$NON-NLS-2$
-// System.out.println(protocol + " " + statusCode + " " +
statusMessage);
- SOAPMessage sm = mc.getResponseMessage();
- if (sm != null){
- MimeHeaders mh = sm.getMimeHeaders();
- if (mh != null){
- Iterator<?> iter = mh.getAllHeaders();
- while (iter.hasNext()) {
- MimeHeader next = (MimeHeader)iter.next();
- resultHeaders.put(next.getName(), next.getValue());
- }
- }
- }
- }
- }
- } catch (AxisFault fault){
-
- // Get back the response message
- if (fault.getFaultString() != null) {
- this.resultBody = fault.getFaultString();
- }
-
- // Get back the response HTTP headers and pass back as a Map
- if (fault.getHeaders() != null && !fault.getHeaders().isEmpty()) {
- Iterator<?> iter = fault.getHeaders().iterator();
- resultHeaders = new HashMap<String, String>();
- while (iter.hasNext()) {
- Object next = iter.next();
- resultHeaders.put(next.toString(), ""); //$NON-NLS-1$
- }
- } else if (call != null && call.getMessageContext() != null) {
- MessageContext mc = call.getMessageContext();
- if (mc.getMessage() != null && mc.getMessage().getMimeHeaders() != null) {
- MimeHeaders mh = mc.getMessage().getMimeHeaders();
- Iterator<?> iter = mh.getAllHeaders();
- resultHeaders = new HashMap<String, String>();
- while (iter.hasNext()) {
- MimeHeader next = (MimeHeader)iter.next();
- resultHeaders.put(next.getName(), next.getValue());
- }
- }
- }
-
- }
-
- }
-}
\ No newline at end of file
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/NetUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/NetUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/NetUtils.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.jboss.tools.ws.ui.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.commons.codec.binary.Base64;
+
+public final class NetUtils
+{
+
+ /**
+ * Get the java.net.URLConnection given a string representing the URL. This class
ensures
+ * that proxy settings in WSAD are respected.
+ * @param urlString String representing the URL.
+ * @return java.net.URLCDonnection URLConnection to the URL.
+ */
+ public static final URLConnection getURLConnection(String urlString)
+ {
+ try
+ {
+ URL url = createURL(urlString);
+ URLConnection uc = url.openConnection();
+ String proxyUserName = System.getProperty("http.proxyUserName");
//$NON-NLS-1$
+ String proxyPassword = System.getProperty("http.proxyPassword");
//$NON-NLS-1$
+ if (proxyUserName != null && proxyPassword != null)
+ {
+ StringBuffer userNamePassword = new StringBuffer(proxyUserName);
+ userNamePassword.append(':').append(proxyPassword);
+ Base64 encoder = new Base64();
+ String encoding = new
String(encoder.encode(userNamePassword.toString().getBytes()));
+ userNamePassword.setLength(0);
+ userNamePassword.append("Basic ").append(encoding); //$NON-NLS-1$
+
uc.setRequestProperty("Proxy-authorization",userNamePassword.toString());
//$NON-NLS-1$
+ }
+ return uc;
+ }
+ catch (MalformedURLException e)
+ {
+ }
+ catch (IOException e)
+ {
+ }
+ return null;
+ }
+
+ /**
+ * Get the java.io.InputStream for a URL given a string representing the URL. This
class
+ * ensures that proxy settings in WSAD are respected.
+ * @param urlString String representing the URL.
+ * @return java.io.InputStream InputStream for reading the URL stream.
+ */
+ public static final InputStream getURLInputStream(String urlString)
+ {
+ try
+ {
+ URLConnection uc = getURLConnection(urlString);
+ if (uc != null)
+ {
+ InputStream is = uc.getInputStream();
+ return is;
+ }
+ }
+ catch (IOException e)
+ {
+ }
+ return null;
+ }
+
+ /**
+ * Create a URL from a string.
+ * @param urlString String representing the URL.
+ * @return URL java.lang.URL representation of the URL.
+ * @throws MalformedURLException
+ */
+ public static final URL createURL(String urlString) throws MalformedURLException
+ {
+ return new URL(urlString);
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/NetUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/SchemaUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/SchemaUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/SchemaUtils.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -0,0 +1,1225 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingInput;
+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.UnknownExtensibilityElement;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.soap.SOAPHeader;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.xsd.XSDDiagnostic;
+import org.eclipse.xsd.XSDDiagnosticSeverity;
+import org.eclipse.xsd.XSDNamedComponent;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDSchemaContent;
+import org.eclipse.xsd.XSDSchemaDirective;
+import org.eclipse.xsd.impl.XSDSchemaImpl;
+import org.eclipse.xsd.util.XSDParser;
+import org.jdom.Element;
+import org.jdom.input.DOMBuilder;
+
+import com.ibm.wsdl.Constants;
+
+/**
+ * Some of this code was borrowed from the org.eclipse.wst.ws.explorer Web Services
Explorer
+ * view from WTP.
+ * @author bfitzpat
+ *
+ */
+public class SchemaUtils {
+
+ private static final String SIMPLE_TYPE_NAME = "simpleType"; //$NON-NLS-1$
+ private static final String DOUBLE_TYPE_NAME = "double"; //$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 BOOLEAN_TYPE_NAME = "boolean"; //$NON-NLS-1$
+ private static final String DECIMAL_TYPE_NAME = "decimal"; //$NON-NLS-1$
+ private static final String PRECISION_DECIMAL_TYPE_NAME = "precisionDecimal";
//$NON-NLS-1$
+ private static final String FLOAT_TYPE_NAME = "float"; //$NON-NLS-1$
+ private static final String DURATION_TYPE_NAME = "duration"; //$NON-NLS-1$
+ private static final String DATETIME_TYPE_NAME = "dateTime"; //$NON-NLS-1$
+ private static final String DATE_TYPE_NAME = "date"; //$NON-NLS-1$
+ private static final String TIME_TYPE_NAME = "time"; //$NON-NLS-1$
+ private static final String GYEARMONTH_TYPE_NAME = "gYearMonth";
//$NON-NLS-1$
+ private static final String GYEAR_TYPE_NAME = "gYear"; //$NON-NLS-1$
+ private static final String GMONTHDAY_TYPE_NAME = "gMonthDay"; //$NON-NLS-1$
+ private static final String GDAY_TYPE_NAME = "gDay"; //$NON-NLS-1$
+ private static final String GMONTH_TYPE_NAME = "gMonth"; //$NON-NLS-1$
+ private static final String HEXBINARY_TYPE_NAME = "hexBinary"; //$NON-NLS-1$
+ private static final String BASE64BINARY_TYPE_NAME = "base64Binary";
//$NON-NLS-1$
+ private static final String ANYURI_TYPE_NAME = "anyURI"; //$NON-NLS-1$
+ private static final String NOTATION_TYPE_NAME = "NOTATION"; //$NON-NLS-1$
+
+ private static Vector<XSDSchema> schemaList_;
+ private static Vector<QName> w3SchemaQNameList_;
+ private static Vector<XSDSchema> constantSchemaList_;
+ private static HashMap<String, String> namespacesAndPrefixes_;
+ private static String wsdlUrl_;
+ private static Vector<String> schemaURI_;
+ private static Definition definition_;
+ private static boolean rootIsQualified_ = false;
+ private static String rootURI_ = null;
+
+ 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 final static String SOAP_NS_URI =
"http://schemas.xmlsoap.org/soap/envelope/"; //$NON-NLS-1$
+ public final static String SOAP12_ENVELOPE_NS_URI =
"http://www.w3.org/2003/05/soap-envelope"; //$NON-NLS-1$
+ public final static String SOAP12_NS_URI =
"http://schemas.xmlsoap.org/wsdl/soap12/"; //$NON-NLS-1$
+ public final static String SOAP12_PREFIX = "soap12"; //$NON-NLS-1$
+ public final static String SOAP_PREFIX = "soap"; //$NON-NLS-1$
+
+ static
+ {
+ // w3 schema URI list:
+ //
http://www.w3.org/2001/XMLSchema
+ //
http://www.w3.org/2000/10/XMLSchema
+ //
http://www.w3.org/1999/XMLSchema
+ w3SchemaQNameList_ = new Vector<QName>();
+ w3SchemaQNameList_.addElement(new
QName(FragmentConstants.NS_URI_CURRENT_SCHEMA_XSD,"schema")); //$NON-NLS-1$
+ w3SchemaQNameList_.addElement(new
QName(FragmentConstants.NS_URI_2000_SCHEMA_XSD,"schema")); //$NON-NLS-1$
+ w3SchemaQNameList_.addElement(new
QName(FragmentConstants.NS_URI_1999_SCHEMA_XSD,"schema")); //$NON-NLS-1$
+
+ // Constant schema URI list:
+ //
http://www.w3.org/2001/XMLSchema
+ //
http://www.w3.org/2000/10/XMLSchema
+ //
http://www.w3.org/1999/XMLSchema
+ //
http://schemas.xmlsoap.org/soap/encoding/
+ //
http://schemas.xmlsoap.org/wsdl/
+ constantSchemaList_ = new Vector<XSDSchema>();
+ constantSchemaList_.addElement(XSDSchemaImpl.getSchemaForSchema(FragmentConstants.NS_URI_CURRENT_SCHEMA_XSD));
+ constantSchemaList_.addElement(XSDSchemaImpl.getSchemaForSchema(FragmentConstants.NS_URI_2000_SCHEMA_XSD));
+ constantSchemaList_.addElement(XSDSchemaImpl.getSchemaForSchema(FragmentConstants.NS_URI_1999_SCHEMA_XSD));
+ constantSchemaList_.addElement(XSDSchemaImpl.getSchemaForSchema(FragmentConstants.NS_URI_SOAP_ENC));
+ constantSchemaList_.addElement(XSDSchemaImpl.getSchemaForSchema(FragmentConstants.URI_WSDL));
+
+ namespacesAndPrefixes_ = new HashMap<String, String>();
+ }
+
+ public static Vector<String> loadWSDL(Definition wsdlDefinition ) throws
WSDLException
+ {
+
+ Vector<String> errorMessages = new Vector<String>();
+ definition_ = wsdlDefinition;
+
+
+ if (definition_ != null)
+ {
+ wsdlUrl_ = wsdlDefinition.getDocumentBaseURI();
+ gatherSchemas(definition_, wsdlUrl_);
+ // Validate the schemas.
+ for (int i=0;i<schemaList_.size();i++)
+ {
+ XSDSchema xsdSchema = (XSDSchema)schemaList_.elementAt(i);
+ // xsdSchema.clearDiagnostics();
+ // xsdSchema.validate();
+ if (xsdSchema == null) continue;
+ EList<XSDDiagnostic> errors = xsdSchema.getAllDiagnostics();
+ if (!errors.isEmpty())
+ {
+ for (ListIterator<XSDDiagnostic> li = errors.listIterator();li.hasNext();)
+ {
+ XSDDiagnostic xd = (XSDDiagnostic)li.next();
+ String msg = xd.getMessage();
+ // do not report low severity diagnostics or erroneous array reference errors.
+ if (xd.getSeverity().getValue() == XSDDiagnosticSeverity.FATAL_LITERAL.getValue()
|| (msg != null && msg.length() > 0 &&
msg.toLowerCase().indexOf("#array") != -1)) //$NON-NLS-1$
+ li.remove();
+ else
+ {
+ if (msg != null && msg.length() > 0)
+ errorMessages.addElement(xd.getMessage());
+ }
+ }
+ }
+ }
+
+ for (int i=0;i<constantSchemaList_.size();i++)
+ schemaList_.addElement(constantSchemaList_.elementAt(i));
+
+ }
+ return errorMessages;
+ }
+
+ public static String getSampleSOAPInputMessage ( Definition wsdlDefinition, String
serviceName, String portName, String bindingName, String opName ) {
+
+ try {
+ loadWSDL (wsdlDefinition);
+ } catch (WSDLException e) {
+ e.printStackTrace();
+ }
+ namespacesAndPrefixes_ = new HashMap<String, String>();
+ 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();
+ StringBuffer buf = new StringBuffer();
+ for( Iterator<?> it4 = parts.iterator(); it4.hasNext(); ) {
+ Part part = (Part) it4.next();
+ if (part.getName().equalsIgnoreCase("header")) { //$NON-NLS-1$
+ continue;
+ }
+ WSDLPartsToXSDTypeMapper mapper = new WSDLPartsToXSDTypeMapper();
+ mapper.addSchemas(schemaList_);
+
+ buf.append(startProcessingPartXML(wsdlDefinition, part));
+ }
+ return buf.toString();
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public static Definition readWSDLURL(URL contextURL) throws WSDLException,
NullPointerException {
+ Properties props = System.getProperties();
+ String oldPropValue = props.getProperty(DEF_FACTORY_PROPERTY_NAME);
+
+ wsdlUrl_ = contextURL.toExternalForm();
+ 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 getSampleSOAPMessageHeader ( Definition wsdlDefinition, String
serviceName, String portName, String bindingName, String opName ) {
+
+ try {
+ loadWSDL (wsdlDefinition);
+ } catch (WSDLException e) {
+ e.printStackTrace();
+ }
+
+ namespacesAndPrefixes_ = new HashMap<String, String>();
+ 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)) {
+ BindingInput input = operation.getBindingInput();
+ List<?> extensions = input.getExtensibilityElements();
+ for (Iterator<?> extIter = extensions.iterator(); extIter.hasNext();) {
+ Object extension = extIter.next();
+ if (extension instanceof SOAPHeader) {
+ SOAPHeader header = (SOAPHeader) extension;
+ String part = header.getPart();
+ StringBuffer buf = new StringBuffer();
+ WSDLPartsToXSDTypeMapper mapper = new WSDLPartsToXSDTypeMapper();
+ mapper.addSchemas(schemaList_);
+ buf.append(startProcessingPartXML(wsdlDefinition, part,
header.getMessage().getNamespaceURI()));
+ return buf.toString();
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static XSDSchema getSchemaForNamespace ( String namespaceURI ) {
+ Iterator<XSDSchema> iter = schemaList_.iterator();
+ while (iter.hasNext()) {
+ XSDSchema schema = (XSDSchema)iter.next();
+ if (schema != null && schema.getTargetNamespace() != null &&
schema.getTargetNamespace().equals(namespaceURI)) {
+ return schema;
+ }
+ }
+ return null;
+ }
+
+ private static String getURIForNamespacePrefix ( String nsPrefix ) {
+ Iterator<XSDSchema> iter = schemaList_.iterator();
+ while (iter.hasNext()) {
+ XSDSchema schema = (XSDSchema)iter.next();
+ String nsURI =
+ schema.getQNamePrefixToNamespaceMap().get(nsPrefix);
+ if (nsURI != null) {
+ return nsURI;
+ }
+ }
+ return null;
+ }
+
+ private final static void gatherSchemas(Definition definition, String definitionURL)
+ {
+ schemaList_ = new Vector<XSDSchema>();
+ Types types = definition.getTypes();
+ if (types != null)
+ {
+ List<?> extTypes = types.getExtensibilityElements();
+ if (extTypes != null)
+ {
+ // org.eclipse.emf.common.util.URI uri =
org.eclipse.emf.common.util.URI.createURI(definitionURL);
+ // Resource resource = resourceSet.createResource(uri);
+ for (int i=0;i<extTypes.size();i++)
+ {
+ XSDSchema xsdSchema = null;
+ Object obj = extTypes.get(i);
+ if (obj instanceof Schema) {
+ Schema schemaElement = (Schema) obj;
+ if (isW3SchemaElementType(schemaElement.getElementType()))
+ {
+ xsdSchema = XSDSchemaImpl.createSchema(schemaElement.getElement());
+ if(!checkSchemaURI(definitionURL)){
+ schemaList_.addElement(xsdSchema);
+ gatherSchemaDirective(xsdSchema, definitionURL);
+ }
+ xsdSchema.update();
+ xsdSchema.updateElement();
+ //Add the Schema to the resource
+ // boolean success = resource.getContents().add(xsdSchema);
+ // System.out.println(success + "Added schema " +
xsdSchema.getTargetNamespace() + " to wsdl resource " + uri.toString());
+ }
+ }
+ else if (obj instanceof UnknownExtensibilityElement)
+ {
+ UnknownExtensibilityElement schemaElement = (UnknownExtensibilityElement)obj;
+ if (isW3SchemaElementType(schemaElement.getElementType()))
+ {
+ xsdSchema = XSDSchemaImpl.createSchema(schemaElement.getElement());
+ if(!checkSchemaURI(definitionURL)){
+ schemaList_.addElement(xsdSchema);
+ gatherSchemaDirective(xsdSchema, definitionURL);
+ }
+ //Add the Schema to the resource
+ // boolean success = resource.getContents().add(xsdSchema);
+ // System.out.println(success + "Added schema " +
xsdSchema.getTargetNamespace() + " to wsdl resource " + uri.toString());
+ }
+ }
+ }
+ }
+ }
+ Map<?, ?> imports = definition.getImports();
+ if (imports != null)
+ gatherImportedSchemas(definition,imports);
+ }
+
+ private final static boolean isW3SchemaElementType(QName qname)
+ {
+ for (int i=0;i<w3SchemaQNameList_.size();i++)
+ {
+ QName w3SchemaQName = (QName)w3SchemaQNameList_.elementAt(i);
+ if (w3SchemaQName.equals(qname))
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean checkSchemaURI(String schemaURI){
+ boolean found = false;
+
+ if (schemaURI != null) {
+ schemaURI = normalize(schemaURI);
+ if(schemaURI.equals(normalize(wsdlUrl_)))return false;
+ Enumeration<String> e = schemaURI_.elements();
+ while(e.hasMoreElements()){
+ String uri = (String)e.nextElement();
+ if(schemaURI.equals(uri)){
+ found = true;
+ break;
+ }
+ }
+
+ if (!found){
+ schemaURI_.addElement(schemaURI);
+ }
+ }
+ return found;
+
+ }
+
+ private static String normalize(String uri )
+ {
+ try {
+ String encodedURI = URIEncoder.encode(uri,"UTF-8"); //$NON-NLS-1$
+ URI normalizedURI = new URI(encodedURI);
+ normalizedURI = normalizedURI.normalize();
+ return normalizedURI.toString();
+ } catch (URISyntaxException e) {
+ return uri;
+ } catch (UnsupportedEncodingException e) {
+ return uri;
+ }
+ }
+
+ private final static void gatherSchemaDirective(XSDSchema xsdSchema, String
xsdSchemaURL)
+ {
+ if (xsdSchema != null)
+ {
+ EList<XSDSchemaContent> xsdSchemaContents = xsdSchema.getContents();
+ for (Iterator<XSDSchemaContent> it = xsdSchemaContents.iterator();
it.hasNext();)
+ {
+ Object content = it.next();
+ if (content instanceof XSDSchemaDirective)
+ {
+ XSDSchemaDirective xsdSchemaDirective = (XSDSchemaDirective)content;
+ StringBuffer xsdSchemaDirectiveURL = new StringBuffer();
+ String xsdSchemaDirectiveLocation = xsdSchemaDirective.getSchemaLocation();
+ if (xsdSchemaDirectiveLocation != null &&
xsdSchemaDirectiveLocation.indexOf(':') == -1 && xsdSchemaURL != null
&& xsdSchemaURL.indexOf(':') != -1)
+ {
+ // relative URL
+ int index = xsdSchemaURL.lastIndexOf('/');
+ if (index != -1)
+ xsdSchemaDirectiveURL.append(xsdSchemaURL.substring(0, index+1));
+ else
+ {
+ xsdSchemaDirectiveURL.append(xsdSchemaURL);
+ xsdSchemaDirectiveURL.append('/');
+ }
+ }
+ xsdSchemaDirectiveURL.append(xsdSchemaDirectiveLocation);
+
+ //encode the URL so that Schemas with non-ASCII filenames can be resolved
+ String xsdSchemaDirectiveURLString =
URLUtils.encodeURLString(xsdSchemaDirectiveURL.toString());
+ // resolve schema directive
+ XSDSchema resolvedSchema = xsdSchemaDirective.getResolvedSchema();
+ if (resolvedSchema == null && xsdSchemaDirectiveURLString.length() > 0)
+ resolvedSchema = getSchema(xsdSchemaDirectiveURLString);
+ if (resolvedSchema != null)
+ {
+ if(!checkSchemaURI(xsdSchemaDirectiveURLString)){
+ schemaList_.addElement(resolvedSchema);
+ gatherSchemaDirective(resolvedSchema, xsdSchemaDirectiveURLString);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private final static XSDSchema getSchema(String locURI)
+ {
+ locURI = URLUtils.encodeURLString(locURI);
+ XSDSchema xsdSchema = XSDSchemaImpl.getSchemaForSchema(locURI);
+ if (xsdSchema == null)
+ {
+ @SuppressWarnings("deprecation")
+ XSDParser p = new XSDParser();
+ InputStream is = NetUtils.getURLInputStream(locURI);
+ if (is != null)
+ {
+ p.parse(is);
+ xsdSchema = p.getSchema();
+ }
+ }
+ return xsdSchema;
+ }
+
+ private final static void gatherImportedSchemas(Definition definition,Map<?, ?>
imports)
+ {
+ for (Iterator<?> iterator = imports.keySet().iterator();iterator.hasNext();)
+ {
+ List<?> importList = (List<?>)imports.get(iterator.next());
+ for (int i=0;i<importList.size();i++)
+ {
+ Import imp = (Import)importList.get(i);
+ StringBuffer locURI = new StringBuffer(imp.getLocationURI());
+ if (!Validator.validateURL(locURI.toString()))
+ {
+ String base = definition.getDocumentBaseURI();
+ locURI.insert(0,base.substring(0,base.lastIndexOf('/')+1));
+ }
+ try
+ {
+ URL tryURL = new URL ( locURI.toString());
+ Definition importDef = readWSDLURL( tryURL );
+ gatherSchemas(importDef, locURI.toString());
+ }
+ catch (WSDLException e)
+ {
+ // May be an XSD file.
+ gatherSchema(locURI.toString());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private final static void gatherSchema(String locURI)
+ {
+ XSDSchema xsdSchema = getSchema(locURI);
+ if (xsdSchema != null)
+ {
+ schemaList_.addElement(xsdSchema);
+ gatherSchemaDirective(xsdSchema, locURI);
+ }
+ }
+
+ private static XSDSchema findFirstSchemaWithPartNameAsChild ( String partName ) {
+ for (Iterator<XSDSchema> schemaIter = schemaList_.iterator();
schemaIter.hasNext(); ) {
+ XSDSchema schema = schemaIter.next();
+ DOMBuilder domBuilder = new DOMBuilder();
+ org.jdom.Element jdomSchemaElement = domBuilder.build(schema.getElement());
+ List<?> kids = jdomSchemaElement.getChildren();
+ for (Iterator<?> kidIter = kids.iterator(); kidIter.hasNext(); ) {
+ Object kid = kidIter.next();
+ if (kid instanceof org.jdom.Element) {
+ org.jdom.Element kidElement = (org.jdom.Element) kid;
+ if (kidElement.getAttribute("name") != null) { //$NON-NLS-1$
+ if (kidElement.getAttributeValue("name").equals(partName)) {
//$NON-NLS-1$
+ return schema;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static org.jdom.Element findFirstElementWithPartNameInSchema( XSDSchema schema,
String partName ) {
+ DOMBuilder domBuilder = new DOMBuilder();
+ org.jdom.Element jdomSchemaElement = domBuilder.build(schema.getElement());
+ List<?> kids = jdomSchemaElement.getChildren();
+ for (Iterator<?> kidIter = kids.iterator(); kidIter.hasNext(); ) {
+ Object kid = kidIter.next();
+ if (kid instanceof org.jdom.Element) {
+ org.jdom.Element kidElement = (org.jdom.Element) kid;
+ if (kidElement.getAttribute("name") != null) { //$NON-NLS-1$
+ if (kidElement.getAttributeValue("name").equals(partName)) {
//$NON-NLS-1$
+ return kidElement;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static String startProcessingPartXML ( Definition wsdlDefinition, String
partName, String partUri ) {
+
+ XSDSchema schema = findFirstSchemaWithPartNameAsChild(partName);
+ DOMBuilder domBuilder = new DOMBuilder();
+ org.jdom.Element jdomSchemaElement = domBuilder.build(schema.getElement());
+
+ org.jdom.Element jdomElement = findFirstElementWithPartNameInSchema(schema, partName);
+
+ String typeAttr = jdomElement.getAttributeValue("type"); //$NON-NLS-1$
+ String nsprefix = null;
+ String nstypename = typeAttr;
+ if (typeAttr.indexOf(':') > 0) {
+ nsprefix = typeAttr.substring(0, typeAttr.indexOf(':'));
+ nstypename = typeAttr.substring(typeAttr.indexOf(':') + 1,
typeAttr.length());
+ }
+
+ String uri = schema.getTargetNamespace();
+ if (nsprefix != null && !nsprefix.equalsIgnoreCase("tns")) {
//$NON-NLS-1$
+ uri = getNSURI(nsprefix, wsdlDefinition);
+ }
+
+ StringBuffer buf = new StringBuffer();
+
+ if (nsprefix != null && !nsprefix.equalsIgnoreCase("tns")) {
//$NON-NLS-1$
+ if (schema.getTargetNamespace().equals(uri)) {
+ // cool, we're good
+ buf.append(createXMLForJDOMElement2( jdomSchemaElement, jdomElement ));
+ } else {
+ XSDSchema importXSD = getSchemaForNamespace(uri);
+ if (importXSD != null) {
+ importXSD.updateElement(true);
+ org.jdom.Element jdomSchemaElement2 = domBuilder.build(importXSD.getElement());
+ Element child =
+ jdomSchemaElement2.getChild(nstypename);
+ buf.append(createXMLForJDOMElement2( jdomSchemaElement2, child ));
+ }
+ }
+ } else {
+ buf.append(createXMLForJDOMElement2( jdomSchemaElement, jdomElement ));
+ }
+
+ return buf.toString();
+ }
+
+ private static String startProcessingPartXML ( Definition wsdlDefinition, Part part ) {
+ DOMBuilder domBuilder = new DOMBuilder();
+ WSDLPartsToXSDTypeMapper mapper = new WSDLPartsToXSDTypeMapper();
+ mapper.addSchemas(schemaList_);
+ XSDNamedComponent xsdComponent = mapper.getXSDTypeFromSchema(part);
+ xsdComponent.updateElement(true);
+
+ XSDSchema schema = xsdComponent.getSchema();
+ schema.updateElement(true);
+
+ if (!schema.getTargetNamespace().equals(FragmentConstants.NS_URI_CURRENT_SCHEMA_XSD))
{
+ rootIsQualified_ = true;
+ rootURI_ = schema.getTargetNamespace();
+ }
+
+ org.jdom.Element jdomSchemaElement = domBuilder.build(schema.getElement());
+ org.jdom.Element jdomElement = domBuilder.build(xsdComponent.getElement());
+
+ String typeAttr = xsdComponent.getElement().getAttribute("type");
//$NON-NLS-1$
+ String nsprefix = null;
+ String nstypename = typeAttr;
+ if (typeAttr.indexOf(':') > 0) {
+ nsprefix = typeAttr.substring(0, typeAttr.indexOf(':'));
+ nstypename = typeAttr.substring(typeAttr.indexOf(':') + 1,
typeAttr.length());
+ }
+
+ String uri = schema.getTargetNamespace();
+ if (nsprefix != null && !nsprefix.equalsIgnoreCase("tns")) {
//$NON-NLS-1$
+ uri = getNSURI(nsprefix, wsdlDefinition);
+ }
+
+ StringBuffer buf = new StringBuffer();
+
+ if (nsprefix != null && !nsprefix.equalsIgnoreCase("tns")) {
//$NON-NLS-1$
+ if (schema.getTargetNamespace().equals(uri)) {
+ // cool, we're good
+ org.jdom.Element jdomSchemaElement2 = domBuilder.build(xsdComponent.getElement());
+ buf.append(createXMLForJDOMElement2( jdomSchemaElement, jdomSchemaElement2 ));
+ } else {
+ XSDSchema importXSD = getSchemaForNamespace(uri);
+ if (importXSD != null) {
+ importXSD.updateElement(true);
+ org.jdom.Element jdomSchemaElement2 = domBuilder.build(importXSD.getElement());
+ Element child =
+ jdomSchemaElement2.getChild(nstypename);
+ buf.append(createXMLForJDOMElement2( jdomSchemaElement2, child ));
+ }
+ }
+ } else {
+ buf.append(createXMLForJDOMElement2( jdomSchemaElement, jdomElement ));
+ }
+
+ return buf.toString();
+ }
+
+ private static org.jdom.Element findJDOMTypeInSchema ( org.jdom.Element schemaElement,
String typeName ) {
+ if (schemaElement != null) {
+ String nstypename = null;
+ if (typeName.indexOf(':') > -1) {
+ nstypename = typeName.substring(typeName.indexOf(':') + 1,
typeName.length());
+ } else {
+ nstypename = typeName;
+ }
+ List<?> kids = schemaElement.getChildren();
+ for (Iterator<?> kidsIter = kids.iterator(); kidsIter.hasNext(); ) {
+ Object kid = kidsIter.next();
+ if (kid instanceof org.jdom.Element) {
+ org.jdom.Element kidelement = (org.jdom.Element)kid;
+ if (kidelement.getName().equals("complexType")) { //$NON-NLS-1$
+ if (kidelement.getAttributeValue("name").equals(nstypename))
//$NON-NLS-1$
+ return kidelement;
+ }
+ if (kidelement.getName().equals("attribute")) { //$NON-NLS-1$
+ if (kidelement.getAttributeValue("name").equals(nstypename))
//$NON-NLS-1$
+ return kidelement;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static org.jdom.Element findJDOMTypeInSchemaByNameAttr ( org.jdom.Element
schemaElement, String name ) {
+ if (schemaElement != null) {
+ List<?> kids = schemaElement.getChildren();
+ for (Iterator<?> kidsIter = kids.iterator(); kidsIter.hasNext(); ) {
+ Object kid = kidsIter.next();
+ if (kid instanceof org.jdom.Element) {
+ org.jdom.Element kidelement = (org.jdom.Element)kid;
+ if (kidelement.getName().equals("complexType")) { //$NON-NLS-1$
+ if (kidelement.getAttributeValue("name").equals(name)) //$NON-NLS-1$
+ return kidelement;
+ }
+ if (kidelement.getName().equals("attribute")) { //$NON-NLS-1$
+ if (kidelement.getAttributeValue("name").equals(name)) //$NON-NLS-1$
+ return kidelement;
+ }
+ if (kidelement.getName().equals("element")) { //$NON-NLS-1$
+ if (kidelement.getAttributeValue("name").equals(name)) //$NON-NLS-1$
+ return kidelement;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static org.jdom.Element findJDOMElementInSchema ( org.jdom.Element
schemaElement, String typeName ) {
+ if (schemaElement != null) {
+ List<?> kids = schemaElement.getChildren();
+ for (Iterator<?> kidsIter = kids.iterator(); kidsIter.hasNext(); ) {
+ Object kid = kidsIter.next();
+ if (kid instanceof org.jdom.Element) {
+ org.jdom.Element kidelement = (org.jdom.Element)kid;
+ if (kidelement.getName().equals("element")) { //$NON-NLS-1$
+ String attrvalue = kidelement.getAttributeValue("type"); //$NON-NLS-1$
+ if (attrvalue != null && attrvalue.equals(typeName)) {
+ kidelement = findJDOMTypeInSchema(schemaElement, typeName);
+ return kidelement;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static org.jdom.Element findJDOMElementInSchemaByName ( org.jdom.Element
schemaElement, String typeName ) {
+ if (schemaElement != null) {
+ List<?> kids = schemaElement.getChildren();
+ for (Iterator<?> kidsIter = kids.iterator(); kidsIter.hasNext(); ) {
+ Object kid = kidsIter.next();
+ if (kid instanceof org.jdom.Element) {
+ org.jdom.Element kidelement = (org.jdom.Element)kid;
+ if (kidelement.getName().equals("element")) { //$NON-NLS-1$
+ String attrvalue = kidelement.getAttributeValue("name"); //$NON-NLS-1$
+ if (attrvalue != null && attrvalue.equals(typeName)) {
+ String elemType = kidelement.getAttributeValue("type"); //$NON-NLS-1$
+ if (elemType != null) {
+ String nsprefix = elemType.substring(0, elemType.indexOf(':'));
+ String testUri = getURIForNamespacePrefix(nsprefix);
+ XSDSchema importXSD = getSchemaForNamespace(testUri);
+ if (importXSD != null) {
+ DOMBuilder domBuilder = new DOMBuilder();
+ importXSD.updateElement(true);
+ org.jdom.Element importXSDSchema = domBuilder.build(importXSD.getElement());
+ org.jdom.Element element2 = findJDOMTypeInSchema(importXSDSchema, elemType);
+ if (element2 != null) {
+ return element2;
+ } else {
+ element2 = findJDOMElementInSchema(importXSDSchema, elemType);
+ if (element2 != null) {
+ return element2;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private static String handleAttributes ( org.jdom.Element element ) {
+ StringBuffer buf = new StringBuffer();
+ List<?> kids = element.getChildren();
+ boolean isQualified = false;
+ for (Iterator<?> kidIter = kids.iterator(); kidIter.hasNext(); ) {
+ Element kid = (Element) kidIter.next();
+ if (kid.getName().equals("attribute") ) {//$NON-NLS-1$
+// <xs:attribute ref="ns3:C" use="required" />
+ if (kid.getAttribute("ref") != null) {//$NON-NLS-1$
+ String elemType = kid.getAttributeValue("ref");//$NON-NLS-1$
+ String nsprefix = elemType.substring(0, elemType.indexOf(':'));
+ String typename = elemType.substring(elemType.indexOf(':') + 1,
elemType.length());
+ if (elemType.indexOf(':') > -1) {
+ if (!(elemType.startsWith("xs:") ||
elemType.startsWith("xsd:"))) //$NON-NLS-1$ //$NON-NLS-2$
+ isQualified = true;
+ }
+
+ String testUri = getURIForNamespacePrefix(nsprefix);
+ XSDSchema importXSD = getSchemaForNamespace(testUri);
+ if (importXSD != null) {
+ DOMBuilder domBuilder = new DOMBuilder();
+ importXSD.updateElement(true);
+ org.jdom.Element importXSDSchema = domBuilder.build(importXSD.getElement());
+ org.jdom.Element element2 = findJDOMTypeInSchema(importXSDSchema, typename);
+ if (element2 != null) {
+ element = element2;
+ } else {
+ element2 = findJDOMElementInSchema(importXSDSchema, typename);
+ if (element2 != null) {
+ element = element2;
+ }
+ }
+ if (element != null) {
+ if (isQualified) {
+ String prefix = makePrefixFromURI(testUri);
+ //
xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
+ if (!namespacesAndPrefixes_.containsKey(prefix)) {
+ buf.append(" xmlns:" + prefix + "=\"" + testUri +
"\""); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ namespacesAndPrefixes_.put(prefix, testUri);
+ }
+ buf.append(' ' + prefix + ':');
+ }
+ String name = element.getAttributeValue("name"); //$NON-NLS-1$
+ buf.append(name + "=\"?\" "); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ return buf.toString();
+ }
+
+ private static boolean namespacePrefixListContainsURI ( String uri ) {
+ if (namespacesAndPrefixes_ != null) {
+ if (namespacesAndPrefixes_.containsValue(uri)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static String makePrefixFromURI ( String uri ) {
+
+ if (namespacePrefixListContainsURI(uri)) {
+ Iterator<Entry<String, String>> iter =
namespacesAndPrefixes_.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry<String, String> entry = iter.next();
+ if (entry.getValue().equals(uri)) {
+ return entry.getKey();
+ }
+ }
+ }
+
+ String tnsprefix = uri.substring(uri.indexOf("://") + 3, uri.length());
//$NON-NLS-1$
+ if (tnsprefix.length() > 4) {
+ if (tnsprefix.endsWith("/")) { //$NON-NLS-1$
+ tnsprefix = tnsprefix.substring(0, tnsprefix.length() - 1);
+ }
+ if (tnsprefix.lastIndexOf('/') > -1) {
+ tnsprefix = tnsprefix.substring(tnsprefix.lastIndexOf('/') + 1,
tnsprefix.length());
+ }
+ if (tnsprefix.length() > 4) {
+ tnsprefix = tnsprefix.substring(0, 4);
+ }
+ tnsprefix = tnsprefix.toLowerCase();
+
+ if (namespacesAndPrefixes_.containsKey(tnsprefix)) {
+ int i = 1;
+ String test = tnsprefix + i;
+ while (namespacesAndPrefixes_.containsKey(test)) {
+ i++;
+ test = tnsprefix + i;
+ }
+ tnsprefix = test;
+ }
+ }
+ return tnsprefix;
+ }
+
+ private static boolean elementHasChildren ( org.jdom.Element element ) {
+ boolean rtnflag = false;
+ if (element.getChildren() != null && element.getChildren().size() > 0) {
+ List<?> kids = element.getChildren();
+ for (Iterator<?> kidIter = kids.iterator(); kidIter.hasNext(); ) {
+ Element kid = (Element) kidIter.next();
+ if (kid.getName().equals("element")) { //$NON-NLS-1$
+ rtnflag = true;
+ }
+ boolean kidflag = elementHasChildren(kid);
+ if (kidflag)
+ rtnflag = true;
+ }
+ }
+ return rtnflag;
+ }
+
+ private static String createXMLForJDOMElement2 ( org.jdom.Element schemaElement,
org.jdom.Element element ) {
+ StringBuffer buf = new StringBuffer();
+ String nstypename = null;
+
+ String tns = null;
+ String tnsprefix = null;
+ if (schemaElement.getNamespace("tns") != null) {//$NON-NLS-1$
+ tns = schemaElement.getNamespace("tns").getURI();//$NON-NLS-1$
+ tnsprefix = makePrefixFromURI(tns);
+ }
+
+ boolean isQualified = false;
+
+ if (element.getAttribute("name") != null) {//$NON-NLS-1$
+ nstypename = element.getAttributeValue("name");//$NON-NLS-1$
+ }
+ if (element.getAttribute("type") != null) {//$NON-NLS-1$
+ String type2FindName = element.getAttributeValue("type");//$NON-NLS-1$
+ if (type2FindName.indexOf(':') > -1) {
+ if (!(type2FindName.startsWith("xs:") ||
type2FindName.startsWith("xsd:"))) //$NON-NLS-1$ //$NON-NLS-2$
+ isQualified = true;
+ }
+ org.jdom.Element element2 = findJDOMTypeInSchema(schemaElement, type2FindName);
+ if (element2 != null) {
+ element = element2;
+ if (element.getParentElement() != null) {
+ org.jdom.Element parent = element.getParentElement();
+ if (parent.getNamespace("tns") != null) {//$NON-NLS-1$
+ tns = parent.getNamespace("tns").getURI();//$NON-NLS-1$
+ tnsprefix = makePrefixFromURI(tns);
+ }
+ }
+ }
+ }
+ if (element.getAttribute("ref") != null) {//$NON-NLS-1$
+ String ref2FindName = element.getAttributeValue("ref");//$NON-NLS-1$
+ if (ref2FindName.indexOf(':') > -1) {
+ if (!(ref2FindName.startsWith("xs:") ||
ref2FindName.startsWith("xsd:"))) //$NON-NLS-1$ //$NON-NLS-2$
+ isQualified = true;
+ }
+ org.jdom.Element element2 = findJDOMTypeInSchema(schemaElement, ref2FindName);
+ if (element2 != null) {
+ element = element2;
+ if (element.getParentElement() != null) {
+ org.jdom.Element parent = element.getParentElement();
+ if (parent.getNamespace("tns") != null) {//$NON-NLS-1$
+ tns = parent.getNamespace("tns").getURI();//$NON-NLS-1$
+ tnsprefix = makePrefixFromURI(tns);
+ }
+ }
+ } else {
+ element2 = findJDOMElementInSchema(schemaElement, ref2FindName);
+ if (element2 != null) {
+ element = element2;
+ if (element.getParentElement() != null) {
+ org.jdom.Element parent = element.getParentElement();
+ if (parent.getNamespace("tns") != null) {//$NON-NLS-1$
+ tns = parent.getNamespace("tns").getURI();//$NON-NLS-1$
+ tnsprefix = makePrefixFromURI(tns);
+ }
+ }
+ }
+ }
+ }
+ Integer minOccurs = 1;
+ String elemType = null;
+
+ if (element.getAttributes().size() > 0) {
+ if (element.getAttribute("minOccurs") != null) {//$NON-NLS-1$
+ String value = element.getAttributeValue("minOccurs");//$NON-NLS-1$
+ minOccurs = Integer.decode(value);
+ }
+ if (element.getAttribute("type") != null) {//$NON-NLS-1$
+ elemType = element.getAttributeValue("type");//$NON-NLS-1$
+ String nsprefix = elemType.substring(0, elemType.indexOf(':'));
+ String testUri = getURIfromSchemaPrefix(element, nsprefix);
+ if (elemType.indexOf(':') > -1) {
+ if (!(elemType.startsWith("xs:") ||
elemType.startsWith("xsd:"))){ //$NON-NLS-1$ //$NON-NLS-2$
+ isQualified = true;
+ }
+ }
+ XSDSchema importXSD = getSchemaForNamespace(testUri);
+ if (importXSD != null) {
+ DOMBuilder domBuilder = new DOMBuilder();
+ importXSD.updateElement(true);
+ org.jdom.Element importXSDSchema = domBuilder.build(importXSD.getElement());
+ org.jdom.Element element2 = findJDOMTypeInSchema(importXSDSchema, elemType);
+ if (element2 != null) {
+ element = element2;
+ } else {
+ element2 = findJDOMElementInSchema(importXSDSchema, elemType);
+ if (element2 != null) {
+ element = element2;
+ }
+ }
+ }
+ }
+ if (element.getAttribute("ref") != null) {//$NON-NLS-1$
+ elemType = element.getAttributeValue("ref");//$NON-NLS-1$
+ String nsprefix = elemType.substring(0, elemType.indexOf(':'));
+ String typename = elemType.substring(elemType.indexOf(':') + 1,
elemType.length());
+ nstypename = typename;
+
+ String testUri = getURIfromSchemaPrefix(element, nsprefix);
+ if (elemType.indexOf(':') > -1) {
+ if (!elemType.startsWith("xs:")) { //$NON-NLS-1$
+ isQualified = true;
+ tns = testUri;
+ tnsprefix = makePrefixFromURI(tns);
+ }
+ }
+ XSDSchema importXSD = getSchemaForNamespace(testUri);
+ if (importXSD != null) {
+ DOMBuilder domBuilder = new DOMBuilder();
+ importXSD.updateElement(true);
+ org.jdom.Element importXSDSchema = domBuilder.build(importXSD.getElement());
+ org.jdom.Element element2 = findJDOMTypeInSchema(importXSDSchema, elemType);
+ if (element2 != null) {
+ element = element2;
+ } else {
+ element2 = findJDOMElementInSchema(importXSDSchema, elemType);
+ if (element2 != null) {
+ element = element2;
+ } else {
+ element2 = findJDOMElementInSchemaByName(importXSDSchema, nstypename);
+ if (element2 != null) {
+ element = element2;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ boolean hasKids = false;
+ if (elementHasChildren(element)) {
+ hasKids = true;
+ }
+
+ boolean isSimpleType = false;
+ if (elemType != null && isTypeBaseXSDOrSimple(tns, elemType)) {
+ isSimpleType = true;
+ }
+
+ boolean includeTNSInRoot = false;
+ if (rootIsQualified_ && !isQualified) {
+ includeTNSInRoot = true;
+ isQualified = true;
+ tnsprefix = "tns"; //$NON-NLS-1$
+ } else if (isQualified) {
+ rootIsQualified_ = false;
+ }
+
+ boolean isSequence = element.getName().equals("sequence"); //$NON-NLS-1$
+ if (!isSequence) {
+ // open tag
+ if (minOccurs.intValue() == 0) {
+ buf.append("<!-- optional -->\n");//$NON-NLS-1$
+ }
+ buf.append('<');
+ if (isQualified) {
+ buf.append(tnsprefix + ':');
+ }
+
+ buf.append(nstypename);
+ String attributes = handleAttributes(element);
+ if (attributes != null && attributes.trim().length() > 0) {
+ buf.append(' ');
+ buf.append(attributes);
+ }
+
+ if (isQualified) {
+ //
xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
+ if (includeTNSInRoot && !namespacePrefixListContainsURI(rootURI_)) {
+ buf.append(" xmlns:tns=\"" + rootURI_ + "\"");
//$NON-NLS-1$ //$NON-NLS-2$
+ namespacesAndPrefixes_.put(tnsprefix, rootURI_);
+ }
+ else if (!namespacesAndPrefixes_.containsKey(tnsprefix)) {
+ buf.append(" xmlns:" + tnsprefix + "=\"" + tns +
"\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ namespacesAndPrefixes_.put(tnsprefix, tns);
+ }
+ }
+
+
+ if (hasKids || isSimpleType)
+ buf.append(">"); //$NON-NLS-1$
+ else
+ buf.append("/>");//$NON-NLS-1$
+ }
+
+ if (hasKids) {
+ if (!isSequence) {
+ buf.append('\n');
+ }
+ List<?> kids = element.getChildren();
+ for (Iterator<?> kidIter = kids.iterator(); kidIter.hasNext(); ) {
+ Element kid = (Element) kidIter.next();
+ if (kid.getName().equals("complexType") ||
kid.getName().equals("sequence")) {//$NON-NLS-1$//$NON-NLS-2$
+ List<?> innerkids = kid.getChildren();
+ for (Iterator<?> kidIter2 = innerkids.iterator(); kidIter2.hasNext(); ) {
+ Element innerkid = (Element) kidIter2.next();
+ String out = createXMLForJDOMElement2 ( schemaElement, innerkid );
+ buf.append(out);
+ }
+ } else if (kid.getName().equals("element")) {//$NON-NLS-1$
+ String out = createXMLForJDOMElement2 (schemaElement, kid);
+ buf.append(out);
+ }
+ }
+ }
+
+ if (!isSequence && ( hasKids || isSimpleType )) {
+ // add ? for value
+ if (!hasKids || isSimpleType)
+ buf.append('?');
+
+ // close tag
+ buf.append("</");//$NON-NLS-1$
+
+ if (isQualified) {
+ buf.append(tnsprefix + ':');
+ }
+ buf.append(nstypename);
+ buf.append(">\n"); //$NON-NLS-1$
+ }
+
+ return buf.toString();
+ }
+
+ private static HashMap<String, String> getDefinitionNamespaces ( Definition
wsdlDefinition) {
+ HashMap<String, String> namespaceMap = new HashMap<String, String>();
+ namespaceMap.put(SOAP_NS_URI, SOAP_PREFIX);
+ namespaceMap.put(SOAP12_ENVELOPE_NS_URI, SOAP12_PREFIX);
+
namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance",
"xsi"); //$NON-NLS-1$//$NON-NLS-2$
+
namespaceMap.put("http://www.w3.org/2001/XMLSchema", "xsd");
//$NON-NLS-1$//$NON-NLS-2$
+
+ Map<?,?> namespaces = wsdlDefinition.getNamespaces();
+ Set<?> namespaceKeys = namespaces.keySet();
+ int i = 1;
+ for ( Iterator<?> it = namespaceKeys.iterator(); it.hasNext(); ) {
+ String prefix = (String) it.next();
+ String url = wsdlDefinition.getNamespace(prefix);
+ if (!namespaceMap.containsKey(url)) {
+ String newprefix = "ns" + i++; //$NON-NLS-1$
+ namespaceMap.put(url, newprefix);
+ }
+ }
+ return namespaceMap;
+ }
+
+ private static String getNSURI ( String inPrefix, Definition wsdlDefinition) {
+ HashMap<String, String> map = getDefinitionNamespaces(wsdlDefinition);
+ if (map.containsValue(inPrefix)) {
+ for (Iterator<Entry<String, String>> mapIter = map.entrySet().iterator();
mapIter.hasNext(); ) {
+ Map.Entry<String, String> test = (Entry<String, String>) mapIter.next();
+ if (test.getValue().equals(inPrefix))
+ return test.getKey();
+ }
+ }
+ return null;
+ }
+
+
+
+ private static String getURIfromSchemaPrefix(Element el, String prefix) {
+ Element e = el;
+ while (e.getParentElement() != null) {
+ e = e.getParentElement();
+ }
+ if (e.getNamespace(prefix) != null) {
+ return e.getNamespace(prefix).getURI();
+ }
+ return null;
+ }
+
+ private static boolean isTypeBaseXSDOrSimple ( String uri, String type ) {
+
+ if (uri != null) {
+ XSDSchema schema = getSchemaForNamespace(uri);
+ DOMBuilder domBuilder = new DOMBuilder();
+ schema.updateElement(true);
+ org.jdom.Element importXSDSchema = domBuilder.build(schema.getElement());
+ if (type.indexOf(':') > -1) {
+ String typename = type.substring(type.indexOf(':') + 1, type.length());
+ org.jdom.Element element = findJDOMTypeInSchemaByNameAttr(importXSDSchema,
typename);
+ if (element != null) {
+ if (element.getAttribute("type") != null) { //$NON-NLS-1$
+ type = element.getAttributeValue("type"); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ // typically the type starts with a namespace prefix, so
+ // we want to compare the end of the string with the actual
+ // type name
+ if (type.endsWith(STRING_TYPE_NAME) ||
+ type.endsWith(BOOLEAN_TYPE_NAME) ||
+ type.endsWith(DECIMAL_TYPE_NAME) ||
+ type.endsWith(INT_TYPE_NAME) ||
+ type.endsWith(DOUBLE_TYPE_NAME) ||
+ type.endsWith(FLOAT_TYPE_NAME) ||
+ type.endsWith(DURATION_TYPE_NAME) ||
+ type.endsWith(DATE_TYPE_NAME) ||
+ type.endsWith(TIME_TYPE_NAME) ||
+ type.endsWith(DATETIME_TYPE_NAME) ||
+ type.endsWith(ANYURI_TYPE_NAME) ||
+ type.endsWith(BASE64BINARY_TYPE_NAME) ||
+ type.endsWith(GDAY_TYPE_NAME) ||
+ type.endsWith(GMONTH_TYPE_NAME) ||
+ type.endsWith(GMONTHDAY_TYPE_NAME) ||
+ type.endsWith(GYEAR_TYPE_NAME) ||
+ type.endsWith(GYEARMONTH_TYPE_NAME) ||
+ type.endsWith(HEXBINARY_TYPE_NAME) ||
+ type.endsWith(NOTATION_TYPE_NAME) ||
+ type.endsWith(PRECISION_DECIMAL_TYPE_NAME)
+ ) {
+ return true;
+ } else if (type.contains(SIMPLE_TYPE_NAME)) {
+ return true;
+ }
+ return false;
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/SchemaUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
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 2011-05-10
16:55:18 UTC (rev 31191)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/TesterWSDLUtils.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 Red Hat, Inc.
+ * Copyright (c) 2011 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,
@@ -15,29 +15,21 @@
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.ExtensibilityElement;
-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;
@@ -46,51 +38,19 @@
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
-//import org.jdom.Attribute;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.jboss.tools.ws.core.utils.StatusUtils;
import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
-import org.jdom.Namespace;
-import org.jdom.input.DOMBuilder;
import com.ibm.wsdl.Constants;
/**
+ * Cleaned up and separated WSDL from Schema utilities
* @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 DOUBLE_TYPE_NAME = "double"; //$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 BOOLEAN_TYPE_NAME = "boolean"; //$NON-NLS-1$
- private static final String DECIMAL_TYPE_NAME = "decimal"; //$NON-NLS-1$
- private static final String PRECISION_DECIMAL_TYPE_NAME = "precisionDecimal";
//$NON-NLS-1$
- private static final String FLOAT_TYPE_NAME = "float"; //$NON-NLS-1$
- private static final String DURATION_TYPE_NAME = "duration"; //$NON-NLS-1$
- private static final String DATETIME_TYPE_NAME = "dateTime"; //$NON-NLS-1$
- private static final String DATE_TYPE_NAME = "date"; //$NON-NLS-1$
- private static final String TIME_TYPE_NAME = "time"; //$NON-NLS-1$
- private static final String GYEARMONTH_TYPE_NAME = "gYearMonth";
//$NON-NLS-1$
- private static final String GYEAR_TYPE_NAME = "gYear"; //$NON-NLS-1$
- private static final String GMONTHDAY_TYPE_NAME = "gMonthDay"; //$NON-NLS-1$
- private static final String GDAY_TYPE_NAME = "gDay"; //$NON-NLS-1$
- private static final String GMONTH_TYPE_NAME = "gMonth"; //$NON-NLS-1$
- private static final String HEXBINARY_TYPE_NAME = "hexBinary"; //$NON-NLS-1$
- private static final String BASE64BINARY_TYPE_NAME = "base64Binary";
//$NON-NLS-1$
- private static final String ANYURI_TYPE_NAME = "anyURI"; //$NON-NLS-1$
- private static final String NOTATION_TYPE_NAME = "NOTATION"; //$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$
@@ -210,77 +170,6 @@
return false;
}
- 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();
- String ns = portType.getQName().getNamespaceURI();
- 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();
- StringBuffer buf = new StringBuffer();
- if (parts.size() > 1) {
- buf.append('<' + operation.getName());
- buf.append(" xmlns = \"" + ns + "\"");
//$NON-NLS-1$ //$NON-NLS-2$
- buf.append(">\n"); //$NON-NLS-1$
- }
- 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();
- }
- if (parts.size() > 1) {
- if (part != null && part.getTypeName() != null &&
!part.getTypeName().getNamespaceURI().
-
equalsIgnoreCase("http://www.w3.org/2001/XMLSchema")) {
//$NON-NLS-1$
- buf.append(createMessageForSchemaElement(wsdlDefinition, part.getName(),
part.getTypeName().getLocalPart(), ns));
- } else {
- buf.append('<' + part.getName());
- // buf.append(" xmlns = \"" + ns + "\"");
//$NON-NLS-1$ //$NON-NLS-2$
- buf.append(">?"); //$NON-NLS-1$
- buf.append("</" + part.getName() +
">\n");//$NON-NLS-1$//$NON-NLS-2$
- }
- } else {
- String partName = part.getName();
- if (parts.size() == 1) partName = null;
- String out = createMessageForSchemaElement(wsdlDefinition, partName,
schemaName, ns);
- if (out == null) {
- StringBuffer tempBuffer = new StringBuffer();
- tempBuffer.append('<' + part.getName());
- // tempBuffer.append(" xmlns = \"" + ns + "\"");
//$NON-NLS-1$ //$NON-NLS-2$
- tempBuffer.append(">?"); //$NON-NLS-1$
- tempBuffer.append("</" + part.getName() +
">\n");//$NON-NLS-1$//$NON-NLS-2$
- out = tempBuffer.toString();
- }
- return out;
- }
- }
- return buf.toString();
- }
- }
- }
- }
- }
- }
- return null;
- }
-
public static String[] getNSServiceNameAndMessageNameArray (Definition wsdlDefinition,
String serviceName, String portName, String bindingName, String opName ) {
Map<?, ?> services = wsdlDefinition.getServices();
Set<?> serviceKeys = services.keySet();
@@ -380,421 +269,6 @@
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 partName, String messageName, String namespace ) {
- 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();
- if (schemaImport.getReferencedSchema() != null) {
- 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 != null && rootName.equalsIgnoreCase(messageName)) {
- StringBuffer buf = new StringBuffer();
- buf.append('<' + rootName);
- buf.append(" xmlns = \"" + namespace + "\"");
//$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)) {
- if (temp.getParentElement().getAdditionalNamespaces() != null &&
temp.getParentElement().getAdditionalNamespaces().size() > 0) {
- @SuppressWarnings("unchecked")
- List<Namespace> addlNamespaces =
temp.getParentElement().getAdditionalNamespaces();
- for (int j = 0; j < addlNamespaces.size(); j++) {
- Namespace addlNS = addlNamespaces.get(j);
- if (addlNS.getPrefix().equalsIgnoreCase("tns")) { //$NON-NLS-1$
- if (!addlNS.getURI().equalsIgnoreCase(namespace)) {
- namespace = addlNS.getURI();
- break;
- }
- }
- }
- }
-
- StringBuffer buf = new StringBuffer();
- buf.append('<');
- if (partName != null) {
- buf.append(partName);
- }
- else {
- buf.append(rootName);
- buf.append(" xmlns = \"" + namespace + "\"");
//$NON-NLS-1$ //$NON-NLS-2$
- }
- buf.append(">\n"); //$NON-NLS-1$
- if (temp.getChildren().isEmpty()) {
- String nstemp = namespace;
- String typeName = temp.getAttributeValue(TYPE_ATTR);
- String prefix = null;
- if (typeName.indexOf(':') > 0) {
- prefix = typeName.substring(0, typeName.indexOf(':'));
- nstemp = temp.getNamespace(prefix).getURI();
- typeName = typeName.substring(typeName.indexOf(':') + 1,
typeName.length());
- }
- temp = getNodeFromSchema(temp.getParentElement(), typeName, nstemp, prefix);
- }
- if (temp != null && !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("</");//$NON-NLS-1$
- if (partName != null)
- buf.append(partName);
- else
- buf.append(rootName);
- buf.append(">\n");//$NON-NLS-1$
- return buf.toString();
- } else {
- Message msg = wsdlDefinition.getMessage(new QName(namespace, messageName));
- if (msg != null) {
- StringBuffer buf = new StringBuffer();
- buf.append('<');
- if (partName != null)
- buf.append(partName);
- else
- buf.append(rootName);
- buf.append(" xmlns = \"" + namespace + "\"");
//$NON-NLS-1$ //$NON-NLS-2$
- buf.append(">?"); //$NON-NLS-1$
- buf.append("</");//$NON-NLS-1$
- if (partName != null)
- buf.append(partName);
- else
- buf.append(rootName);
- buf.append(">\n");//$NON-NLS-1$
- return buf.toString();
- }
- }
- }
- }
- }
- }
- return null;
- }
-
- private static org.jdom.Element getNodeFromSchema ( org.jdom.Element root, String name,
String ns, String prefix) {
- if (root != null) {
- List<?> childList = root.getChildren();
- Iterator<?> iter1 = childList.iterator();
- while (iter1.hasNext()) {
- Object test = iter1.next();
- if (test instanceof org.jdom.Element) {
- org.jdom.Element childEl = (org.jdom.Element) test;
- if (childEl.getAttributeValue(NAME_ATTR, ns).equalsIgnoreCase(name)) {
- String typeName = childEl.getAttributeValue(TYPE_ATTR);
- if (typeName == null || !typeName.equalsIgnoreCase(prefix + ':' + name))
- return childEl;
- }
- }
- }
- }
- 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 boolean isTypeBaseXSDOrSimple ( String type ) {
- // typically the type starts with a namespace prefix, so
- // we want to compare the end of the string with the actual
- // type name
- if (type.endsWith(STRING_TYPE_NAME) ||
- type.endsWith(BOOLEAN_TYPE_NAME) ||
- type.endsWith(DECIMAL_TYPE_NAME) ||
- type.endsWith(INT_TYPE_NAME) ||
- type.endsWith(DOUBLE_TYPE_NAME) ||
- type.endsWith(FLOAT_TYPE_NAME) ||
- type.endsWith(DURATION_TYPE_NAME) ||
- type.endsWith(DATE_TYPE_NAME) ||
- type.endsWith(TIME_TYPE_NAME) ||
- type.endsWith(DATETIME_TYPE_NAME) ||
- type.endsWith(ANYURI_TYPE_NAME) ||
- type.endsWith(BASE64BINARY_TYPE_NAME) ||
- type.endsWith(GDAY_TYPE_NAME) ||
- type.endsWith(GMONTH_TYPE_NAME) ||
- type.endsWith(GMONTHDAY_TYPE_NAME) ||
- type.endsWith(GYEAR_TYPE_NAME) ||
- type.endsWith(GYEARMONTH_TYPE_NAME) ||
- type.endsWith(HEXBINARY_TYPE_NAME) ||
- type.endsWith(NOTATION_TYPE_NAME) ||
- type.endsWith(PRECISION_DECIMAL_TYPE_NAME)
- ) {
- return true;
- } else if (type.contains(SIMPLE_TYPE_NAME)) {
- return true;
- }
- return false;
- }
-
- private static String processType (Definition wsdlDefinition, org.jdom.Element childEl,
String type, boolean isOptional) {
- StringBuffer buf = new StringBuffer();
- if (isTypeBaseXSDOrSimple(type)) {
- buf.append("?"); //$NON-NLS-1$
- } 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
partName, String messageName, String namespace ) {
- Types types = wsdlDefinition.getTypes();
- if (types == null || wsdlDefinition.getImports().size() > 0) {
- 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();
-// namespace = importInstance.getNamespaceURI();
- if (importInstance.getDefinition().getTypes() != null) {
- Types temptypes = importInstance.getDefinition().getTypes();
- String attempt = createMessageForSchemaElementFromTypes(wsdlDefinition, temptypes,
partName, messageName, namespace);
- if (attempt != null)
- return attempt;
- } else if (importInstance.getDefinition().getImports() != null) {
- String attempt = createMessageForSchemaElement(importInstance.getDefinition(),
partName, messageName, namespace);
- if (attempt != null)
- return attempt;
- }
- }
- }
- // if we got this far, it wasn't found in the imports
- String attempt = createMessageForSchemaElementFromTypes(wsdlDefinition, types,
partName, messageName, namespace);
- if (attempt != null)
- return attempt;
- } else {
- String attempt = createMessageForSchemaElementFromTypes(wsdlDefinition, types,
partName, messageName, namespace);
- if (attempt != null)
- return attempt;
- }
- return null;
- }
-
public static String getFileContents (URL inURL){
try {
BufferedReader in = new BufferedReader(
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URIEncoder.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URIEncoder.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URIEncoder.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - Initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *******************************************************************************/
+package org.jboss.tools.ws.ui.utils;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.BitSet;
+
+/**
+ * This class is a modified version of java.lang.URLEncoder.
+ */
+public class URIEncoder
+{
+ static BitSet dontNeedEncoding;
+ static final int caseDiff = ('a' - 'A');
+ static String dfltEncName = null;
+
+
+ static
+ {
+ dontNeedEncoding = new BitSet(256);
+ int i;
+ for (i = 'a'; i <= 'z'; i++)
+ {
+ dontNeedEncoding.set(i);
+ }
+ for (i = 'A'; i <= 'Z'; i++)
+ {
+ dontNeedEncoding.set(i);
+ }
+ for (i = '0'; i <= '9'; i++)
+ {
+ dontNeedEncoding.set(i);
+ }
+
+ //dontNeedEncoding.set(' '); // cs.. removed so that space character will be
replaced by %20
+ dontNeedEncoding.set('-');
+ dontNeedEncoding.set('_');
+ dontNeedEncoding.set('.');
+ dontNeedEncoding.set('*');
+ dontNeedEncoding.set(':'); // cs.. added
+ dontNeedEncoding.set('/'); // cs.. added so that slashes don't get
encoded as %2F
+
+ // dfltEncName = (String)AccessController.doPrivileged(new
GetPropertyAction("file.encoding"));
+ // As discussed with Sandy, we should encode URIs with UTF8
+ dfltEncName = "UTF8"; //$NON-NLS-1$
+ //System.out.println("dfltEncName " + dfltEncName);
+ }
+
+ /**
+ * You can't call the constructor.
+ */
+ private URIEncoder() { }
+
+ /**
+ * Translates a string into <code>x-www-form-urlencoded</code>
+ * format. This method uses the platform's default encoding
+ * as the encoding scheme to obtain the bytes for unsafe characters.
+ *
+ * @param s <code>String</code> to be translated.
+ * @deprecated The resulting string may vary depending on the platform's
+ * default encoding. Instead, use the encode(String,String)
+ * method to specify the encoding.
+ * @return the translated <code>String</code>.
+ */
+ public static String encode(String s)
+ {
+ String str = null;
+ try
+ {
+ str = encode(s, dfltEncName);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // The system should always have the platform default
+ }
+ return str;
+ }
+
+ /**
+ * Translates a string into <code>application/x-www-form-urlencoded</code>
+ * format using a specific encoding scheme. This method uses the
+ * supplied encoding scheme to obtain the bytes for unsafe
+ * characters.
+ * <p>
+ * <em><strong>Note:</strong> The <a href=
+ * "http://www.w3.org/TR/html40/appendix/notes.html#non-ascii-chars">
+ * World Wide Web Consortium Recommendation</a> states that
+ * UTF-8 should be used. Not doing so may introduce
+ * incompatibilites.</em>
+ *
+ * @param s <code>String</code> to be translated.
+ * @param enc The name of a supported
+ * <a href="../lang/package-summary.html#charenc">character
+ * encoding</a>.
+ * @return the translated <code>String</code>.
+ * @exception UnsupportedEncodingException
+ * If the named encoding is not supported
+ * @see java.net.URLDecoder#decode(java.lang.String, java.lang.String)
+ */
+ public static String encode(String s, String enc) throws UnsupportedEncodingException
+ {
+ boolean needToChange = false;
+ boolean wroteUnencodedChar = false;
+ int maxBytesPerChar = 10; // rather arbitrary limit, but safe for now
+ StringBuffer out = new StringBuffer(s.length());
+ ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buf, enc));
+
+ for (int i = 0; i < s.length(); i++)
+ {
+ int c = s.charAt(i);
+ //System.out.println("Examining character: " + c);
+ if (dontNeedEncoding.get(c))
+ {
+ //if (c == ' ')
+ //{
+ // c = '+';
+ // needToChange = true;
+ //}
+ //System.out.println("Storing: " + c);
+ out.append((char)c);
+ wroteUnencodedChar = true;
+ }
+ else
+ {
+ // convert to external encoding before hex conversion
+ try
+ {
+ if (wroteUnencodedChar)
+ { // Fix for 4407610
+ writer = new BufferedWriter(new OutputStreamWriter(buf, enc));
+ wroteUnencodedChar = false;
+ }
+ writer.write(c);
+
+ // If this character represents the start of a Unicode
+ // surrogate pair, then pass in two characters. It's not
+ // clear what should be done if a bytes reserved in the
+ // surrogate pairs range occurs outside of a legal
+ // surrogate pair. For now, just treat it as if it were
+ // any other character.
+ //
+ if (c >= 0xD800 && c <= 0xDBFF)
+ {
+ // System.out.println(Integer.toHexString(c) + " is high
surrogate");
+ if ( (i+1) < s.length())
+ {
+ int d = s.charAt(i+1);
+ // System.out.println("\tExamining " + Integer.toHexString(d));
+ if (d >= 0xDC00 && d <= 0xDFFF)
+ {
+ // System.out.println("\t" + Integer.toHexString(d) + " is low
surrogate");
+ writer.write(d);
+ i++;
+ }
+ }
+ }
+ writer.flush();
+ }
+ catch(IOException e)
+ {
+ buf.reset();
+ continue;
+ }
+ byte[] ba = buf.toByteArray();
+
+ for (int j = 0; j < ba.length; j++)
+ {
+ out.append('%');
+ char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16);
+ // converting to use uppercase letter as part of
+ // the hex value if ch is a letter.
+ if (Character.isLetter(ch))
+ {
+ ch -= caseDiff;
+ }
+ out.append(ch);
+ ch = Character.forDigit(ba[j] & 0xF, 16);
+ if (Character.isLetter(ch))
+ {
+ ch -= caseDiff;
+ }
+ out.append(ch);
+ }
+ buf.reset();
+ needToChange = true;
+ }
+ }
+ return (needToChange? out.toString() : s);
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URIEncoder.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URLUtils.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URLUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URLUtils.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ * yyyymmdd bug Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20081119 255374 mahutch(a)ca.ibm.com - Mark Hutchinson
+ *******************************************************************************/
+package org.jboss.tools.ws.ui.utils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
+/**
+ * This class contains utility methods for managing URLs
+ * as used by the Web Services Explorer Web application.
+ * @author cbrealey(a)ca.ibm.com
+ */
+public final class URLUtils
+{
+ /**
+ * Objects of this class should not be constructed.
+ */
+ private URLUtils ()
+ {
+ }
+
+ /**
+ * UTF-8
+ */
+ public static final String UTF8 = "UTF-8"; //$NON-NLS-1$
+
+ /**
+ * Equivalent to {@link #encode(String,String)}
+ * with second parameter set to the "UTF-8" encoding.
+ * @param s The string to encode.
+ * @return The encoded string.
+ */
+ public static String encode(String s)
+ {
+ return encode(s,UTF8);
+ }
+
+ /**
+ * Equivalent to {@link URLEncoder#encode(String,String)},
+ * only throws an unchecked {@link RuntimeException} wrapped
+ * around an {@link UnsupportedEncodingException} instead of
+ * an {@link UnsupportedEncodingException}.
+ * @param s The string to encode.
+ * @param enc The encoding to use.
+ * @return The encoded string.
+ */
+ public static String encode(String s, String enc)
+ {
+ try
+ {
+ return URLEncoder.encode(s,enc);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // TODO: MSG_BROKEN_VM_DOES_NOT_SUPPORT_UTF-8
+ throw new RuntimeException("%MSG_BROKEN_VM_DOES_NOT_SUPPORT_UTF-8",e);
//$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Equivalent to {@link #decode(String,String)}
+ * with second parameter set to the "UTF-8" encoding.
+ * @param s The string to decode.
+ * @return The decoded string.
+ */
+ public static String decode(String s)
+ {
+ return decode(s,UTF8);
+ }
+
+ /**
+ * Equivalent to {@link URLEncoder#decode(String,String)},
+ * only throws an unchecked {@link RuntimeException} wrapped
+ * around an {@link UnsupportedEncodingException} instead of
+ * an {@link UnsupportedEncodingException}.
+ * @param s The string to decode.
+ * @param enc The encoding to use.
+ * @return The decoded string.
+ */
+ public static String decode(String s, String enc)
+ {
+ try
+ {
+ return URLDecoder.decode(s,enc);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // TODO: MSG_BROKEN_VM_DOES_NOT_SUPPORT_UTF-8
+ throw new RuntimeException("%MSG_BROKEN_VM_DOES_NOT_SUPPORT_UTF-8",e);
//$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Encodes non-ASCII characters in a URL string.
+ * @param urlString The URL string to encode
+ * @return The URL as an encoded string
+ */
+ public static String encodeURLString(String urlString) {
+ try {
+ URI uri = new URI(urlString);
+ return uri.toASCIIString();
+ } catch (Exception e) {
+ //do nothing, we will just return the original string
+ }
+ return urlString;
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/URLUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/Validator.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/Validator.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/Validator.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ * yyyymmdd bug Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20060612 142290 gilberta(a)ca.ibm.com - Gilbert Andrews
+ *******************************************************************************/
+
+package org.jboss.tools.ws.ui.utils;
+
+public class Validator
+{
+ public static final boolean validateString(String input)
+ {
+ return ((input != null) && (input.trim().length() > 0));
+ }
+
+ public static final boolean validateURL(String input)
+ {
+ return (input != null && input.matches("[a-zA-Z\\+\\-\\.]++:.*"));
//$NON-NLS-1$
+ }
+
+ public static final boolean validateInteger(String input)
+ {
+ try
+ {
+ Integer.parseInt(input);
+ return true;
+ }
+ catch (NumberFormatException e)
+ {
+ return false;
+ }
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/Validator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSDLPartsToXSDTypeMapper.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSDLPartsToXSDTypeMapper.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSDLPartsToXSDTypeMapper.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2002, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.ws.ui.utils;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Vector;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+import org.eclipse.xsd.XSDComponent;
+import org.eclipse.xsd.XSDElementDeclaration;
+import org.eclipse.xsd.XSDModelGroupDefinition;
+import org.eclipse.xsd.XSDNamedComponent;
+import org.eclipse.xsd.XSDSchema;
+import org.eclipse.xsd.XSDTypeDefinition;
+
+public class WSDLPartsToXSDTypeMapper
+{
+ private final char POUND = '#';
+ private Vector<Object> xsdSchemaList_;
+ private Hashtable<String, XSDNamedComponent> partToXSDCache_;
+
+ public WSDLPartsToXSDTypeMapper() {
+ xsdSchemaList_ = new Vector<Object>();
+ partToXSDCache_ = new Hashtable<String, XSDNamedComponent>();
+ }
+
+ public void addSchemas(Vector<?> schemaList) {
+ for (int i=0;i<schemaList.size();i++) {
+ Object schema = schemaList.elementAt(i);
+ if (schema != null)
+ xsdSchemaList_.addElement(schema);
+ }
+ }
+
+ public XSDNamedComponent getXSDType(Part part, String id) {
+ XSDNamedComponent component = getXSDTypeFromCache(id);
+ if (component != null)
+ return component;
+ component = getXSDTypeFromSchema(part);
+ if (component != null)
+ addToCache(id, component);
+ return component;
+ }
+
+ public XSDNamedComponent getXSDTypeFromCache(String id) {
+ return (XSDNamedComponent)partToXSDCache_.get(id);
+ }
+
+ public XSDNamedComponent getXSDTypeFromSchema(Part part) {
+ boolean isElementDeclaration = (part.getTypeName() == null);
+ QName qName = isElementDeclaration ? part.getElementName() : part.getTypeName();
+ return getXSDTypeFromSchema(qName.getNamespaceURI(), qName.getLocalPart(),
isElementDeclaration);
+ }
+
+ public XSDNamedComponent getXSDTypeFromSchema(String namespaceURI, String localName,
boolean isElementDeclaration) {
+ for (int i = 0; i < xsdSchemaList_.size(); i++) {
+ XSDSchema xsdSchema = (XSDSchema)xsdSchemaList_.elementAt(i);
+ Vector<Object> components = new Vector<Object>();
+ if (isElementDeclaration)
+ components.addAll(xsdSchema.getElementDeclarations());
+ else
+ components.addAll(xsdSchema.getTypeDefinitions());
+ for (Iterator<Object> it = components.iterator(); it.hasNext(); ) {
+ XSDNamedComponent component = (XSDNamedComponent)it.next();
+ String compNSURI = component.getTargetNamespace();
+ String compLocalname = component.getName();
+ if (compNSURI != null && compLocalname != null &&
compNSURI.equals(namespaceURI) && compLocalname.equals(localName))
+ return component;
+ }
+ }
+ return null;
+ }
+
+ public XSDNamedComponent resolveXSDNamedComponent(XSDNamedComponent component)
+ {
+ if (component != null)
+ {
+ String uri = component.getURI();
+ String qname = component.getQName();
+ for (int i = 0; i < xsdSchemaList_.size(); i++)
+ {
+ XSDSchema xsdSchema = (XSDSchema)xsdSchemaList_.elementAt(i);
+ if (xsdSchema != null)
+ {
+ String targetNS = xsdSchema.getTargetNamespace();
+ if (targetNS != null && targetNS.equals(trimQName(uri, qname)))
+ {
+ XSDNamedComponent resolvedComponent = null;
+ if (component instanceof XSDTypeDefinition)
+ resolvedComponent = xsdSchema.resolveTypeDefinition(qname);
+ else if (component instanceof XSDElementDeclaration)
+ resolvedComponent = xsdSchema.resolveElementDeclaration(qname);
+ else if (component instanceof XSDModelGroupDefinition)
+ resolvedComponent = xsdSchema.resolveModelGroupDefinition(qname);
+ if (isComponentResolvable(resolvedComponent))
+ return resolvedComponent;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private String trimQName(String uri, String qname)
+ {
+ int index = uri.indexOf(qname);
+ if (index != -1)
+ {
+ String ns = uri.substring(0, index);
+ if (ns.charAt(index-1) == POUND)
+ return ns.substring(0, index-1);
+ else
+ return ns;
+ }
+ else
+ return uri;
+ }
+
+ private void addToCache(String id, XSDNamedComponent component) {
+ partToXSDCache_.put(id,component);
+ }
+
+ protected boolean isComponentResolvable(XSDComponent component)
+ {
+ if (component == null)
+ return false;
+ XSDSchema schema = component.getSchema();
+ if (schema == null)
+ return false;
+ if (schema.getTargetNamespace() == null)
+ return false;
+ return true;
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSDLPartsToXSDTypeMapper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/AddMonitorDialog.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/AddMonitorDialog.java 2011-05-10
16:55:18 UTC (rev 31191)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/AddMonitorDialog.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -1,18 +0,0 @@
-package org.jboss.tools.ws.ui.views;
-
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitorWorkingCopy;
-import org.eclipse.wst.internet.monitor.ui.internal.MonitorDialog;
-
-@SuppressWarnings("restriction")
-public class AddMonitorDialog extends MonitorDialog {
-
- public AddMonitorDialog(Shell parentShell) {
- super(parentShell);
- }
-
- public IMonitorWorkingCopy getMonitor() {
- return this.monitor;
- }
-
-}
Deleted:
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 2011-05-10
16:55:18 UTC (rev 31191)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -1,1071 +0,0 @@
-/*******************************************************************************
- * 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.net.MalformedURLException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map.Entry;
-
-import javax.wsdl.Definition;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-
-import org.apache.axis.utils.XMLUtils;
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.IJobChangeListener;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.FillLayout;
-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.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.TabFolder;
-import org.eclipse.swt.widgets.TabItem;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IStorageEditorInput;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.ViewPart;
-import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;
-import org.eclipse.wst.internet.monitor.core.internal.provisional.MonitorCore;
-import org.jboss.tools.ws.ui.JBossWSUIPlugin;
-import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
-import org.jboss.tools.ws.ui.utils.JAXRSTester;
-import org.jboss.tools.ws.ui.utils.JAXWSTester2;
-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.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * View for testing web services (JAX-WS & JAX-RS)
- * @author bfitzpat
- *
- */
-@SuppressWarnings("restriction")
-public class JAXRSWSTestView extends ViewPart {
-
- private static final String DEFAULT_TEXT_EDITOR_ID =
"org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
- private static final String XML_EDITOR_ID =
"org.eclipse.wst.xml.ui.internal.tabletree.XMLMultiPageEditorPart";
//$NON-NLS-1$
- private static final String TCPIP_VIEW_ID =
"org.eclipse.wst.internet.monitor.view";//$NON-NLS-1$
- private static final String DELETE = "DELETE";//$NON-NLS-1$
- private static final String PUT = "PUT";//$NON-NLS-1$
- private static final String POST = "POST";//$NON-NLS-1$
- private static final String GET = "GET";//$NON-NLS-1$
- private static final String JAX_WS = "JAX-WS"; //$NON-NLS-1$
- private static final String JAX_RS = "JAX-RS"; //$NON-NLS-1$
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
- private static final String RESULT_HEADER_DELIMITER = "%";//$NON-NLS-1$
-
- /**
- * The ID of the view as specified by the extension.
- */
- public static final String ID =
"org.jboss.tools.ws.ui.tester.views.TestWSView";//$NON-NLS-1$
-
- /* UI controls */
- private Button testButton = null;
- private Button wsdlButton = null;
- private Text actionText;
- private Text resultsText;
- private Combo urlCombo;
- private DelimitedStringList dlsList;
- private Combo methodCombo;
- private Combo wsTypeCombo;
- private Text bodyText;
- private TabFolder tabGroup;
- private TabItem bodyTab;
- private TabItem headerTab;
- private List resultHeadersList;
- private TabItem resultHeadersTab;
- private TabItem resultTab;
- private TabFolder resultTabGroup;
-
- private TabItem parmsTab;
-
- private DelimitedStringList parmsList;
- private Button openTCPIPMonitorButton;
- private Button addTCPIPMonitorButton;
-
- private SOAPEnvelope envelope;
- private SOAPBody soapbody;
- private MenuItem openInXMLEditorAction;
- private MenuItem openResponseTagInXMLEditor;
- private Menu resultsTextMenu;
- private MenuItem copyMenuAction;
- private Menu resultsHeaderMenu;
- private MenuItem copyResultHeaderMenuAction;
-
- private boolean showSampleButton = false;
- private String[] serviceNSMessage = null;
-
- /**
- * The constructor.
- */
- public JAXRSWSTestView() {
- }
-
- /**
- * This is a callback that will allow us
- * to create the viewer and initialize it.
- */
- public void createPartControl(Composite parent) {
-
- Composite innerComposite = new Composite (parent, SWT.NONE);
- innerComposite.setLayout(new FillLayout());
-
- SashForm sashForm = new SashForm(innerComposite, SWT.BORDER);
- sashForm.setOrientation(SWT.HORIZONTAL);
-
- Composite topHalf = new Composite (sashForm, SWT.NONE);
- topHalf.setLayout(new GridLayout(2, false));
-
- Label typeLabel = new Label(topHalf, SWT.NONE);
- typeLabel.setText(JBossWSUIMessages.JAXRSWSTestView_Web_Service_Type_Label);
- typeLabel.setLayoutData(new GridData());
-
- wsTypeCombo = new Combo(topHalf, SWT.DROP_DOWN | SWT.READ_ONLY);
- wsTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
- wsTypeCombo.add(JAX_WS);
- wsTypeCombo.add(JAX_RS);
- wsTypeCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- public void widgetSelected(SelectionEvent e) {
- setControlsForWSType(wsTypeCombo.getText());
- setControlsForMethodType(methodCombo.getText());
- setControlsForSelectedURL();
- }
- });
-
- Label methodLabel = new Label(topHalf, SWT.NONE);
- methodLabel.setText(JBossWSUIMessages.JAXRSWSTestView_HTTP_Method_Label);
- methodLabel.setLayoutData(new GridData());
-
- methodCombo = new Combo(topHalf, SWT.DROP_DOWN | SWT.READ_ONLY);
- methodCombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
- methodCombo.add(GET);
- methodCombo.add(POST);
- methodCombo.add(PUT);
- methodCombo.add(DELETE);
- methodCombo.setText(GET);
- methodCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- public void widgetSelected(SelectionEvent e) {
- setControlsForMethodType(methodCombo.getText());
- }
- });
-
- Label urlLabel = new Label(topHalf, SWT.NONE);
- urlLabel.setText(JBossWSUIMessages.JAXRSWSTestView_Service_URL_Label);
- urlLabel.setLayoutData(new GridData());
-
- urlCombo = new Combo(topHalf, SWT.BORDER | SWT.DROP_DOWN);
- urlCombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
- urlCombo.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- public void widgetSelected(SelectionEvent e) {
- setControlsForSelectedURL();
- }
- });
- urlCombo.addKeyListener(new KeyListener() {
- public void keyPressed(KeyEvent e) {
- }
-
- public void keyReleased(KeyEvent e) {
- setControlsForSelectedURL();
- if (e.keyCode == SWT.CR && e.stateMask == SWT.CTRL) {
- handleTest(wsTypeCombo.getText());
- }
- }
- });
-
- Label actionLabel = new Label(topHalf, SWT.NONE);
- actionLabel.setText(JBossWSUIMessages.JAXRSWSTestView_Action_URL_Label);
- actionLabel.setLayoutData(new GridData());
-
- actionText = new Text(topHalf, SWT.BORDER);
- actionText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
-
- tabGroup = new TabFolder(topHalf, SWT.BORDER);
-
- bodyTab = new TabItem(tabGroup, SWT.NONE, 0);
- bodyTab.setText(JBossWSUIMessages.JAXRSWSTestView_Request_Body_Label);
-
- parmsTab = new TabItem(tabGroup, SWT.NONE, 1);
- parmsTab.setText(JBossWSUIMessages.JAXRSWSTestView_Request_Parameters_Label);
-
- parmsList = new DelimitedStringList(tabGroup, SWT.None);
- parmsTab.setControl(parmsList);
- GridData parmsListGD = new GridData(SWT.FILL, SWT.FILL, true, true);
- parmsListGD.horizontalSpan = 2;
- parmsList.setLayoutData(parmsListGD);
-
- headerTab = new TabItem(tabGroup, SWT.NONE, 2);
- bodyText = new Text(tabGroup, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
- GridData btGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- bodyText.setLayoutData(btGridData);
- bodyTab.setControl(bodyText);
-
- headerTab.setText(JBossWSUIMessages.JAXRSWSTestView_Request_Header_Label);
- GridData hgGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- hgGridData.horizontalSpan = 2;
- tabGroup.setLayoutData(hgGridData);
-
- dlsList = new DelimitedStringList(tabGroup, SWT.None);
- headerTab.setControl(dlsList);
- GridData dlsListGD = new GridData(SWT.FILL, SWT.FILL, true, true);
- dlsListGD.horizontalSpan = 2;
- dlsList.setLayoutData(dlsListGD);
-
- Composite buttonBar = new Composite ( topHalf, SWT.NONE);
- GridData buttonBarGD = new GridData(SWT.FILL, SWT.NONE, true, false);
- buttonBarGD.horizontalSpan = 2;
- buttonBar.setLayoutData(buttonBarGD);
- buttonBar.setLayout(new RowLayout());
-
- testButton = new Button (buttonBar, SWT.PUSH);
- testButton.setText(JBossWSUIMessages.JAXRSWSTestView_Invoke_Label);
-
- testButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- handleTest(wsTypeCombo.getText());
- }
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- });
-
- 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){
- serviceNSMessage = null;
- 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());
- serviceNSMessage = TesterWSDLUtils.getNSServiceNameAndMessageNameArray(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);
-
- addTCPIPMonitorButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- configureMonitor();
- }
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- });
-
- openTCPIPMonitorButton = new Button(buttonBar, SWT.PUSH);
- openTCPIPMonitorButton.setText(JBossWSUIMessages.JAXRSWSTestView_Open_Monitor_Button);
-
- openTCPIPMonitorButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- openMonitor();
- }
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- });
-
- Button sampleButton = new Button(buttonBar, SWT.PUSH);
- sampleButton.setText(JBossWSUIMessages.JAXRSWSTestView_Set_Sample_Data_Label);
- sampleButton.setVisible(showSampleButton);
-
- sampleButton.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- setupSample();
- }
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- });
-
- Composite bottomHalf = new Composite (sashForm, SWT.NONE);
- bottomHalf.setLayout(new GridLayout(2, false));
-
- resultTabGroup = new TabFolder(bottomHalf, SWT.BORDER);
- GridData rtGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
- rtGridData.horizontalSpan = 2;
- resultTabGroup.setLayoutData(rtGridData);
-
- resultTab = new TabItem(resultTabGroup, SWT.NONE, 0);
- resultTab.setText(JBossWSUIMessages.JAXRSWSTestView_Results_Body_Label);
- resultsText = new Text(resultTabGroup, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP |
SWT.READ_ONLY );
- resultsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- resultsTextMenu = new Menu(resultsText.getShell(), SWT.POP_UP);
-
- copyMenuAction = new MenuItem(resultsTextMenu, SWT.PUSH);
- copyMenuAction.setText(JBossWSUIMessages.JAXRSWSTestView_CopyResultsMenu);
- copyMenuAction.setAccelerator(SWT.CTRL + 'C');
- copyMenuAction.addSelectionListener(new SelectionListener(){
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
- if (resultsText.getSelectionCount() == 0)
- resultsText.selectAll();
- resultsText.copy();
- }
-
- public void widgetSelected(SelectionEvent arg0) {
- widgetDefaultSelected(arg0);
- }
- });
- new MenuItem(resultsTextMenu, SWT.SEPARATOR);
-
- openInXMLEditorAction = new MenuItem(resultsTextMenu, SWT.PUSH);
- openInXMLEditorAction.setText(JBossWSUIMessages.JAXRSWSTestView_Open_Result_in_XML_Editor);
- openInXMLEditorAction.setAccelerator(SWT.CTRL + 'O');
- openInXMLEditorAction.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent arg0) {
- String string = resultsText.getText();
- openXMLEditor(string);
- }
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
- widgetSelected(arg0);
- }
- });
-
- openResponseTagInXMLEditor = new MenuItem(resultsTextMenu, SWT.PUSH);
- openResponseTagInXMLEditor.setText(JBossWSUIMessages.JAXRSWSTestView_Open_Response_Tag_Contents_in_XML_Editor);
- openResponseTagInXMLEditor.setAccelerator(SWT.CTRL + 'R');
- openResponseTagInXMLEditor.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent arg0) {
- String string = null;
- try {
- SOAPBody body = null;
- if (envelope != null){
- body = envelope.getBody();
- } else if (soapbody != null) {
- body = soapbody;
- }
-
- NodeList list = body.getChildNodes();
- for (int i = 0; i< list.getLength(); i++){
- Node node = list.item(i);
- if (node.getNodeName().contains("Response")){ //$NON-NLS-1$
- NodeList list2 = node.getChildNodes();
- for (int j = 0; j<list2.getLength(); j++){
- Node node2 = list2.item(j);
- if (node2.getNodeName().contains("Result")){ //$NON-NLS-1$
- Node node3 = node2.getChildNodes().item(0);
- if (node3.getNodeType() == Node.TEXT_NODE) {
- string = node3.getNodeValue();
- break;
- } else if (node3.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element) node3;
- string = XMLUtils.ElementToString(element);
- break;
- }
- }
- }
- if (string != null) break;
- }
- }
- if (string != null){
- openXMLEditor(string);
- }
- } catch (SOAPException e) {
- JBossWSUIPlugin.log(e);
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
- widgetSelected(arg0);
- }
- });
-
- resultsText.setMenu(resultsTextMenu);
-
- resultTab.setControl(resultsText);
-
- resultsText.addFocusListener(new FocusListener() {
-
- public void focusLost(FocusEvent arg0) {
- }
-
- public void focusGained(FocusEvent arg0) {
- setMenusForCurrentState();
- }
- });
-
- resultHeadersTab = new TabItem(resultTabGroup, SWT.NONE, 1);
- resultHeadersTab.setText(JBossWSUIMessages.JAXRSWSTestView_Results_Header_Label);
- resultHeadersList = new List(resultTabGroup, SWT.V_SCROLL);
- resultHeadersTab.setControl(resultHeadersList);
- GridData rdlsListGD = new GridData(SWT.FILL, SWT.FILL, true, true);
- rdlsListGD.horizontalSpan = 2;
- resultHeadersList.setLayoutData(dlsListGD);
-
- resultsHeaderMenu = new Menu(resultHeadersList.getShell(), SWT.POP_UP);
-
- copyResultHeaderMenuAction = new MenuItem(resultsHeaderMenu, SWT.PUSH);
- copyResultHeaderMenuAction.setText(JBossWSUIMessages.JAXRSWSTestView_CopyResultMenu_Text);
- copyResultHeaderMenuAction.setAccelerator(SWT.CTRL + 'C');
- copyResultHeaderMenuAction.addSelectionListener(new SelectionListener(){
-
- public void widgetDefaultSelected(SelectionEvent arg0) {
- if (resultHeadersList.getSelectionCount() == 0)
- resultHeadersList.selectAll();
- Display display = Display.getDefault();
- final Clipboard cb = new Clipboard(display);
- TextTransfer textTransfer = TextTransfer.getInstance();
- cb.setContents(resultHeadersList.getSelection() ,
- new Transfer[] { textTransfer });
- }
-
- public void widgetSelected(SelectionEvent arg0) {
- widgetDefaultSelected(arg0);
- }
- });
-
- resultHeadersList.setMenu(resultsHeaderMenu);
-
- resultHeadersList.addMouseListener(new MouseListener() {
- public void mouseDoubleClick(MouseEvent arg0) {
- }
- public void mouseDown(MouseEvent arg0) {
- setMenusForCurrentState();
- }
- public void mouseUp(MouseEvent arg0) {
- }
- });
-
- wsTypeCombo.setText(JAX_WS);
- setControlsForWSType(wsTypeCombo.getText());
- setControlsForMethodType(methodCombo.getText());
- setControlsForSelectedURL();
- 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;
- copyMenuAction.setEnabled(enabled);
- openInXMLEditorAction.setEnabled(enabled);
- if (wsTypeCombo.getText().equalsIgnoreCase(JAX_WS)) {
- openResponseTagInXMLEditor.setEnabled(enabled);
- } else if (wsTypeCombo.getText().equalsIgnoreCase(JAX_RS) ){
- openResponseTagInXMLEditor.setEnabled(false);
- }
- }
- if (resultHeadersList != null && !resultHeadersList.isDisposed()) {
- boolean enabled = resultHeadersList.getItemCount() > 0;
- copyResultHeaderMenuAction.setEnabled(enabled);
- }
- }
-
- private void openXMLEditor (String text){
- IWorkbenchWindow window = getSite().getWorkbenchWindow();
- IStorage storage = new ResultsXMLStorage(text);
- IStorageEditorInput input = new ResultsXMLStorageInput(storage);
- IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- try {
- if (window.getWorkbench().getEditorRegistry().findEditor(XML_EDITOR_ID) != null) {
- page.openEditor(input, XML_EDITOR_ID);
- } else {
- page.openEditor(input, DEFAULT_TEXT_EDITOR_ID);
- }
- } catch (PartInitException e) {
- JBossWSUIPlugin.log(e);
- }
- }
- }
-
- private void setControlsForSelectedURL() {
- if (urlCombo.getText().trim().length() > 0) {
- String urlText = urlCombo.getText();
- try {
- new URL(urlText);
- testButton.setEnabled(true);
- addTCPIPMonitorButton.setEnabled(true);
- } catch (MalformedURLException mue) {
- testButton.setEnabled(false);
- addTCPIPMonitorButton.setEnabled(false);
-
- return;
- }
- } else {
- testButton.setEnabled(false);
- addTCPIPMonitorButton.setEnabled(false);
- }
- }
-
- /*
- * Open the TCP/IP Monitor View
- */
- private void openMonitor() {
- try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().
- getActivePage().showView(TCPIP_VIEW_ID);
- } catch (PartInitException e) {
- JBossWSUIPlugin.log(e);
- }
- }
-
- private IMonitor findMonitor(String urlToCheck) {
- IMonitor monitor = null;
-
- IMonitor[] monitors = MonitorCore.getMonitors();
- if (monitors != null && monitors.length > 0) {
- for (int i= 0; i < monitors.length; i++) {
- if (urlToCheck.contains(monitors[i].getRemoteHost())) {
- monitor = monitors[i];
- break;
- }
- }
- }
- return monitor;
- }
-
- /*
- * Configure a TCP/IP Monitor entry so we can monitor it
- */
- private void configureMonitor() {
- if (urlCombo.getText().trim().length() > 0) {
- String oldUrl = urlCombo.getText();
- IMonitor monitor = findMonitor(oldUrl);
- if (monitor == null) {
-
- URL tempURL = null;
- try {
- tempURL = new URL(oldUrl);
- } catch (MalformedURLException e) {
- // ignore
- }
- AddMonitorDialog dialog = new AddMonitorDialog(getSite().getShell());
- if (tempURL != null) {
- dialog.getMonitor().setRemoteHost(tempURL.getHost());
- if (tempURL.getPort() > 0)
- dialog.getMonitor().setRemotePort(tempURL.getPort());
- }
- if (dialog.open() == Window.CANCEL)
- return;
- monitor = dialog.getMonitor();
- }
-
- if (monitor != null) {
- monitor = findMonitor(oldUrl);
- if (monitor != null) {
- if (!monitor.isRunning()) {
- try {
- monitor.start();
- int port = monitor.getLocalPort();
- int remotePort = monitor.getRemotePort();
- String host = monitor.getRemoteHost();
- String newUrl = null;
- if (oldUrl.contains(host + ':' + remotePort)) {
- newUrl = oldUrl.replace(host + ':' + remotePort, "localhost:" +
port); //$NON-NLS-1$
- } else if (oldUrl.contains(host + ':' + port)) {
- // do nothing - host/port combo is already correct
- newUrl = oldUrl;
- } else {
- newUrl = oldUrl.replace(host, "localhost:" + port); //$NON-NLS-1$
- }
- urlCombo.setText(newUrl);
- } catch (CoreException e) {
- // if we hit an error, open a dialog
- ErrorDialog dialog = new ErrorDialog(this.getSite().getShell(),
- JBossWSUIMessages.JAXRSWSTestView_Error_Title_Starting_Monitor,
- JBossWSUIMessages.JAXRSWSTestView_Error_Msg_Starting_Monitor,
- new Status(IStatus.ERROR, JBossWSUIPlugin.PLUGIN_ID,
- e.getLocalizedMessage(), e), IStatus.ERROR);
- dialog.open();
- }
- }
- }
- }
- }
- }
-
- /*
- * Enable/disable controls based on the WS technology type
- * and the method.
- *
- * @param methodType
- */
- private void setControlsForMethodType ( String methodType ) {
- if (wsTypeCombo.getText().equalsIgnoreCase(JAX_RS) &&
- methodType.equalsIgnoreCase(GET)) {
- bodyText.setEnabled(false);
- } else {
- bodyText.setEnabled(true);
- }
- }
-
- /*
- * Enable/disable controls based on the WS technology type
- * @param wsType
- */
- private void setControlsForWSType ( String wsType ) {
- if (wsType.equalsIgnoreCase(JAX_WS)) {
- actionText.setEnabled(true);
- bodyText.setEnabled(true);
- methodCombo.setEnabled(false);
- parmsList.setEnabled(false);
- parmsList.removeAll();
- dlsList.setEnabled(false);
- parmsTab.getControl().setEnabled(false);
- headerTab.getControl().setEnabled(true);
- methodCombo.setText(POST);
-
- String emptySOAP = "<?xml version=\"1.0\"
standalone=\"yes\" ?>" + //$NON-NLS-1$
- "<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + //$NON-NLS-1$
- "xmlns:ns=\"INSERT_URL_HERE\">" + //$NON-NLS-1$
- "<soap:Body>" + //$NON-NLS-1$
- "</soap:Body>" + //$NON-NLS-1$
- "</soap:Envelope>"; //$NON-NLS-1$
- emptySOAP = WSTestUtils.addNLsToXML(emptySOAP);
-
- if (bodyText.getText().trim().length() == 0) {
- bodyText.setText(emptySOAP);
- }
- wsdlButton.setEnabled(true);
- }
- else if (wsType.equalsIgnoreCase(JAX_RS)) {
- actionText.setEnabled(false);
- bodyText.setEnabled(true);
- methodCombo.setEnabled(true);
- parmsList.setEnabled(true);
- dlsList.setEnabled(true);
- parmsTab.getControl().setEnabled(true);
- headerTab.getControl().setEnabled(true);
- methodCombo.setText(GET);
- wsdlButton.setEnabled(false);
-
- if (bodyText.getText().trim().length() > 0) {
- bodyText.setText(""); //$NON-NLS-1$
- }
- }
- setMenusForCurrentState();
- }
-
- /*
- * Sets up the controls to call a public sample RESTful WS that does
- * a postal code lookup or a JAX-WS service that does a
- * Shakespeare lookup.
- */
- private void setupSample() {
- // go to
http://www.geonames.org/export/web-services.html for example
- //http://ws.geonames.org/postalCodeSearch?postalcode=9011&maxRows=10
- if (wsTypeCombo.getText().equalsIgnoreCase(JAX_RS)) {
-
urlCombo.setText("http://ws.geonames.org/postalCodeSearch?"); //$NON-NLS-1$
- parmsList.setSelection("postalcode=80920,maxRows=10"); //$NON-NLS-1$
- dlsList.setSelection("content-type=application/xml"); //$NON-NLS-1$
- methodCombo.setText(GET);
- tabGroup.setSelection(parmsTab);
- bodyText.setText(EMPTY_STRING);
- }
- else if (wsTypeCombo.getText().equalsIgnoreCase(JAX_WS)) {
- String soapIn = "<?xml version=\"1.0\" standalone=\"yes\"
?>" + //$NON-NLS-1$
- "<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + //$NON-NLS-1$
- "xmlns:ns=\"http://xmlme.com/WebServices\">" + //$NON-NLS-1$
- "<soap:Body>" + //$NON-NLS-1$
- "<ns:GetSpeech>" + //$NON-NLS-1$
- "<ns:Request>slings and arrows</ns:Request>"+ //$NON-NLS-1$
- "</ns:GetSpeech>"+ //$NON-NLS-1$
- "</soap:Body>" + //$NON-NLS-1$
- "</soap:Envelope>"; //$NON-NLS-1$
- soapIn = WSTestUtils.addNLsToXML(soapIn);
-
-
urlCombo.setText("http://www.xmlme.com/WSShakespeare.asmx"); //$NON-NLS-1$
-
actionText.setText("http://xmlme.com/WebServices/GetSpeech"); //$NON-NLS-1$
- bodyText.setText(soapIn);
- parmsList.setSelection(EMPTY_STRING);
- dlsList.setSelection(EMPTY_STRING);
- tabGroup.setSelection(bodyTab);
- }
- setControlsForWSType(wsTypeCombo.getText());
- setControlsForMethodType(methodCombo.getText());
- setControlsForSelectedURL();
- }
-
- /*
- * Actually perform the test based on which type of activity it is
- */
- private void handleTest(final String wsTech) {
-
- String urlText = urlCombo.getText();
- try {
- new URL(urlText);
- } catch (MalformedURLException mue) {
- // do nothing, but return since we don't have a working URL
- return;
- }
-
- if (urlCombo.getItemCount() > 0) {
- java.util.List<String> aList = Arrays.asList(urlCombo.getItems());
- if (!aList.contains(urlCombo.getText())) {
- urlCombo.add(urlCombo.getText());
- }
- } else {
- urlCombo.add(urlCombo.getText());
- }
-
- final String url = urlCombo.getText();
- final String action = actionText.getText();
- final String body = bodyText.getText();
- final String method = methodCombo.getText();
- final String headers = dlsList.getSelection();
- final String parms = parmsList.getSelection();
-
- Job aJob = new Job(JBossWSUIMessages.JAXRSWSTestView_Invoking_WS_Status) {
- protected IStatus run(IProgressMonitor monitor) {
- IStatus status = Status.OK_STATUS;
- // execute the task ...
- if (wsTech.equalsIgnoreCase(JAX_RS)) {
- status = handleRSTest(monitor, url, method, body, parms, headers);
- }
- else if (wsTech.equalsIgnoreCase(JAX_WS)) {
- status = handleWSTest(monitor, url, action, body);
- }
- monitor.done();
- return status;
- }
- };
- // true to indicate that this job was initiated by a UI end user
- aJob.setUser(true);
- aJob.addJobChangeListener(new IJobChangeListener() {
-
- public void sleeping(IJobChangeEvent event) {};
- public void scheduled(IJobChangeEvent event) {};
- public void running(IJobChangeEvent event) {};
- public void done(final IJobChangeEvent event) {
- if (event.getResult() instanceof WSTestStatus) {
- final WSTestStatus status = (WSTestStatus) event.getResult();
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
- public void run() {
- if (status.getResultsText() != null)
- resultsText.setText(status.getResultsText());
- else if (status.getMessage() != null)
- resultsText.setText(status.getMessage());
- resultHeadersList.removeAll();
- String[] headers =
- DelimitedStringList.parseString(status.getHeadersList(),
RESULT_HEADER_DELIMITER);
- if (headers != null && headers.length > 0) {
- for (int i = 0; i < headers.length; i++) {
- resultHeadersList.add(headers[i]);
- }
- }
- }
- });
- }
- }
-
- public void awake(IJobChangeEvent event) {};
- public void aboutToRun(IJobChangeEvent event) {};
- });
- aJob.schedule();
-
- setMenusForCurrentState();
- }
-
- /*
- * Actually call the WS and displays the result
- */
- private IStatus handleWSTest(final IProgressMonitor monitor, String url, String action,
String body) {
- try {
-
- envelope = null;
- soapbody = null;
- monitor.worked(10);
-// JAXWSTester tester = new JAXWSTester();
-// tester.doTest(url, action, body);
- JAXWSTester2 tester = new JAXWSTester2();
- boolean itRan = false;
- while (!monitor.isCanceled()) {
- try {
- if (!itRan && serviceNSMessage != null && serviceNSMessage.length ==
3) {
- itRan = true;
- // call the service
- tester.doTest(monitor, url, action, serviceNSMessage[0], serviceNSMessage[1],
serviceNSMessage[2], body);
- } else {
- break;
- }
- } catch (InterruptedException ie) {
- monitor.setCanceled(true);
- }
- }
- if (monitor.isCanceled()) {
- WSTestStatus status = new WSTestStatus(IStatus.OK,
- JBossWSUIPlugin.PLUGIN_ID,
- JBossWSUIMessages.JAXRSWSTestView_Message_Service_Invocation_Cancelled);
- return status;
- }
- if (!itRan) {
- WSTestStatus status = new WSTestStatus(IStatus.OK,
- JBossWSUIPlugin.PLUGIN_ID,
- JBossWSUIMessages.JAXRSWSTestView_Message_Unsuccessful_Test);
- return status;
- }
-// tester.doTest(url, action, serviceNSMessage[0], serviceNSMessage[1],
serviceNSMessage[2], body);
- monitor.worked(70);
- String result = tester.getResultBody();
- envelope = tester.getResultSOAP();
- soapbody = tester.getResultSOAPBody();
- String cleanedUp = WSTestUtils.addNLsToXML(result);
-
- WSTestStatus status = new WSTestStatus(IStatus.OK,
- JBossWSUIPlugin.PLUGIN_ID,
- JBossWSUIMessages.JAXRSWSTestView_JAXWS_Success_Status);
- status.setResultsText(cleanedUp);
- monitor.worked(10);
-
- String listText = EMPTY_STRING;
- if (tester.getResultHeaders() != null) {
- Iterator<?> iter = tester.getResultHeaders().entrySet().iterator();
- while (iter.hasNext()) {
- String text = EMPTY_STRING;
- Entry<?, ?> entry = (Entry<?, ?>) iter.next();
- if (entry.getKey() == null)
- text = entry.getValue().toString();
- else
- text = text + entry.toString();
- listText = listText + text;
- if (iter.hasNext()) {
- listText = listText + RESULT_HEADER_DELIMITER;
- }
- }
- }
- status.setHeadersList(listText);
- monitor.worked(10);
- return status;
- } catch (Exception e) {
- WSTestStatus status = new WSTestStatus(IStatus.OK,
- JBossWSUIPlugin.PLUGIN_ID,
- JBossWSUIMessages.JAXRSWSTestView_Exception_Status + e.getLocalizedMessage());
- status.setResultsText(e.toString());
- JBossWSUIPlugin.log(e);
- return status;
- }
- }
-
- /*
- * Actually call the RESTful WS to test it
- */
- private IStatus handleRSTest(final IProgressMonitor monitor, String address, String
method, String body, String parms, String headersStr) {
-
- if (method.equalsIgnoreCase(GET))
- body = EMPTY_STRING;
-
- // if no actual text in the request body, set to null
- if (body.trim().length() == 0) body = null;
-
- monitor.worked(10);
-
- // Process parameters for web service call
- HashMap<String, String> parameters = new HashMap<String, String>();
- if (parms != null && parms.length() > 0) {
- String[] parsedList = DelimitedStringList.parseString(parms , ",");
//$NON-NLS-1$
- if (parsedList != null && parsedList.length > 0) {
- for (int i = 0; i < parsedList.length; i++) {
- String nameValuePair = parsedList[i];
- String[] nameAndValue = DelimitedStringList.parseString(nameValuePair,
"="); //$NON-NLS-1$
- if (nameAndValue != null && nameAndValue.length == 2) {
- parameters.put(nameAndValue[0], nameAndValue[1]);
- }
- }
- }
- }
-
- monitor.worked(10);
- // Process headers for web service call
- HashMap<String, String> headers = new HashMap<String, String>();
- if (headersStr != null && headersStr.length() > 0) {
- String[] parsedList = DelimitedStringList.parseString(headersStr , ",");
//$NON-NLS-1$
- if (parsedList != null && parsedList.length > 0) {
- for (int i = 0; i < parsedList.length; i++) {
- String nameValuePair = parsedList[i];
- String[] nameAndValue = DelimitedStringList.parseString(nameValuePair,
"="); //$NON-NLS-1$
- if (nameAndValue != null && nameAndValue.length == 2) {
- headers.put(nameAndValue[0], nameAndValue[1]);
- }
- }
- }
- }
-
- JAXRSTester tester = new JAXRSTester();
-
- // now actually call it
- try {
-
- // call the service
- tester.doTest(address, parameters, headers, method, body);
-
- String result = tester.getResultBody();
-
- // put the results in the result text field
- String cleanedUp = WSTestUtils.addNLsToXML(result);
-
- WSTestStatus status = new WSTestStatus(IStatus.OK,
- JBossWSUIPlugin.PLUGIN_ID,
- JBossWSUIMessages.JAXRSWSTestView_JAXRS_Success_Status);
- status.setResultsText(cleanedUp);
-
- String listText = EMPTY_STRING;
- if (tester.getResultHeaders() != null) {
- Iterator<?> iter = tester.getResultHeaders().entrySet().iterator();
- while (iter.hasNext()) {
- String text = EMPTY_STRING;
- Entry<?, ?> entry = (Entry<?, ?>) iter.next();
- if (entry.getKey() == null)
- text = entry.getValue().toString();
- else
- text = text + entry.toString();
- listText = listText + text;
- if (iter.hasNext()) {
- listText = listText + RESULT_HEADER_DELIMITER;
- }
- }
- }
-
- status.setHeadersList(listText);
- monitor.worked(10);
- return status;
-
- } catch (Exception e) {
- String result = tester.getResultBody();
-
- // put the results in the result text field
- String cleanedUp = WSTestUtils.addNLsToXML(result);
-
- WSTestStatus status = new WSTestStatus(IStatus.OK,
- JBossWSUIPlugin.PLUGIN_ID,
- JBossWSUIMessages.JAXRSWSTestView_JAXRS_Success_Status);
- status.setResultsText(cleanedUp);
-
- String listText = EMPTY_STRING;
- if (tester.getResultHeaders() != null) {
- Iterator<?> iter = tester.getResultHeaders().entrySet().iterator();
- while (iter.hasNext()) {
- String text = EMPTY_STRING;
- Entry<?, ?> entry = (Entry<?, ?>) iter.next();
- if (entry.getKey() == null)
- text = entry.getValue().toString();
- else
- text = text + entry.toString();
- listText = listText + text;
- if (iter.hasNext()) {
- listText = listText + RESULT_HEADER_DELIMITER;
- }
- }
- }
-
- status.setHeadersList(listText);
- monitor.worked(10);
- return status;
- }
- }
-
- /**
- * Passing the focus request to the control.
- */
- public void setFocus() {
- // set initial focus to the URL text combo
- urlCombo.setFocus();
- }
-
-}
\ No newline at end of file
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView2.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView2.java 2011-05-10
16:55:18 UTC (rev 31191)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView2.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -109,6 +109,7 @@
import org.jboss.tools.ws.ui.utils.JAXWSTester2;
import org.jboss.tools.ws.ui.utils.ResultsXMLStorage;
import org.jboss.tools.ws.ui.utils.ResultsXMLStorageInput;
+import org.jboss.tools.ws.ui.utils.SchemaUtils;
import org.jboss.tools.ws.ui.utils.TesterWSDLUtils;
import org.jboss.tools.ws.ui.utils.WSTestUtils;
import org.w3c.dom.Element;
@@ -421,7 +422,6 @@
getCurrentHistoryEntry().setOperationName(null);
serviceNSMessage = null;
-// actionText = null;
Definition wsdlDef = wbDialog.getWSDLDefinition();
getCurrentHistoryEntry().setWsdlDef(wsdlDef);
@@ -432,7 +432,7 @@
getCurrentHistoryEntry().setUrl(wbDialog.getWSDLText());
urlCombo.setText(wbDialog.getWSDLText());
- String output = TesterWSDLUtils.getSampleSOAPInputMessage(wsdlDef,
+ String output = SchemaUtils.getSampleSOAPInputMessage(wsdlDef,
wbDialog.getServiceTextValue(),
wbDialog.getPortTextValue(),
wbDialog.getBindingValue(),
@@ -463,8 +463,14 @@
wbDialog.getServiceTextValue(),
wbDialog.getPortTextValue());
getCurrentHistoryEntry().setSOAP12(isSOAP12);
+
+ String headerText = SchemaUtils.getSampleSOAPMessageHeader(wsdlDef,
+ wbDialog.getServiceTextValue(),
+ wbDialog.getPortTextValue(),
+ wbDialog.getBindingValue(),
+ wbDialog.getOperationTextValue());
- String soapIn = generateSampleSOAP(output, isSOAP12);
+ String soapIn = generateSampleSOAP(headerText, output, isSOAP12);
if (opName != null) {
if (bodyText.getText().length() > 0) {
@@ -487,15 +493,6 @@
}
}
}
-// if (MessageDialog.openQuestion(getSite().getShell(),
-// JBossWSUIMessages.JAXRSWSTestView2_Title_Msg_May_Be_Out_of_Date,
-// JBossWSUIMessages.JAXRSWSTestView2_Text_Msg_May_Be_Out_of_Date)) {
-//
-// bodyText.setText(soapIn);
-// getCurrentHistoryEntry().setBody(soapIn);
-// getCurrentHistoryEntry().setAction(actionURL);
-//
-// }
} else if (bodyText.getText().length() > 0) {
String opNameInBody = getOpNameFromRequestBody();
@@ -520,9 +517,6 @@
}
}
-// urlCombo.setText(endpointURL);
-// actionText = actionURL;
-
setControlsForWSType(getCurrentTestType());
setControlsForMethodType(methodCombo.getText());
setControlsForSelectedURL();
@@ -984,25 +978,40 @@
super.dispose();
}
- private String generateSampleSOAP ( String innerText, boolean isSOAP12 ) {
+ private String generateSampleSOAP ( String headerText, String innerText, boolean
isSOAP12 ) {
String prefix = TesterWSDLUtils.SOAP_PREFIX;
String soapURI = TesterWSDLUtils.SOAP_NS_URI;
if (isSOAP12) {
prefix = TesterWSDLUtils.SOAP12_PREFIX;
soapURI = TesterWSDLUtils.SOAP12_ENVELOPE_NS_URI;
}
- String soapIn = "<?xml version=\"1.0\" encoding=\"utf-8\"
standalone=\"yes\" ?>\n" + //$NON-NLS-1$
- "<" + prefix + ":Envelope xmlns:" + prefix +
"=\"" + soapURI + "\" " + //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
- "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$
- "<" + prefix + ":Body>\n";//$NON-NLS-1$ //$NON-NLS-2$
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"
standalone=\"yes\" ?>\n");//$NON-NLS-1$
+ buffer.append("<" + prefix + ":Envelope xmlns:" + prefix +
"=\"" + soapURI + "\" ");//$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
+
buffer.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-ins...
" );//$NON-NLS-1$
+
buffer.append("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
>\n");//$NON-NLS-1$
+ buffer.append("<" + prefix + ":Header>\n");//$NON-NLS-1$
//$NON-NLS-2$
+ if (headerText != null)
+ buffer.append(headerText);
+ buffer.append("</" + prefix + ":Header>\n");;//$NON-NLS-1$
//$NON-NLS-2$
+ buffer.append("<" + prefix + ":Body>\n");//$NON-NLS-1$
//$NON-NLS-2$
if (innerText != null)
- soapIn = soapIn + innerText;
- soapIn = soapIn +
- "</" + prefix + ":Body>\n" + //$NON-NLS-1$ //$NON-NLS-2$
- "</" + prefix + ":Envelope>"; //$NON-NLS-1$ //$NON-NLS-2$
- return soapIn;
+ buffer.append(innerText);
+ buffer.append("</" + prefix + ":Body>\n");;//$NON-NLS-1$
//$NON-NLS-2$
+ buffer.append("</" + prefix + ":Envelope>");//$NON-NLS-1$
//$NON-NLS-2$
+
+// String soapIn = "<?xml version=\"1.0\" encoding=\"utf-8\"
standalone=\"yes\" ?>\n" + //$NON-NLS-1$
+// "<" + prefix + ":Envelope xmlns:" + prefix +
"=\"" + soapURI + "\" " + //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$ //$NON-NLS-4$
+// "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$
+// "<" + prefix + ":Body>\n";//$NON-NLS-1$ //$NON-NLS-2$
+// if (innerText != null)
+// soapIn = soapIn + innerText;
+// soapIn = soapIn +
+// "</" + prefix + ":Body>\n" + //$NON-NLS-1$ //$NON-NLS-2$
+// "</" + prefix + ":Envelope>"; //$NON-NLS-1$ //$NON-NLS-2$
+ return buffer.toString();
}
private void setMenusForCurrentState() {
@@ -1087,7 +1096,7 @@
dlsList.setEnabled(false);
String emptySOAP =
- generateSampleSOAP(null, false);
+ generateSampleSOAP(null, null, false);
emptySOAP = WSTestUtils.addNLsToXML(emptySOAP);
if (bodyText.getText().trim().length() == 0) {
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/TestHistoryEntry.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/TestHistoryEntry.java 2011-05-10
16:55:18 UTC (rev 31191)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/TestHistoryEntry.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -24,7 +24,6 @@
private String portName;
private String bindingName;
private String operationName;
-// private String wsMethod;
private Definition wsdlDef = null;
private String[] serviceNSMessage = null;
private boolean isSOAP12 = false;
@@ -126,14 +125,6 @@
this.operationName = operationName;
}
-// public void setWsMethod(String wsMethod) {
-// this.wsMethod = wsMethod;
-// }
-//
-// public String getWsMethod() {
-// return wsMethod;
-// }
-
public void setWsdlDef(Definition wsdlDef) {
this.wsdlDef = wsdlDef;
}
Modified:
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 2011-05-10
16:55:18 UTC (rev 31191)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/WSDLBrowseDialog.java 2011-05-10
17:05:54 UTC (rev 31192)
@@ -173,21 +173,25 @@
* @param arg0
*/
private void validateLocation ( ModifyEvent arg0 ) {
- this.getContents().getDisplay().asyncExec( new Runnable() {
- public void run() {
- setMessage(JBossWSUIMessages.WSDLBrowseDialog_Message);
- IStatus status = validate(false);
- if (status != Status.OK_STATUS) {
- setMessage(status.getMessage(), IMessageProvider.WARNING);
- if (showServicePortOperaton)
- setGroupEnabled(false);
- } else {
- setMessage(JBossWSUIMessages.WSDLBrowseDialog_Message);
- if (showServicePortOperaton)
- setGroupEnabled(true);
- }
+ if (this.getContents() != null) {
+ if (this.getContents().getDisplay() != null) {
+ this.getContents().getDisplay().asyncExec( new Runnable() {
+ public void run() {
+ setMessage(JBossWSUIMessages.WSDLBrowseDialog_Message);
+ IStatus status = validate(false);
+ if (status != Status.OK_STATUS) {
+ setMessage(status.getMessage(), IMessageProvider.WARNING);
+ if (showServicePortOperaton)
+ setGroupEnabled(false);
+ } else {
+ setMessage(JBossWSUIMessages.WSDLBrowseDialog_Message);
+ if (showServicePortOperaton)
+ setGroupEnabled(true);
+ }
+ }
+ });
}
- });
+ }
}
@Override