无法使用JAXB封送XBRL实例

时间:2015-01-20 07:34:11

标签: java jaxb jaxb2 xbrl

我正在尝试使用JAXB创建XBRL实例。我可以使用基于xbrl-instance模式的xjc成功创建java模型(http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd

使用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

1 个答案:

答案 0 :(得分:4)

我可以通过发现实际堆栈跟踪由于已知错误而导致错误解决我的问题,这种错误在转换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