我们正在使用JAXB来处理wsdl验证。在wsdl中,我们有这样一个枚举:
<xs:simpleType name="myEnum">
<xs:annotation>
<xs:documentation>The enums which matter.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="MYENUM_1">
<xs:annotation>
<xs:documentation>MYENUM_1 is the first enum.</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="MYENUM_2">
<xs:annotation>
<xs:documentation>MYENUM_2 is the second enum.</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
package com.sun.xml.bind.v2.model.impl;
//...
public T parse(CharSequence lexical) throws AccessorException, SAXException {
// TODO: error handling
B b = baseXducer.parse(lexical);
if(b==null) {
return null;
}
return parseMap.get(b);
}
很明显,parseMap是我们的枚举列表,但是如果映射的键(在本例中是b值)不在映射中,它只返回null。如果b不在parseMap中,我们希望它抛出和某种异常。
除了修复这个问题并重新编译我们自己的JAXB之外,还有其他方法来解决这个问题吗?
我们使用的是JAXB2.1.9,我们希望对数据进行解组和验证。当然,我可能忽略了文档中有关验证的某些内容。