限制在 soap web 服务中发送的值

Restrict values to send in a soap web service

我已经创建了一个 soap 网络服务和一个 xml 验证器,我想知道是否有任何注释可以用来限制在任何字段中发送的值,例如:

   @XmlType
public class ContactoBean implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 6034293066688534650L;

    @XmlElement(required = true)
    private String emailContacto;
    
    @XmlElement(required = true)
    private String telfContacto;
    
    @XmlElement(required = false)
    private String faxContacto;

是否有任何注释可以在电话中使用正则表达式来验证号码是否正确?或验证电子邮件的更正?

此致

您采用的是代码优先方法还是合同优先方法(根据 WSDL+XSD 文件生成 类)?

如果是后者,您可以使用 xsd:patterns 定义所需的正则表达式来扩展相关的 XSD 类型。

示例:

<xsd:element name="elementName">
    <xsd:simpleType>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="[^*+]"></xsd:pattern>
        </xsd:restriction>
    </xsd:simpleType>
</xsd:element>    

XMLBeans 应该为您生成必要的 类、getter 和 setter。

但是如果您直接通过 Java 代码创建 Web 服务,我假设您需要使用标准 Java 正则表达式方法。我找到了 org.apache.xmlbeans.impl.regex.RegularExpression 的以下描述 - 可能有帮助:

一个。标准方式

RegularExpression re = new RegularExpression(regex);
if (re.matches(text)) { ... }

乙。捕获组

RegularExpression re = new RegularExpression(regex);
Match match = new Match();
if (re.matches(text, match)) {
    ... // You can refer captured texts with methods of the Match class.
}

不区分大小写匹配

RegularExpression re = new RegularExpression(regex, "i");
if (re.matches(text) >= 0) { ...}

选项

You can specify options to RegularExpression(regex, options) or setPattern(regex, options). This options parameter consists of the following characters.

"i"
This option indicates case-insensitive matching.
"m"
^ and $ consider the EOL characters within the text.
"s"
. matches any one character.
"u"
Redefines \d \D \w \W \s \S \b \B \< \> as becoming to Unicode.
"w"
By this option, \b \B \< \> are processed with the method of 'Unicode Regular Expression Guidelines' Revision 4. When "w" and "u" are specified at the same time, \b \B \< \> are processed for the "w" option.
","
The parser treats a comma in a character class as a range separator. [a,b] matches a or , or b without this option. [a,b] matches a or b with this option.
"X"
By this option, the engine confoms to XML Schema: Regular Expression. The match() method does not do subsring matching but entire string matching.

来源:http://www.docjar.com/docs/api/org/apache/xmlbeans/impl/regex/RegularExpression.html

在我看来,我会建议 contract-/WSDL-first 方法。