users@jaxb.java.net

Re: Lazy Init Collections in Generated Classes

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 4 Nov 2011 07:49:54 +0100

IIRC, undoing what has been generated is difficult. It might be easier to
fix with a patch right in the xjc code. Or you could post-process the
generated java code using a simple Perl (or whatever) script - the quickest
solution ;-)
-W

On 4 November 2011 07:37, Nick Heudecker <nheudecker_at_gmail.com> wrote:

> Do you think I can address this with an XJC extension?
>
> On Thu, Nov 3, 2011 at 11:24 PM, Wolfgang Laun <wolfgang.laun_at_gmail.com>wrote:
>
>>
>>
>> On 3 November 2011 22:52, Nick Heudecker <nheudecker_at_gmail.com> wrote:
>>
>>> I'm sure this has been asked before but my searches haven't turned up
>>> anything.
>>
>>
>> I'm quite sure this hasn't come up during the last few years.
>>
>>
>>> I need a way to initialize collection objects lazily. My XSDs (which
>>> I don't control) have the following for all objects:
>>>
>>> <xsd:anyAttribute namespace="##any" processContents="lax"/>
>>>
>>> Resulting in lots of the following:
>>>
>>> public class Foo {
>>> private Map<QName, String> otherAttributes = new HashMap<QName,
>>> String>();
>>>
>>> // ....
>>> }
>>>
>>> How can I tell XJC to not create the otherAttributes map until the
>>> 'getOtherAttributes()' method is called? Ordinarily this wouldn't be a
>>> problem but I'm seeing a lot of needless object creation under load.
>>
>>
>> Don't think you can. But it stands to reason to expect lazy
>> initialization for this Map as well since it's being done for List objects,
>> so you might raise an issue.
>>
>> -W
>>
>>>
>>>
>>> Thanks for your time.
>>>
>>
>>
>