在类型生成期间使用jaxb绑定替换XmlType.namespace [英] Replacing XmlType.namespace using jaxb bindings during type generation

查看:226
本文介绍了在类型生成期间使用jaxb绑定替换XmlType.namespace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web服务应用程序正在从Axis迁移到JAX-WS,并且在进行某些转换时遇到了麻烦.我的主要问题是,我有几个XSD,它们的相同类型定义略有不同,但名称相同.在wsimport期间,我可以使用外部JAXB绑定文件来解析软件包,但是生成的类仍然以相同的@XmlType批注结尾.

My web-services application is moving from Axis to JAX-WS and I'm having trouble doing some of the conversions. My primary issue is that I have several XSD's with the same types defined slightly differently, but with the same names. During my wsimport I'm able to use an external JAXB bindings file to resolve the packages, but the generated classes still end up with the same @XmlType annotations.

V1:

package com.service.v1.bill.request;
@XmlType(name = "FileBillReqType", namespace = "http://epayments.metavante.com/types/bill/request"})
public class FileBillReqType extends AbstractContextMethodRequest...

V2:

package com.service.v2.bill.request;
@XmlType(name = "FileBillReqType", namespace = "http://epayments.metavante.com/types/bill/request"})
public class FileBillReqType extends AbstractContextMethodRequest...

绑定:

<jaxb:bindings schemaLocation="file:../wsdl/v1/bill/BillRequest.xsd" 
    node="/xs:schema[@targetNamespace='http://service.example.com/bill/request']">
    <jaxb:schemaBindings>
        <jaxb:package name="com.service.v1.bill.request" />
    </jaxb:schemaBindings>
</jaxb:bindings>

以前,这可以通过axis提供的类型映射解决(我们将其硬编码为一个非常丑陋的wsdd):

Previously this would have been resolved with the type mappings provided by axis (which we hard coded into a massively ugly wsdd):

<service name="v1" provider="java:RPC" style="document" use="literal">...
<typeMapping
    xmlns:ns="http://service.example.com/bill/request"
    qname="ns:FileBillReqType"
    type="java:com.service.v1.bill.request.FileBillReqType"
    serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
    deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
    encodingStyle=""
  />...

无论如何,是否有使我生成的JAXB对象具有自定义名称空间的功能,而无需在每次重新生成它们时手动修改生成的文件(有数百个)?

Is there anyway to get my generated JAXB objects to have a custom namespace without modifying the generated files manually every time I regenerate them (there are hundreds)?

推荐答案

在使用wsimport生成客户端类的同时,使用v2作为架构位置指定另一个xjb定制可能会解决此问题.

Specifying another xjb customization with v2 as schema location while generating the client classes using wsimport might solve the problem.

<jaxb:bindings schemaLocation="file:../wsdl/v2/bill/BillRequest.xsd"
node="/xs:schema[@targetNamespace='http://service.example.com/bill/request']">
    <jaxb:schemaBindings>
        <jaxb:package name="com.service.v2.bill.request" />
    </jaxb:schemaBindings>
</jaxb:bindings>

这篇关于在类型生成期间使用jaxb绑定替换XmlType.namespace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆