级别: 中级 Subhash Kumar, SOA 交付顾问,
IBM
2008 年 9 月 24 日 通过在 IBM® WebSphere® Service Registry and Repository 中创建类别分类,您可以灵活地对服务和元数据进行编目和组织,从而实现高效的治理。本文介绍一种使用基于 XML 的接口将类别分类加载到 WebSphere Service Registry and Repository 中的机制,还可以将这种机制扩展为将类别分类从其他外部系统同步到 WebSphere Service Registry and Repository 的集成机制。了解如何使用 WebSphere Service Registry and Repository 提供的 Java™ 管理扩展(Java Management Extensions,JMX)来管理 API 将类别分类加载到 WebSphere Service Registry and Repository 中。
引言
WebSphere Service Registry and Repository 允许您发布、查找、充实、管理和治理面向服务的体系架构(Service-Oriented Architecture,SOA)中的服务和策略(有关更多信息,请参阅“IBM WebSphere Service Registry and Repository 简介,第 1 部分: WebSphere Service Registry and Repository 在 SOA 生命周期中的一天
”)。
在本文中,了解如何在 WebSphere Service Registry and Repository 中使用简单 XML 接口以编程方式创建类别分类。WebSphere Service Registry and Repository 允许您导入使用 Web 本体语言(Web Ontology Language,OWL)创建的类别分类。目前,这些 OWL 文件是通过 WebSphere Service Registry and Repository 中提供的简单 Web 用户界面或通过其他自定义方法来手动创建的。
其他公司 IT 系统中通常存在组织和功能分类,需要以编程方式将它们提取并加载到 WebSphere Service Registry and Repository 中。这样的分类可能会在维护它们的其他系统中更改(尽管不是经常更改),这种情况是相当普遍的,您需要将这些分类与 WebSphere Service Registry and Repository 保持同步。基于 XML 的接口通过提供表示分类信息的规范格式,并使用 WebSphere Service Registry and Repository 提供的 JMX 接口,以编程方式将分类加载到 WebSphere Service Registry and Repository 中,从而解决了这些问题。
背景
类别分类为您提供了一种组织 WebSphere Service Registry and Repository 中的服务和服务元数据的方法。将各种服务和关联的元数据元素分类为适当类别的能力,是有效治理和管理的重要支持功能之一。分类系统通常包含分类的层次结构,这些分类定义了该分类中的实体。WebSphere Service Registry and Repository 通过 OWL 本体定义文件的定义来支持使用类别分类,该文件根据分类和子分类来布置分类系统。虽然 OWL 本体能够以具有丰富语义的方式定义实体和关系,但是适合用于在 WebSphere Service Registry and Repository 中定义分类系统的本体定义仅采用了这些功能的有限子集,特别是分类和子分类(有关 OWL 的更多信息,请参阅参考资料)。
目前,WebSphere Service Registry and Repository 提供了基于 Web 的简单 UI 来定义类别分类和包含分类。(有关该 UI 的更多详细信息,请参阅参考资料中的 WebSphere Service Registry and Repository 产品信息中心链接。)WebSphere Service Registry and Repository 还提供了一个基于 JMX 的 API,用于加载已经定义为 OWL 本体的类别分类。其他实用工具提供了各种方法,允许以文本文件格式指定类别分类以创建 OWL 文件,然后您可以将这些文件加载到 WebSphere Service Registry and Repository 中(有关更多信息,请参阅文章“Creating customized classification systems with WebSphere Service Registry and Repository V6.0.0.1 and higher” 和“Creating business model templates with WebSphere Service Registry and Repository V6.1”)。
本文描述的实用工具(和方法)也称为 WSRRClassificationLoader,它使用规范 XML 格式来布置类别分类,使用可扩展样式表语言(Extensible Stylesheet Language,XSL)转换将其转换为 OWL 文件,并使用 JMX API 将类别分类加载到 WebSphere Service Registry and Repository 中。你可以利用和扩展此方法,将其作为在多个系统中维护分类的同步机制,包括 WebSphere Service Registry and Repository。
规范 XML Schema 格式
规范 XML Schema 格式指定了能够在 WebSphere Service Registry and Repository 中可表示的类别分类中定义的元素。这种简单 Schema 格式捕获类别分类的元素,用户可以使用 WebSphere Service Registry and Repository UI 手动输入这些元素以创建类别分类。根元素应该是 ClassificationTaxonomy 类型。ClassificationTaxonomy 中必需的元素是 name 和 URI。comment 元素是可选的,此元素指定类别分类的描述。可选地,可以使用 nameLanguageVariants 和 commentLanguageVariants 元素以替代语言指定 name 和 comment 元素的变体。这些变体的类型为 LanguageVariant,需要指定 language 和 translation 元素,其中 language 表示替代语言的语言代码,translation 是该元素在指定的替代语言中的表示形式。图 1 显示了规范 XML Schema 的重要元素的图形表示。
图 1. 规范 XML Schema
ClassificationTaxonomy 下的 rootNodes 元素表示构成该分类层次结构的根节点的分类列表。该元素的类型为 Node,需要 id 和 name 元素,其中 id 表示该节点在整个类别分类下的唯一标识符,name 表示该节点的用户友好的名称。您可以为 Node 指定可选的 comment 元素。与 ClassificationTaxonomy 类型相似,Node 类型可以包含 name 和 comment 元素的其他语言变体。但是要注意,附加的语言元素需要与在 ClassificationTaxonomy 级别指定的语言元素相同。例如,当您在 ClassificationTaxonomy 级别仅指定了法语语言变体之后,不能在 Node 级别指定德语语言变体。Node 类型又可以在 childrenNodes 元素之下包含其他 Node 类型,从而建立类别分类的树形结构。图 2 显示了使用规范 XML Schema 格式表示的类别分类的示例。
图 2. 假想的 IBM 组织分类
XSL 转换方法
在使用规范 XML 格式定义类别分类之后,WSRRClassificationLoader 实用工具将读取并验证该 XML 文件。在验证之后,将使用 XSL 转换(XSL transformation,XSLT)将该 XML 文件中指定的类别分类转换为对应的 OWL 文件格式。对于没有经验的人来说,XSLT 通常用于将一个 XML 文档转换为另一个 XML 文档。在此例中,则是将符合规范模式的 XML 文档转换为 OWL 文档。classificationTaxonomy 元素转换为 OWL ontology 元素。使用 XSL 转换,Node 元素 rootNodes 和 childrenNodes 分别转换为 OWL Class 和 subClassOf 元素。(有关用于转换的 XSLT 代码片段,请参见图 3。请参阅下载部分以获取完整的 XSLT。)
图 3. 用于创建 OWL 的 XSL 转换
将类别分类加载到 WebSphere Service Registry and Repository 中
如前所述,WSRRClassificationLoader 实用工具使用 WebSphere Service Registry and Repository 提供的 JMX API 来将类别分类加载到 WebSphere Service Registry and Repository 中。下一个部分将简要地描述 WebSphere Service Registry and Repository 提供的 JMX API 方法。(提供所有 JMX API 方法的描述超出了本文的范围。有关 WebSphere Service Registry and Repository 提供的其他 API 的信息,请阅读文章“使用 JAX-RPC 访问 IBM WebSphere Service Registry and Repository” 和“Introducing WebSphere Service Registry and Repository APIs”。)
WebSphere Service Registry and Repository 的 JMX API
WebSphere Service Registry and Repository 管理接口 (JMX) 提供了一个 API,用于管理控制 WebSphere Service Registry and Repository 运行时行为的配置设置。这包括诸如加载和删除分类系统以及设置访问控制策略等功能。WebSphere Service Registry and Repository 在部署它的 IBM WebSphere Application Server MBean 服务器上注册了一个托管 Bean (MBean) (WebSphere:*,type=ServiceRegistryRepository)。此外,ServiceRegistryClient.jar 中提供了一个名为 ServiceRegistryRepositoryProxy 的客户端代理,此代理可以简化该 Mbean 上的连接和调用操作。这个类提供了有用的抽象,并使用底层的标准 Mbean 客户端代码来调用必要的 Mbean 操作。特别是,要调用 WebSphere Service Registry and Repository Mbean 上的操作,您需要:
- 获取
ServiceRegistryRepositoryProxy 类的一个实例。
- 根据 WebSphere Service Registry and Repository MBean API 的需要准备参数。
- 调用代理类中的适当方法,并传递必需的参数。
- 处理该操作所报告的任何异常。
就 WSRRClassificationLoader 实用工具而言,Mbean API 上的 createOntologySystem 和 deleteOntologySystem 方法是通过 ServiceRegistryRepositoryProxy 调用的。
配置和运行 WSRRClassificationLoader
WSRRClassificationLoader 实用工具(以及源代码)可通过本文的下载部分进行下载。该实用工具作为 .jar 文件提供,并附带了关联的规范 Schema 定义 (WSRRClassification.xsd)、XSLT 文件 (WSRRClassificationXMLtoOWL.xsl) 和示例类别分类输入文件。您可以使用简单的属性文件 WSRRClassificationLoader.properties 来配置该实用工具,此属性文件也是提供了的。有关各个配置参数的含义是什么的详细说明,请参见该实用工具包括的示例配置文件。清单 1 显示了一个示例配置。
清单 1. WSRRClassificationLoader 的示例配置
inputXMLFile = sample/IBM-Taxonomy.xml
outputOWLFile = sample/IBM-Taxonomy.owl
generateIds = true
loadWSRR = true
wsrr.secure = false
wsrr.host = localhost
wsrr.port = 8881
wsrr.username =
wsrr.password =
wsrr.trustStorePath =
wsrr.keyStorePath =
wsrr.trustStorePassword =
wsrr.keyStorePassword =
|
在为配置元素设置正确的值以后,您可以使用所提供的简单脚本来调用该实用工具:wsrr-classification-load.bat。图 4 显示了该实用工具的成功执行示例。
图 4. WSRRClassificationLoader 的示例执行
在 WebSphere Service Registry and Repository 中导航到 Configuration 透视图,并检查新创建的名为 IBM SOA Governance Taxonomy 的类别分类。新创建的分类中的具体分类应该与图 5 所示的分类类似。
图 5. WebSphere Service Registry and Repository 中加载的示例 IBM 组织分类
语言变体支持
如前所述,WebSphere Service Registry and Repository 提供了一种为类别分类的相关部分指定替代语言变体的机制。这包括主体的 name 和 comment 部分,以及类别分类中定义的所有分类。因此,规范 Schema 格式允许指定这些以及可选的元素。图 6 显示了本文前面提供的相同类别分类的示例,不过现在使用语言变体进行了增强。
图 6. 带语言变体的示例 IBM 组织分类
使用所提供的示例将带语言变体的类别分类加载到 WebSphere Service Registry and Repository 中。加载之后,类别分类的语言变体部分应该会显示出来,如图 7 所示。
图 7. WebSphere Service Registry and Repository 中加载的带语言变体的示例 IBM 组织分类
结束语
您已经了解了使用基于规范 XML Schema 的格式和 JMX API 以编程方式将类别分类加载到 WebSphere Service Registry and Repository 中的机制。如果您需要将从其他 IT 系统提取的类别分类加载到 WebSphere Service Registry and Repository 中,并根据需要定期更新或同步 WebSphere Service Registry and Repository 中的类别分类,则此方法应该非常适合于此类情况。
致谢
作者要感谢 Majeed Arni,是他的讨论和建议导致了本文的面世。
下载 | 描述 | 名字 | 大小 | 下载方法 |
|---|
| Classification loader sample code | WSRRClassificationLoader.zip | 24KB | HTTP |
|---|
参考资料 学习
获得产品和技术
讨论
关于作者  | 
|  | Subhash Kumar 是 IBM Software Services for WebSphere 组织的一名 IBM 认证 SOA 解决方案设计师和顾问。他的工作重点是 SOA 解决方案的设计、开发和部署,并使用和增强 IBM 的 SOA 中间件产品。在此之前,Subhash 担任 IBM Software Group 的 SOA Advanced Technologies 团队的开发工程师,为 IBM 的软件产品做出了重要贡献,包括 IBM WebSphere Registry and Repository、IBM Rational Asset Manager 和 IBM WebSphere Message Broker。 |
对本文的评价
|