java - JAXB - XJC - 将 XML 加密模式映射到 Java 类
问题描述
我正在尝试使用 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>
XJC 生成以下类型(为简洁起见,已删除注释):
@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", namespace = "http://www.w3.org/2001/04/xmlenc#", type = JAXBElement.class, 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;
}
提前致谢!
解决方案
推荐阅读
- javascript - Promises Sequencing
- c# - 使用 zkemkeeper.dll 进行访问控制,但不使用 #application.for zkteco c3-100 设备解锁
- spring-boot - 使用枚举过滤状态
- pytorch - 在每一行中选择/屏蔽不同的列索引
- linux - 在 Alt push 上 Manjaro Xfce 中基于电子的应用程序中的焦点丢失
- android - 从 ArrayAdapter 中的项目从 ListView 更改为 DetailView
- flutter - 从颤动的图像选择器中选择图像后,如何在图像上实现删除图标?
- c++ - Can't recolor edges in vtk
- javascript - designing three dimensional relationships with ORM (TypeORM)
- java - 我无法在 geofire 的关键出口处删除地图上的标记