This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: tutorial on using Kawa annotations with JAXB to serialize XML


In the section on unmarshalling:
"You create an Unmarshaller from the , and then just invoke one of the Unmarshaller unmarshall methods."


Presumably this should have "from the JAXBContext". Other than that, it was fairly straightforward to me, and I've never used JAXB.

I am now attempting to follow the style of your example to write code to handle the DTD used by Orocos deployment files [1], and I have hit an issue:

I ran xjc on the DTD file to see what the auto-generated Java code would look like, and this:

<!ELEMENT properties (description? , (simple|sequence|struct)* )>

translates into this:

  @XmlElements ({
    @XmlElement(name = "simple", type = Simple.class),
    @XmlElement(name = "sequence", type = Sequence.class),
    @XmlElement(name = "struct", type = Struct.class)
  })
  protected List<Object> simpleOrSequenceOrStruct;


I'm not sure how to reproduce that in Kawa. I tried
(contents (@XmlElements [(@XmlElement name: "simple" type: Simple)
(@XmlElement name: "sequence" type: Sequence)
(@XmlElement name: "struct" type: Struct)])
::ArrayList)


but I got
java.lang.UnsupportedOperationException
at gnu .bytecode .RuntimeAnnotationsAttr.assignConstants(RuntimeAnnotationsAttr.java:306)
during compilation. I also tried removing the '@' from the inner XmlElement items, but that gave me
"no accessible method '<init>/valueOf' in javax.xml.bind.annotation.XmlElement".


How are we supposed to declare an annotation which contains other annotations?


In this case I could create separate lists for the different types, but then I lose the ordering in the original XML file.


Thanks,
Jamie

[1] http://svn.mech.kuleuven.be/repos/orocos/trunk/rtt/doc/cpf.dtd

On Jan 5, 2011, at 10:34 AM, Per Bothner wrote:

This is a draft - please let me know if you see any mistakes,
or if the explanation could be made more helpful.

http://per.bothner.com/blog/2011/Using-JAXB-annotations/
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/

-- Jamison Hope The PTR Group www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]