无法使用JAXB编排XBRL实例

3
我正在尝试使用JAXB创建XBRL实例。我已经成功地使用xjc基于xbrl-instance模式(http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd)创建了Java模型。

在使用xjc创建Java类时,我遵循了这篇文章的建议(除了maven部分,因为我没有使用它):JAXB fails to generate Java classes for XBRL

xbrl_bindings.xjb:

<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" version="2.1">
    <bindings schemaLocation="xl-2003-12-31.xsd" version="1.0">
        <bindings node="//xs:schema//xs:element[@name='title']">
            <property name="xlTitle"/>
        </bindings>
    </bindings>
</bindings>

现在我正在尝试生成一个XBRL实例,但是在初始化上下文时出现了Java.lang.IllegalArgumentException。我找到了另一篇帖子,建议通过引用包和ObjectFactory(使用类加载器)来调用newInstance()。但是错误仍然发生,我无法从堆栈跟踪中提取任何有用的信息。

编组代码:

public class JaxbXbrlInstanceCreationTest {

    public static void main(String[] args) {

        org.xbrl._2003.instance.ObjectFactory instObjFact = new ObjectFactory();
        Xbrl xbrl = instObjFact.createXbrl();
        xbrl.setId("Test");

        org.xbrl._2003.linkbase.ObjectFactory linkbaseObjFact = new org.xbrl._2003.linkbase.ObjectFactory();
        org.xbrl._2003.xlink.ObjectFactory xlinkObjFact = new org.xbrl._2003.xlink.ObjectFactory();
        org.xbrl._2003.xlink.SimpleType schemaRefvalue = xlinkObjFact.createSimpleType();

        schemaRefvalue.setHref("http://eiopa.europa.eu/eu/xbrl/s2md/fws/solvency/solvency2/2014-07-23/mod/ars.xsd");
        schemaRefvalue.setType("simple");
        List<SimpleType> schemaRefList = xbrl.getSchemaRef();
        schemaRefList.add(linkbaseObjFact.createSchemaRef(schemaRefvalue).getValue());

        List<Object> contextList = xbrl.getItemOrTupleOrContext();

        Context context = instObjFact.createContext();
        context.setId("Context");

        ContextEntityType entityType = instObjFact.createContextEntityType();
        Identifier identifier = new Identifier();
        identifier.setValue("someone");
        identifier.setScheme("http://www.example.com");
        entityType.setIdentifier(identifier);
        context.setEntity(entityType);

        ContextPeriodType contextPeriodType = instObjFact.createContextPeriodType();
        contextPeriodType.setInstant("2014-02-28");
        context.setPeriod(contextPeriodType);

        ContextScenarioType contextScenarioType = instObjFact.createContextScenarioType();
        context.setScenario(contextScenarioType);

        contextList.add(context);

        try {
            //JAXBContext jaxbContext = JAXBContext.newInstance(Xbrl.class, org.xbrl._2003.instance.ObjectFactory.class);
            JAXBContext jaxbContext = JAXBContext.newInstance("org.xbrl._2003.instance", org.xbrl._2003.instance.ObjectFactory.class.getClassLoader());
            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
            marshaller.marshal( xbrl, new FileOutputStream( "C:/Users/peter.goldenbogen/Desktop/test.xbrl" ) );

        } catch (JAXBException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

堆栈跟踪:

Exception in thread "main" java.lang.IllegalArgumentException: can't parse argument number: ''{0}''
    at java.text.MessageFormat.makeFormat(Unknown Source)
    at java.text.MessageFormat.applyPattern(Unknown Source)
    at java.text.MessageFormat.<init>(Unknown Source)
    at java.text.MessageFormat.format(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.Messages.format(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.ReferencePropertyInfoImpl.calcTypes(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.ReferencePropertyInfoImpl.link(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.ClassInfoImpl.link(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeClassInfoImpl.link(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.ModelBuilder.link(Unknown Source)
    at com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder.link(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at de.sample.test.JaxbXbrlInstanceCreationTest.main(JaxbXbrlInstanceCreationTest.java:76)
Caused by: java.lang.NumberFormatException: For input string: "''{0}''"
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    ... 27 more

我认为这与已经报告的问题有关:https://java.net/jira/browse/JAXB-1017。但我仍然想知道哪个元素引起了冲突? - nouseforaname
我假设真正的异常导致了错误消息的产生,而错误消息格式遇到了问题。日志记录的是英语(en_us)消息还是其他语言? - bdoughan
这是德语,这导致了误导性的错误信息。 - nouseforaname
你能否将你的环境切换成英文,以获取一个新的错误信息? - bdoughan
你知道语言设置从哪里派生出来的吗?更改Win 8操作系统语言设置时似乎是相同的。 - nouseforaname
请参见:https://dev59.com/MWoy5IYBdhLWcg3wCpzQ - bdoughan
1个回答

7
我通过发现实际的堆栈跟踪信息是误导性的,因为在翻译 jaxb 错误消息时会出现已知的错误,从而解决了我的问题。请参见此处:https://java.net/jira/browse/JAXB-1017 最终,我的 jaxb 上下文调用仍然存在问题,我通过在一个字符串中引用所有包并用冒号分隔来解决它。
JAXBContext jaxbContext = JAXBContext.newInstance("org.xbrl._2003.instance:org.xbrl._2003.linkbase:org.xbrl._2003.xlink");

编辑:

更改语言环境可以获得更详细的错误信息:

Locale.setDefault(Locale.ENGLISH);` 

输出:

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
There's no ObjectFactory with an @XmlElementDecl for the element {http://www.xbrl.org/2003/linkbase}footnoteLink.
    this problem is related to the following location:
        at protected java.util.List org.xbrl._2003.instance.Xbrl.itemOrTupleOrContext
        at org.xbrl._2003.instance.Xbrl

你是否仍然遇到问题,或者更改创建“JAXBContext”的方式已经解决了它? - bdoughan
现在已经修复了!感谢您的帮助!干杯! - nouseforaname
你在哪里设置了 Locale ?我正在尝试设置,但它没有起作用。 - musikele
这是JVM区域设置。请参见此处:https://dev59.com/MWoy5IYBdhLWcg3wCpzQ - nouseforaname
谢谢,这个Locale提示帮了我大忙! - dmonti

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接