Java:JAX-WS Mapping [英] Java: JAX-WS Mapping

查看:119
本文介绍了Java:JAX-WS Mapping的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JAX-WS进行Web服务。

I am using JAX-WS for web services.

每当我使用char作为方法参数时,我将其作为xsd中的unsignedShort(Focus on weatherLetter)。

Whenever I use a char as a method parameter, I am getting it as an unsignedShort in the xsd (Focus on weatherLetter).

以下是声明:

@WebMethod
public boolean setWXtatus(
        @WebParam(name = "weatherLetter") char weatherLetter,
        @WebParam(name = "weatherDigit") int weatherDigit,
        @WebParam(name = "cloudCover") int cloudCover,
        @WebParam(name = "cloudBaseInHundredsOfFeet") int cloudBaseInHundredsOfFeet,
        @WebParam(name = "pressureInHg") int pressureInHg,
        @WebParam(name = "visibilityInKm") int visibilityInKm,
        @WebParam(name = "windSpeed") int windSpeed,
        @WebParam(name = "windDirection") int windDirection,
        @WebParam(name = "lastUpdateHour") int lastUpdateHour,
        @WebParam(name = "lastUpdateMin") int lastUpdateMin
) 

这是我得到的类型映射:

Here is the type mappings I get:

<xs:complexType name="setWXStatus">
<xs:sequence>
<xs:element name="weatherLetter" type="xs:unsignedShort" minOccurs="0"/>
<xs:element name="weatherDigit" type="xs:int"/>
<xs:element name="cloudCover" type="xs:int"/>
<xs:element name="cloudBaseInHundredsOfFeet" type="xs:int"/>
<xs:element name="pressureInHg" type="xs:int"/>
<xs:element name="visibilityInKm" type="xs:int"/>
<xs:element name="windSpeed" type="xs:int"/>
<xs:element name="windDirection" type="xs:int"/>
<xs:element name="lastUpdateHour" type="xs:int"/>
<xs:element name="lastUpdateMin" type="xs:int"/>
</xs:sequence>
</xs:complexType>

如何将weatherLetter生成为Char或1个字符串或其他内容?

How can I get weatherLetter to generate as a Char or 1 Letter String or something?

推荐答案

更新:

一种方法是XSD(如果你首先签约),例如直接添加 XSD限制,例如

One way to do this is the in XSD (if you do contract first) e.g. add an XSD Restriction to it directly, e.g.

<xs:element name="singleChar">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:length value="1"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

但我认为问题是最后合约(例如编写代码,生成XSD,反之亦然)

But I think the question is on contract last (e.g. write code that generates the XSD, not vice versa)

据我所知,这在JAX-WS或JAXB中尚不支持(但是一个很好的增强请求)

This is not yet supported in JAX-WS or JAXB, as far as I know (but a nice enhancement request)

来源:

JAX-WS和JAXB不支持代码生成来自XSD的限制(例如xsd:restriction)
http://old.nabble.com/Does-jaxb-2.1-enforce-xs:restriction-td21348458.html

JAX-WS and JAXB don't have support for code generation for restrictions from XSD (e.g. xsd:restriction) http://old.nabble.com/Does-jaxb-2.1-enforce-xs:restriction-td21348458.html

原因是其他方向(通过注释产生限制)也不受支持

The reason is that the other direction (generating restrictions by Annotation), is not supported too

解决方法:

看看这个: http://download.oracle .com / docs / cd / E17802_01 / webservices / webservices / docs / 1.5 / tutorial / doc / JAXBUsing4.html

还有这个问题:

JAX-WS和Joda-Time?

没有做到你想要的,但让你更近一点

Not doing exactly what you want, but getting you a little bit closer

我不认为你可以将它限制为1个字符串任何其他方式,一个char确实是一个无符号的short,并且最接近你可以限制为1Stringchar。

I don't think you can have it limited to 1 char any other way, a char is indeed an unsigned short, and the closest thing you can to limiting to 1 "String" char.

如果您使用字符串,您将允许无限制的字符。并且 @WebParam 没有用于限制长度的API

If you use a String, you will allow unlimited chars. and @WebParam doesn't have an API to limit length

实际上我没有看到使用JAX-WS完全做XSD限制的方法,但我可能错了

Actually I didn't see a way to do XSD restrictions at all using JAX-WS, but I may be wrong

这篇关于Java:JAX-WS Mapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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