问题描述
我正在尝试使用 XJC 将 XML 加密的 XML 模式映射到与 JAXB (https://www.w3.org/TR/xmlenc-core/xenc-schema.xsd) 一起使用的 Java 类。
我对 EncryptionMethodType
类型的映射有点困惑。在模式中,它被定义为
<complexType name='EncryptionMethodType' mixed='true'>
<sequence>
<element name='KeySize' minOccurs='0' type='xenc:KeySizeType'/>
<element name='OAEPparams' minOccurs='0' type='base64Binary'/>
<any namespace='##other' minOccurs='0' maxOccurs='unbounded'/>
</sequence>
<attribute name='Algorithm' type='anyURI' use='required'/>
</complexType>
@XmlAccessorType(XmlAccesstype.FIELD)
@XmlType(name = "EncryptionMethodType",propOrder = {
"content"
})
public class EncryptionMethodType {
@XmlElementRefs({
@XmlElementRef(name = "KeySize",namespace = "http://www.w3.org/2001/04/xmlenc#",type = JAXBElement.class,required = false),@XmlElementRef(name = "OAEPparams",required = false)
})
@XmlMixed
@XmlAnyElement(lax = true)
protected List<Object> content;
@XmlAttribute(name = "Algorithm",required = true)
@XmlSchemaType(name = "anyURI")
protected String algorithm;
/**
* Objects of the following type(s) are allowed in the list
* {@link JAXBElement }{@code <}{@link BigInteger }{@code >}
* {@link JAXBElement }{@code <}{@link byte[]}{@code >}
* {@link String }
* {@link Object }
*/
public List<Object> getContent() {
if (content == null) {
content = new ArrayList<Object>();
}
return this.content;
}
public String getAlgorithm() {
return algorithm;
}
public void setAlgorithm(String value) {
this.algorithm = value;
}
}
我不是 JAXB 专家(而且文档很少而且大多很糟糕),但是由于 KeySize
和 OAEPparams
元素的基数为 0 或 1,我希望它们成为单独的属性在 Java 代码中,为无界 List<Object>
元素保留 ##other
。
我可以应用任何参数或自定义绑定来获得更简单的 Java 表示,即像这样吗?
class EncryptionMethodType {
public BigInteger KeySize;
public byte[] OAEPparams;
public List<Object> otherContent;
}
提前致谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)