微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JAXB - XJC - 将 XML 加密模式映射到 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",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 专家(而且文档很少而且大多很糟糕),但是由于 KeySizeOAEPparams 元素的基数为 0 或 1,我希望它们成为单独的属性在 Java 代码中,为无界 List<Object> 元素保留 ##other

我可以应用任何参数或自定义绑定来获得更简单的 Java 表示,即像这样吗?

class EncryptionMethodType {
   public BigInteger KeySize;
   public byte[] OAEPparams;
   public List<Object> otherContent;
}

提前致谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。