gpt4 book ai didi

java - JAXB SCD 无法与 annox 一起使用

转载 作者:太空宇宙 更新时间:2023-11-04 06:49:09 26 4
gpt4 key购买 nike

我在让 JAXB 绑定(bind)文件与 annox 和 SCD 元素选择一起使用时遇到困难。该模式是一个简单的基本模式,具有名为 SongType 的 ComplexType。我尝试了正常的方法做如下的事情,一切都很顺利,类被命名为 Song 而不是 SongType 并且还有 Deprecated 注释。

<jaxb:bindings node="/xsd:schema" schemaLocation="example.xsd">
<jaxb:bindings node="xsd:complexType[@name='SongType']">
<jaxb:class name="Song"/>
<annox:annotateClass>
<annox:annotate annox:class="java.lang.Deprecated"/>
</annox:annotateClass>
</jaxb:bindings>
</jaxb:bindings>

但是当我尝试对 jaxb scd 引用执行相同操作时,XJC 只是失败并出现 xerces 异常,提示它不知道存在的 annox 元素。谁能对这里的问题提出建议?

<jaxb:bindings scd="x-schema::tns" xmlns:tns="http://www.fleurida.com/blueprint">
<jaxb:bindings scd="~tns:SongType">
<jaxb:class name="Song"/>
<annox:annotateClass>
<annox:annotate annox:class="java.lang.Deprecated"/>
</annox:annotateClass>
</jaxb:bindings>
</jaxb:bindings>

错误跟踪:

[INFO] Parsing input schema(s)...[ERROR] Error while parsing schema(s).Location [ file:/dev/oss/jaxb-scd-annox-problem/src/main/resources/scd.annox.jaxb.xml{8,25}].org.xml.sax.SAXParseException; systemId: file:/dev/oss/jaxb-scd-annox-problem/src/main/resources/scd.annox.jaxb.xml; lineNumber: 8; columnNumber: 25; cvc-elt.1: Cannot find the declaration of element 'annox:annotateClass'.        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1906)        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:746)        at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:570)        at com.sun.tools.xjc.util.ForkContentHandler.startElement(ForkContentHandler.java:114)        at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:551)        at com.sun.tools.xjc.reader.internalizer.DOMForestScanner$LocationResolver.startElement(DOMForestScanner.java:147)        at com.sun.xml.bind.unmarshaller.DOMScanner.visit(DOMScanner.java:244)        at com.sun.xml.bind.unmarshaller.DOMScanner.scan(DOMScanner.java:127)        at com.sun.tools.xjc.reader.internalizer.DOMForestScanner.scan(DOMForestScanner.java:92)        at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet$Target.apply(SCDBasedBindingSet.java:184)        at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet$Target.applyAll(SCDBasedBindingSet.java:142)        at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet$Target.apply(SCDBasedBindingSet.java:163)        at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet$Target.applyAll(SCDBasedBindingSet.java:142)        at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet$Target.access$700(SCDBasedBindingSet.java:86)        at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet.apply(SCDBasedBindingSet.java:241)        at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:541)        at com.sun.tools.xjc.ModelLoader.loadXMLSchema(ModelLoader.java:378)        at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174)        at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119)        at org.jvnet.mjiip.v_2_2.XJC22Mojo.loadModel(XJC22Mojo.java:58)        at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:44)        at org.jvnet.mjiip.v_2_2.XJC22Mojo.doExecute(XJC22Mojo.java:29)        at org.jvnet.jaxb2.maven2.RawXJC2Mojo.doExecute(RawXJC2Mojo.java:364)        at org.jvnet.jaxb2.maven2.RawXJC2Mojo.execute(RawXJC2Mojo.java:161)        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)        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:108)        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)        at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)        at java.lang.reflect.Method.invoke(Method.java:606)        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

github 上的完整记录且可运行的示例

最佳答案

这是由于 XJC 中的问题造成的,据报道 here .

简而言之,Annox 使用供应商扩展(即特殊配置元素,如 annox:annotate),目前基于 SCD 的绑定(bind)不支持这些扩展。

不幸的是,我不相信这个问题会很快得到解决。请改用 node Bindigs。

顺便说一句,我也将 Annox 移至 GitHub:

您现在可以使用 Java 语法进行注释:

<xsd:complexType name="FooType">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate>@java.lang.SuppressWarnings({"unchecked","rawtypes"})</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence> ...</xsd:sequence>
</xsd:complexType>

关于java - JAXB SCD 无法与 annox 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23570003/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com