相对而言。Eclipse API中国的数据是比较小的。但Eclipse的API提供了许多的。非常强大。

实例,eclipse的Eclipse API 提供 org.eclipse.wst.wsdl包裹,它提供了大量的类来解决WSDL档。

。其提供的API简单易懂。并且其API是和专业术语相应起来的,比方,

一个WSDL文档通常包括7个重要的元素。即types、import、message、portType、operation、binding、 service元素。

这些元素嵌套在definitions元素中,

(1) Definitions是WSDL文档的根元素。相应于这个类: org.eclipse.wst.wsdl.Definition 其它的对象都能够通过这个对象获得

(2) Types - 数据类型定义的容器,它使用某种类型系统(一般地使用XML Schema中的类型系统)。

(3) Message - 通信消息的数据结构的抽象类型化定义。使用Types所定义的类型来定义整个消息的数据结构。 

(4) PortType - 对于某个訪问入口点类型所支持的操作的抽象集合。这些操作能够由一个或多个服务訪问点来支持。

 (子节点) Operation - 对服务中所支持的操作的抽象描写叙述。一般单个Operation描写叙述了一个訪问入口的请求/响应消息对。

(5) Binding - 特定port类型的详细协议和数据格式规范的绑定。

(6) Service- 相关服务訪问点的集合。

(子节点) Port - 定义为协议/数据格式绑定与详细Web訪问地址组合的单个服务訪问点。

以下是代码实例:

  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.util.Iterator;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.Set;
  7.  
  8. import javax.wsdl.Message;
  9. import javax.wsdl.Part;
  10. import javax.wsdl.PortType;
  11. import javax.xml.namespace.QName;
  12.  
  13. import org.eclipse.emf.common.util.URI;
  14. import org.eclipse.emf.ecore.resource.Resource;
  15. import org.eclipse.emf.ecore.resource.ResourceSet;
  16. import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
  17. import org.eclipse.wst.wsdl.Definition;
  18. import org.eclipse.wst.wsdl.Types;
  19. import org.eclipse.wst.wsdl.internal.impl.PartImpl;
  20. import org.eclipse.wst.wsdl.internal.util.WSDLResourceFactoryImpl;
  21. import org.eclipse.wst.wsdl.util.WSDLResourceImpl;
  22. import org.eclipse.xsd.XSDElementDeclaration;
  23. import org.eclipse.xsd.XSDSchema;
  24. import org.eclipse.xsd.util.XSDResourceImpl;
  25. import org.junit.Test;
  26. import org.junit.Before;
  27.  
  28. public class WSDLParserWithEclipse {
  29. Definition definition=null;
  30. String wsdlPathString="E:/HelloEclipse-EMF-WSDL-XSD/test.wsdl";
  31.  
  32. @Before
  33. public void setup(){
  34. ResourceSet resourceSet = new ResourceSetImpl();
  35. Resource.Factory.Registry registry = resourceSet.getResourceFactoryRegistry();
  36. Map extensionToFactoryMap = registry.getExtensionToFactoryMap();
  37. extensionToFactoryMap.put("wsdl", new WSDLResourceFactoryImpl());
  38. File wsdlFile =new File(wsdlPathString);
  39. URI uri = URI.createFileURI(wsdlFile.getAbsolutePath());
  40. // You can avoid this cast, but will have to cast anyway later to get the Definition out the resource contents
  41. WSDLResourceImpl wsdlResource = (WSDLResourceImpl) resourceSet.createResource(uri);
  42. try {
  43. wsdlResource.load(null);
  44. definition = wsdlResource.getDefinition();
  45. }catch(Exception e){
  46. e.printStackTrace();
  47. }
  48. }
  49.  
  50. @Test
  51. public void testTypes(){
  52. Types types = definition.getETypes();
  53. List schemas = types.getSchemas("http://www.xxxxx.com/problem");
  54. XSDSchema schema = (XSDSchema) schemas.get(0);
  55. org.eclipse.xsd.util.XSDResourceImpl.serialize(System.out, schema.getElement());
  56. }
  57.  
  58. @Test
  59. public void testMessage(){
  60. Map messages=definition.getMessages();
  61. System.out.println("The message size is:"+messages.size());
  62. Set setMessages=messages.keySet();
  63. Iterator iteratorMessages=setMessages.iterator();
  64. while(iteratorMessages.hasNext()){
  65. QName key=(QName)iteratorMessages.next();
  66. Message message=(Message)messages.get(key);
  67. //{http://www.xxxxx.com/problem}getKeysSoapIn
  68. //System.out.println("Message Name:"+message.getQName());
  69. if(message.getQName().toString().indexOf("getKeysSoapIn")>0){
  70. System.out.println("Message Name:"+message.getQName());
  71. Map partsMap=message.getParts();
  72. //org.eclipse.xsd.impl.XSDElementDeclarationImpl
  73. System.out.println("Message Part size for getKeysSoapIn message is:"+partsMap.size());
  74. PartImpl part= (PartImpl)partsMap.get("problem");
  75. XSDElementDeclaration xsdElementDeclaration=part.getElementDeclaration();
  76. XSDResourceImpl.serialize(System.out, xsdElementDeclaration.getElement());
  77. }
  78. }
  79. }
  80. @Test
  81. public void testPortType(){
  82. Map portTypes=definition.getPortTypes();
  83. System.out.println("Port Type size:"+portTypes.size());
  84. if(portTypes!=null&&portTypes.size()>0){
  85. Set set=portTypes.keySet();
  86. Iterator iterator=set.iterator();
  87. while(iterator.hasNext()){
  88. QName object=(QName)iterator.next();
  89. PortType portType=(PortType)portTypes.get(object);
  90. System.out.println("Port Type name:"+portType.getQName());
  91. org.eclipse.xsd.util.XSDResourceImpl.serialize(System.out, portType.getDocumentationElement());
  92. }
  93. }
  94. }
  95.  
  96. }

版权声明:本文博主原创文章,博客,未经同意不得转载。

如何使用Eclipse API 提供 org.eclipse.wst.wsdl 要解决阅读WSDL档?的更多相关文章

  1. 【eclipse插件开发实战】Eclipse插件开发4——插件JDE、PDE开发方式及plugin.xml配置文件结构

    Eclipse插件开发4--插件JDE.PDE开发方式及plugin.xml配置文件结构 开发方式分为:java开发环境JDE开发插件的方式和插件开发环境PDE开发插件方式. 插件通过添加到预定义的扩 ...

  2. 【eclipse插件开发实战】Eclipse插件开发2——SWT

    Eclipse插件开发实战2--SWT 一.SWT简介 SWT(StandardWidget Toolkit) 标准小窗口工具箱,一开源的GUI编程框架,与AWT/Swing有相似的用处,eclips ...

  3. 【eclipse插件开发实战】Eclipse插件开发1——eclipse内核结构、扩展点机制

    Eclipse插件开发实战1--eclipse内核结构.扩展点机制 一.前言 本系列总体介绍eclipse插件开发基本理论.插件项目结构及开发步骤,最后再给出两个插件开发实例. 总体安排结构如下: 1 ...

  4. eclipse中的js文件报错的解决办法

    在使用别人的项目的时候,导入到eclipse中发现js文件报错,解决办法是关闭eclipse的js校验功能. 三个步骤: 1. 右键点击项目->properties->Validation ...

  5. eclipse启动报错eclipse failed to create the java virutal machine

    早上一来,我的eclipse就无法启动了,错误就是这句话: eclipse failed to create the java virutal machine 直译就是eclipse无法创建JAVA虚 ...

  6. 打开Eclipse时出现"The Eclipse executable launcher was unable to locate its companion shared library"情况的解决办法

    在网上有坑,各种解决方法都有,但似乎我这台64位机器不太给面子,都不能解决: 结果自己找到了解决办法,总结了一下,大多数软件出问题,如果卸载了重新装还是出现问题,一般都是注册表残留的问题: 将ecli ...

  7. 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!&&在eclipse.ini中为eclipse指定jdk启动

    参考:http://blog.csdn.net/zyz511919766/article/details/7442633 http://blog.sina.com.cn/s/blog_028f0c1c ...

  8. 让32位Eclipse和64位Eclipse同时在64的Windows7上运行

    转自让32位Eclipse和64位Eclipse同时在64的Windows7上运行 参考这篇文章:http://wenku.baidu.com/view/57994c270066f5335a81214 ...

  9. Eclipse优化集合,Eclipse优化速度,解决Ctrl+C、Ctrl+V卡

    Eclipse优化集合,Eclipse优化速度,解决Ctrl+C.Ctrl+V卡 >>>>>>>>>>>>>>> ...

随机推荐

  1. cocos2.2.3 HelloCpp TestCpp android 环境搭建 编译

    cygwin make PATH->E:\cygwin\bin JAVA_HOME->C:\Program Files\Java\jdk1.8.0_05 Eclipse->Windo ...

  2. Centos 6安装完美搭建mysql、php、apache之旅

    安装apache [root@centos share]# yum -y install httpd Loaded plugins: fastestmirror, refresh-packagekit ...

  3. https原理及tomcat配置https方法

    一. 什么是HTTPS 在说HTTPS之前先说说什么是HTTP,HTTP就是我们平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不 ...

  4. fzu2150(bfs)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 题意:在任意两处点火,求最短时间烧光所有草堆. 分析:由于n,m比较小,将所有草堆坐标记录下来,然后暴力 ...

  5. hdu2606(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2606 题意:  用1*1,2*2,3*3,4*4的正方形填充4*n的矩形, 问有多少种不同填法. 分析 ...

  6. hdu2062(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2062 详细分析:http://mamicode.com/info-detail-95273.html ...

  7. ubuntu Linux 安装和首次使用

    1.ubuntu Linux 安装后切换到root账户,在默认情况下,系统安装过程中需要创建一个用户,切换到root账号命令如下:$ sudo -s -H输入 当前账户密码就可以切换到root.2.u ...

  8. C#的百度地图开发(三)依据坐标获取位置、商圈及周边信息

    原文:C#的百度地图开发(三)依据坐标获取位置.商圈及周边信息 我们得到了百度坐标,现在依据这一坐标来获取相应的信息.下面是相应的代码 public class BaiduMap { /// < ...

  9. .Net路(十三)导出数据库到EXCEL

    .NET出口Office文件(word,excel)有两种方法我明白.一个存储在导出的文件中server录以下.利用response输出到浏览器地址栏,直接打开:还有直接利用javascript来导出 ...

  10. Fedora16 安装相关

    安装BCM4312无线网卡驱动 Linux系统BCM4312无线网卡驱动的安装 联想Y450 Linux系统 无线网卡驱动安装 准备工作: Broadcom官网驱动下载地址 http://www.br ...