users@jaxb.java.net

Re: parameterizing attributes

From: Alec Swan <aukcioner_at_yahoo.com>
Date: Thu, 25 May 2006 11:06:00 -0700 (PDT)

I think what I said about XmlJavaTypeAdapter is wrong. The adapter does fire every time a getter or a setter method is invoked on the element, which is good. However, the adapter does not apply to each element of a collection before the collection is returned, which is bad. Is there a way to instruct JAXB to do that?

Also, when XmlJavaTypeAdapter it does not contain any information about the context it was fired in. Is there a way to get ahold of the instance on which the getter or setter method was invoked, which caused the adapter to fire?

Thanks.


Alec Swan <aukcioner_at_yahoo.com> wrote: I have an XML document, which contains an element, which gets unmarshalled and processed by my application. Now, suppose I want to simulate a case where I have a document with 1000 such elements (with little variations) and see how my application performs under load.

So, I added an attribute to the element, which allows me to specify how many times this elements needs to be processed by my application once it's unmarshalled. However, in order to avoid violating unique constraints (e.g. when storing element state in the database), I need to change some of its attributes and sub-elements. In other words, I need to be able to parameterize the element and replace parameters at run time with sequential or random values.

I was planning to use type adaptors, but then realized that they are used only during unmarshalling and will not help me replace parameters in attribute values after that. It would be nice if there was a way to instruct JAXB to use my preprocessor before returning the value from a getter method.

I would appreciate any ideas on how to best parameterize XML attributes and elements.

Thanks.