users@jaxb.java.net

No ObjectFactory with an _at_XmlElementDecl

From: Moravec Jan <Jan.Moravec_at_ips-ag.cz>
Date: Wed, 26 Jul 2006 18:33:56 +0200

Hi,

I have written a simple Ant task that uses JAXB (jaxb-ri-20060607) to create GraphML XML instances describing JAR-level dependencies between 3rd party JARs and my project module JARs (helpful when one wants to update a 3rd party JAR and want to see which of project modules and 3rd party libs will be affected).

I am using GraphML XSD schemas with yWorks extensions (http://www.yworks.com/en/products_yfiles_ep_graphml.htm) to generate Java classes for the content tree objects. That goes fine, but when I populate these objects and attempt to marchall the content tree I receive the following exception:

[findlibdeps] 26.7.2006 17:05:45 javax.xml.bind.ContextFinder newInstance
[findlibdeps] FINE: Trying to load com.sun.xml.bind.v2.ContextFactory
[findlibdeps] 26.7.2006 17:05:45 javax.xml.bind.ContextFinder newInstance
[findlibdeps] FINE: loaded com.sun.xml.bind.v2.ContextFactory from jar:file:/c:/Java/e/lib/jaxb/jaxb-impl.jar!/com/sun/xml/bind/v2/ContextFactory.class
[findlibdeps] Error marschalling dependency graph: org.graphdrawing.graphml.xmlns.graphml.GraphmlType_at_33f0de
[findlibdeps] com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
[findlibdeps] There's no ObjectFactory with an @XmlElementDecl for the element {http://www.yworks.com/xml/graphml}ProxyShapeNode.
[findlibdeps] this problem is related to the following location:
[findlibdeps] at protected java.util.List org.graphdrawing.graphml.xmlns.graphml.DataExtensionType.content
[findlibdeps] at org.graphdrawing.graphml.xmlns.graphml.DataExtensionType
[findlibdeps] at org.graphdrawing.graphml.xmlns.graphml.DefaultType
[findlibdeps] at protected org.graphdrawing.graphml.xmlns.graphml.DefaultType org.graphdrawing.graphml.xmlns.graphml.KeyType._default
[findlibdeps] at org.graphdrawing.graphml.xmlns.graphml.KeyType
[findlibdeps] at protected java.util.List org.graphdrawing.graphml.xmlns.graphml.GraphmlType.key
[findlibdeps] at org.graphdrawing.graphml.xmlns.graphml.GraphmlType
[findlibdeps] at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
[findlibdeps] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:364)
[findlibdeps] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:216)

The generated JAXB classes are in two packages:

org.graphdrawing.graphml.xmlns.graphml - standard GraphML types
com.yworks.xml.graphml - yWorks GraphML extension types

The error would indicate that JAXB has problems finding the ObjectFactory for the ProxyShapeNode. I thought it was because I did not include the com.yworks.xml.graphml package into the list of packages the JAXBContext gets initialized with. However, later on I added that package, but to no avail.

This is how I obtain the JAXBContext:

JAXBContext jaxb = JAXBContext.newInstance( GraphmlType.class, ProxyShapeNodeType.class );

GraphmlType.class - is from the org.graphdrawing.graphml.xmlns.graphml package.

ProxyShapeNodeType.class - is from the GraphML extension (com.yworks.xml.graphml) package. I used this class as there was no "root" object in the extension package, so I just picked this one when JAXB started complaining about it. I expect I would get the same result with any class from the GraphML extension package.

My poor understanding of JAXB internals is that JAXB merely extracts package names from the classes passed to JAXBContext.newInstance method and uses them to obtain a list of ObjectFactory instances. These are then consulted to handle individual content tree types.

I checked the com.yworks.xml.graphml.ObjectFactory to see what is has to say about the ProxyShapeNode and it contains:

    /**
     * Create an instance of {_at_link JAXBElement }{_at_code <}{_at_link ProxyShapeNodeType }{_at_code >}}
     *
     */
    @XmlElementDecl(namespace = "http://www.yworks.com/xml/graphml", name = "ProxyShapeNode")
    public JAXBElement<ProxyShapeNodeType> createProxyShapeNode(ProxyShapeNodeType value) {
        return new JAXBElement<ProxyShapeNodeType>(_ProxyShapeNode_QNAME, ProxyShapeNodeType.class, null, value);
    }

Because the exception says JAXB detected problem related to org.graphdrawing.graphml.xmlns.graphml.DataExtensionType.content, I checked the DataExtensionType and it has:

public class DataExtensionType {

    @XmlElementRefs({
        @XmlElementRef(name = "ProxyShapeNode", namespace = "http://www.yworks.com/xml/graphml", type = JAXBElement.class),
        @XmlElementRef(name = "ImageNode", namespace = "http://www.yworks.com/xml/graphml", type = JAXBElement.class),
        ....

The problematic ProxyShapeNode is the first annotated element reference. The element name and namespace seem to match the @XmlElementDecl in the ObjectFactory above.

So I am kinda lost as to which @XmlElementDecl is missing and where, or what else is wrong. Any help is greately appreciated.

Thank you,
Jan