users@jaxb.java.net

AW: Mapping of SAX events to corresponding JAXB classes

From: Claus Nagel <claus.nagel_at_gmail.com>
Date: Sat, 29 Sep 2007 12:18:14 +0200

Hi.

> A second approach is to use the jaxb reflection.
> Consider the following code:
>
> public static TypeInfoSet<Type, Class, Field, Method> create(
> Class... classes) throws IllegalAnnotationsException
{
>
> ModelBuilder<Type, Class, Field, Method> builder = new
> ModelBuilder<Type, Class, Field, Method>(
> new RuntimeInlineAnnotationReader(),
> Navigator.REFLECTION,
> Collections.<Class, Class> emptyMap(),
null);
> IllegalAnnotationsException.Builder errorHandler = new
> IllegalAnnotationsException.Builder();
> builder.setErrorHandler(errorHandler);
> for (Class c : classes)
> builder.getTypeInfo(new Ref<Type,
> Class>(Navigator.REFLECTION
> .use(c)));
> errorHandler.check();
>
> return builder.link();
> }
>
> public void testReflection() throws Exception {
>
> TypeInfoSet<Type, Class, Field, Method> set =
> create(ObjectFactory.class);
>
> for (ElementInfo<Type, Class> elementInfo :
> set.getAllElements()) {
> final QName elementName =
elementInfo.getElementName();
> final Type type =
elementInfo.getContentInMemoryType();
> logger.debug("Element [" + elementName + "] is
mapped
> onto ["
> + type + "].");
> }
>
> }
>
> For the purchase order schema this prints out:
>
> <Element [purchaseOrder] is mapped onto [class
> org.jvnet.hyperjaxb3.ejb.tests.po.PurchaseOrderType].>
> <Element [comment] is mapped onto [class java.lang.String].>
>
> Is this the information you're looking for?

Yes, that's exactly what I was looking for! Terrific, thank you very much
for your fast and competent answer.

> If you want to construct the TypeInfoSet from the context path
> ("com.acme.foo:com.acme.bar"), I guess you'll first have to parse this
> string to get the list of ObjectFactory classes for the context
> packages.

Could you please give me another hint on how to do this? I would prefer to
create the TypeInfoSet from a context path. So if I have a string like
"com.acme.foo", how do I get the corresponding ObjectFactory class that I
have to forward to your create method?

Best regards,
Claus