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:24:32 +0100

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.
>