users@jaxb.java.net

Re: Enum Plugin ?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Tue, 02 Jan 2007 12:22:53 -0800

Hanson Char wrote:
> However, I couldn't find an easy way to generate the static block, besides
> resorting to use the JDefinedClass.direct() method. One undesirable side
> effect is that it seems such "direct" static block is always generated at
> the end of the source file, rather then observing the execution order of the
> plugin.
>
> Is there a better way ?

You can create a static initialize block by calling
JDefinedClass.init(). I know, the naming is poor.


> Also, if anyone finds this plugin interesting, I can host it at
> jaxb2-commons as a separate plugin project.
>
> Regards,
> Hanson
>
> public enum USState {
> ..
> // Generated by the enum-plugin
> private final static HashMap<Integer, USState> ordinalToEnum = new
> HashMap<Integer, USState>();
>
> // Generated by the enum-plugin
> public static USState fromOrdinal(int ordinal) {
> return USState.ordinalToEnum.get(ordinal);
> }
>
> // Generated by the enum-plugin
> static {
> for (USState t : USState.values())
> ordinalToEnum.put(t.ordinal(), t);
> }
> }
>


-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com