The Eclipse API is relatively small in Chinese, but the Eclipse API provides a very large and powerful feature.
For example, Eclipse's Eclipse API provides a ORG.ECLIPSE.WST.WSDL package that provides many classes to parse a WSDL file.
In general, the API is simple to understand, and its API is compatible with professional terminology, for example,
A WSDL document typically contains 7 important elements, the types, import, message, PortType, operation, binding, and service elements.
These elements are nested within the definitions element,
(1) Definitions is the root element of the WSDL document. Corresponds to this class: Org.eclipse.wst.wsdl.Definition other objects can be obtained by this object.
(2) Types-a container for a data type definition that uses a type system (generally using the type system in XML schemas).
(3) Message-Abstract typed definition of the data structure of the communication message. Use the type defined by types to define the data structure of the entire message.
(4) PortType-an abstract collection of operations supported by an access entry point type that can be supported by one or more service access points.
(Child node) Operation-an abstract description of the operations supported in the service, typically a single operation describes a request/response message pair for an access portal.
(5) Binding-the specific protocol and data format specification bindings for a specific port type.
(6) A collection of service-related service access points.
(Child node) Port-Defines a single service access point for which the Protocol/data format binding is combined with a specific Web access address.
Here is the code example:
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.wsdl.Message;
import javax.wsdl.Part;
import javax.wsdl.PortType;
import javax.xml.namespace.QName;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.wst.wsdl.Definition;
import org.eclipse.wst.wsdl.Types;
import org.eclipse.wst.wsdl.internal.impl.PartImpl;
import org.eclipse.wst.wsdl.internal.util.WSDLResourceFactoryImpl;
import org.eclipse.wst.wsdl.util.WSDLResourceImpl;
import org.eclipse.xsd.XSDElementDeclaration;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDResourceImpl;
import org.junit.Test;
import org.junit.Before;
public class WSDLParserWithEclipse {
Definition definition=null;
String wsdlPathString="E:/HelloEclipse-EMF-WSDL-XSD/test.wsdl";
@Before
public void setup(){
ResourceSet resourceSet = new ResourceSetImpl();
Resource.Factory.Registry registry = resourceSet.getResourceFactoryRegistry();
Map extensionToFactoryMap = registry.getExtensionToFactoryMap();
extensionToFactoryMap.put("wsdl", new WSDLResourceFactoryImpl());
File wsdlFile =new File(wsdlPathString);
URI uri = URI.createFileURI(wsdlFile.getAbsolutePath());
// You can avoid this cast, but will have to cast anyway later to get the Definition out the resource contents
WSDLResourceImpl wsdlResource = (WSDLResourceImpl) resourceSet.createResource(uri);
try {
wsdlResource.load(null);
definition = wsdlResource.getDefinition();
}catch(Exception e){
e.printStackTrace();
}
}
@Test
public void testTypes(){
Types types = definition.getETypes();
List schemas = types.getSchemas("http://www.xxxxx.com/problem");
XSDSchema schema = (XSDSchema) schemas.get(0);
org.eclipse.xsd.util.XSDResourceImpl.serialize(System.out, schema.getElement());
}
@Test
public void testMessage(){
Map messages=definition.getMessages();
System.out.println("The message size is:"+messages.size());
Set setMessages=messages.keySet();
Iterator iteratorMessages=setMessages.iterator();
while(iteratorMessages.hasNext()){
QName key=(QName)iteratorMessages.next();
Message message=(Message)messages.get(key);
//{http://www.xxxxx.com/problem}getKeysSoapIn
//System.out.println("Message Name:"+message.getQName());
if(message.getQName().toString().indexOf("getKeysSoapIn")>0){
System.out.println("Message Name:"+message.getQName());
Map partsMap=message.getParts();
//org.eclipse.xsd.impl.XSDElementDeclarationImpl
System.out.println("Message Part size for getKeysSoapIn message is:"+partsMap.size());
PartImpl part= (PartImpl)partsMap.get("problem");
XSDElementDeclaration xsdElementDeclaration=part.getElementDeclaration();
XSDResourceImpl.serialize(System.out, xsdElementDeclaration.getElement());
}
}
}
@Test
public void testPortType(){
Map portTypes=definition.getPortTypes();
System.out.println("Port Type size:"+portTypes.size());
if(portTypes!=null&&portTypes.size()>0){
Set set=portTypes.keySet();
Iterator iterator=set.iterator();
while(iterator.hasNext()){
QName object=(QName)iterator.next();
PortType portType=(PortType)portTypes.get(object);
System.out.println("Port Type name:"+portType.getQName());
org.eclipse.xsd.util.XSDResourceImpl.serialize(System.out, portType.getDocumentationElement());
}
}
}
}
How do I use the org.eclipse.wst.wsdl provided by the Eclipse API to parse a WSDL file?