如何解决限制值以在soap Web 服务中发送
我创建了一个soap web服务和一个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 描述 - 也许它有帮助:
A.标准方式
RegularExpression re = new RegularExpression(regex);
if (re.matches(text)) { ... }
B.捕获组
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
在我看来,我建议采用契约/WSDL-first 方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。