jaxb2简化了xs:choice的具有相同类型的插件 [英] jaxb2 simplify plugin for xs:choice having same types

查看:119
本文介绍了jaxb2简化了xs:choice的具有相同类型的插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将jaxb2基础简化插件用于我的架构到JAXB的转换. 对于下面的复杂类型,它工作正常.在xs:choice内部定义的每个元素都有不同的类型(type1type2).

I'm trying to use jaxb2 basics simplify plugin for my schema to JAXB conversion. It works fine for the complex types like below. Each element is defined inside the xs:choice has different types (type1 and type2).

sample.xsd(具有不同类型的复杂选择类型)

<xs:complexType name="doclist">
    <xs:sequence>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:annotation>
                <xs:appinfo>
                    <simplify:as-element-property />
                </xs:appinfo>
            </xs:annotation>
            <xs:element name="document1" type="type1" />
            <xs:element name="document2" type="type2" />
        </xs:choice>
    </xs:sequence>
    <xs:attribute name="heading" type="xs:string" />
</xs:complexType>

但是,如果复杂类型包含多个具有相同类型(xs:string)的元素,如下所示,则maven安装会引发错误.

But if the complex type contains more than one element with same type (xs:string), as shown below, then maven install throws error.

sample.xsd(具有相同类型的复杂选择类型)

<xs:complexType name="addressTEST">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
            <xs:appinfo>
                <simplify:as-element-property />
            </xs:appinfo>
        </xs:annotation>
        <xs:element name="street" type="xs:string" />
        <xs:element name="city" type="xs:string" />
    </xs:choice>
</xs:complexType>

如果我为多个元素使用相同类型, jaxb2简化是否行不通?

Does jaxb2 simplify will not work if I have same types for more than one elements ?

[ERROR] Error while parsing schema(s).Location [ file:/D:/workspace/trunk/sampmes/src/main/resources/sample.xsd{1099,38}].
com.sun.istack.SAXParseException2: compiler was unable to honor this as-element-property customization. It is attached to a wrong place, or its inconsistent with other bindings.
    at com.sun.tools.xjc.ErrorReceiver.error(ErrorReceiver.java:82)
    at com.sun.tools.xjc.reader.xmlschema.ErrorReporter.error(ErrorReporter.java:79)
    at com.sun.tools.xjc.reader.xmlschema.UnusedCustomizationChecker.check(UnusedCustomizationChecker.java:144)
    at com.sun.tools.xjc.reader.xmlschema.UnusedCustomizationChecker.check(UnusedCustomizationChecker.java:122)
    at com.sun.tools.xjc.reader.xmlschema.UnusedCustomizationChecker.modelGroup(UnusedCustomizationChecker.java:220)
    at com.sun.xml.xsom.impl.ModelGroupImpl.visit(ModelGroupImpl.java:125)
    at com.sun.tools.xjc.reader.xmlschema.UnusedCustomizationChecker.particle(UnusedCustomizationChecker.java:241)
    at com.sun.xml.xsom.impl.ParticleImpl.visit(ParticleImpl.java:124)
    at com.sun.tools.xjc.reader.xmlschema.UnusedCustomizationChecker.complexType(UnusedCustomizationChecker.java:182)
    at com.sun.xml.xsom.impl.ComplexTypeImpl.visit(ComplexTypeImpl.java:295)
    at com.sun.tools.xjc.reader.xmlschema.UnusedCustomizationChecker.run(UnusedCustomizationChecker.java:108)
    at com.sun.tools.xjc.reader.xmlschema.UnusedCustomizationChecker.run(UnusedCustomizationChecker.java:98)
    at com.sun.tools.xjc.reader.xmlschema.BGMBuilder._build(BGMBuilder.java:187)
    at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:116)
    at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:415)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:167)
    at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:113)
    at org.jvnet.mjiip.v_2_1.XJC21Mojo.loadModel(XJC21Mojo.java:50)
    at org.jvnet.mjiip.v_2_1.XJC21Mojo.doExecute(XJC21Mojo.java:40)
    at org.jvnet.mjiip.v_2_1.XJC21Mojo.doExecute(XJC21Mojo.java:28)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:505)
    at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:328)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

推荐答案

它应该可以工作,但是请尝试自定义xs:element之一.

It should work, but try customizing one of the xs:elements instead.

根据生成的属性类型,您需要自定义xs:choice或子级xs:elements之一.

Depending on the property type produced, you'll need to customize either xs:choice or one of the child xs:elements.

如果获得元素"属性,请自定义xs:choice.参见文档.这是第一种情况.

If you get an "elements" property, customize xs:choice. See the documentation. This is what you have in the first case.

如果获得元素引用"属性,请自定义xs:elements之一.参见文档.这是第二种情况.

If you get an "element references" property, customize one of the xs:elements. See the documentation. This is what you have in the second case.

这篇关于jaxb2简化了xs:choice的具有相同类型的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆