Support for JAXB annotations
adrian.brock Feb 8, 2007 8:11 AMI've committed some stuff that adds support for JAXB annotations
using JBossXB (the unmarshalling part).
https://svn.jboss.org/repos/common/jbossxb-builder/trunk/
http://anonsvn.jboss.org/repos/common/jbossxb-builder/trunk/
This was pretty easy to do, since it is very simillar to some other code that
I'm working on to construct ManagedObjects for the profile service.
Although the code that splits and creates the model for the
attributes/elements/wildcards is very ugly.
I guess it really needs an intermediate infoset model to make this code
nicer. :-)
This has support for the most of the basics.
I haven't done anything that does things with JAXBElement and theres a couple
of things missing like the ValueAdapters that don't map directly to the
JBossXB notion, but should be trivial to add?
The api I've implemented works in a similar way to JAXB.
You don't need a schema, it just creates the xml model from the object model.
i.e. object model -> SchemaBinding
There's a TODO to integrate this with some other work I did before
Christmas where the model is validated against the schema bindings.
This allows more strict checking/mapping of the object model to the schema
(e.g. you can tell when you forget to map something or did it wrong)
i.e. schema -> SchemaBinding <- object model
There are also some additional annotations that does extra things beyond
what the JAXB annotations allow.
The api is not currently a JAXBContext/Unmarshaller
but you can do something that is pretty similar with the JBossXB api.
Example usage:
SchemaBinding schemaBinding = JBossXBBuilder.build(MyJAXBAnnotatedRoot.class); Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller(); Object result = unmarshaller.unmarshal(urlString, schemaBinding);
If you want to allow multiple roots that don't appear in the same Object hierarchy
then you can do something with a SchemaBindingResolver like
this one I used to test wildcards:
http://anonsvn.jboss.org/repos/common/jbossxb-builder/trunk/src/test/java/org/jboss/test/xb/builder/TestSchemaResolver.java
Though that is obviously not a full implementation. :-)
Finally, the build is broken since there are a few dependencies in the pom.xml
that don't exist in the maven2 repository.
But you can add them manually to your local repository until I get this
updated properly. You need the latest versions of JBossXB and jboss-container.