users@jaxb.java.net

RE: Re: No ObjectFactory with an _at_XmlElementDecl

From: Moravec Jan <Jan.Moravec_at_ips-ag.cz>
Date: Thu, 27 Jul 2006 01:01:30 +0200

Hello,
 
I have just tried that, but I ended up with a different error. With simple schemas I normally do not have problems using both kinds of JAXBContext.newInstance methods, but this GraphML schema is somehow more resistant. The exception is now (I added some logging to print out the context path and info on the marshalled object and its type):
 
[findlibdeps] Creating a new JAXBContext with context path: org.graphdrawing.graphml.xmlns.graphml:com.yworks.xml.graphml
[findlibdeps] About to marshall object: javax.xml.bind.JAXBElement_at_29c58e
[findlibdeps] Object is a JAXBElement, name={http://graphml.graphdrawing.org/xmlns/graphml}graphml, type=class org.graphdrawing.graphml.xmlns.graphml.GraphmlType, scope=class javax.xml.bind.JAXBElement$GlobalScope, value=org.graphdrawing.graphml.xmlns.graphml.GraphmlType@691dee <mailto:value=org.graphdrawing.graphml.xmlns.graphml.GraphmlType@691dee>
[findlibdeps] Error marschalling dependency graph: javax.xml.bind.JAXBElement_at_29c58e
[findlibdeps] javax.xml.bind.MarshalException
[findlibdeps] - with linked exception:
[findlibdeps] [com.sun.istack.SAXException2: unable to marshal type "com.yworks.xml.graphml.ShapeNodeType" as an element because it is missing an @XmlRootElement annotation]
[findlibdeps] at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295)

Why should a nested element have @XmlRootElement annotation?
 
Thank you,
Jan
 
-----Original Message-----
From: Sekhar Vajjhala [mailto:Sekhar.Vajjhala_at_Sun.COM]
Sent: Wed 7/26/2006 8:05 PM
To: users_at_jaxb.dev.java.net
Cc:
Subject: Re: No ObjectFactory with an @XmlElementDecl



        Use the JAXBContext.newInstance(...) method which takes a list of
        package names
        
              JAXBContext.newInstance("com.acme.foo:com.acme.bar")
        
        instead of JAXBContext.newInstance method that takes a list of classes.
        See javadoc for
        https://jaxb.dev.java.net/nonav/jaxb20-pfd/api/javax/xml/bind/JAXBContext.html
        .
        
        Sekhar
        
        
        Moravec Jan wrote:
        
>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
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>
        
        
        ---------------------------------------------------------------------
        To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
        For additional commands, e-mail: users-help_at_jaxb.dev.java.net