3

I'm trying to create a XBRL-instance by using JAXB. I could successfully create java models using xjc based on the xbrl-instance schema (http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd)

When creating the java classes by using xjc I was following the recommendations of this post (except for the maven part as im not using it): 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>

So now I'm trying to produce a XBRL instance but i get a Java.lang.IllegalArgumentException when initializing the context. I've found another post that recommends to call newInstance() by referring to the package and the ObjectFactory (using classloader). But still the error occurs and i can't really extract any useful information out of the stacktrace.

Marshalling Code:

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();
        }
    }
}

Stacktrace:

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
Community
  • 1
  • 1
nouseforaname
  • 309
  • 3
  • 11
  • I think it's related to this issue that already has been reported: https://java.net/jira/browse/JAXB-1017. Still I wonder which element is causing the conflict? – nouseforaname Jan 20 '15 at 10:12
  • I'm assuming the real exception is causing an error message to be produced and the error message formatting is encountering a problem. Are English (en_us) messages logged, or another language? – bdoughan Jan 20 '15 at 11:19
  • It's german and that was causing the misleading error message. – nouseforaname Jan 20 '15 at 12:29
  • Can you switch your environment to English to get a new error message? – bdoughan Jan 20 '15 at 12:32
  • Due you know where the language setting is derived from? Appears to be the same when changing the win 8 os language setting. – nouseforaname Jan 20 '15 at 12:34
  • See: http://stackoverflow.com/questions/8809098/how-do-i-set-the-default-locale-for-my-jvm – bdoughan Jan 20 '15 at 12:44

1 Answers1

7

I could solve my issue by finding out that the actual stack trace was misleading due to a known bug, that occurs when translating jaxb error messages. See here: https://java.net/jira/browse/JAXB-1017

After all there was still an issue with my jaxb context call, which i solved by referencing all packages in one String seperated by colons.

JAXBContext jaxbContext = JAXBContext.newInstance("org.xbrl._2003.instance:org.xbrl._2003.linkbase:org.xbrl._2003.xlink");

Edit:

Changing locale leads to a more informative error message:

Locale.setDefault(Locale.ENGLISH);` 

Output:

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
nouseforaname
  • 309
  • 3
  • 11