--- En date de : Lun 4.5.09, Noel Grandin <[email protected]> a écrit :

> De: Noel Grandin <[email protected]>
> Objet: Re: using annotations for binding between XML/Java elements
> À: [email protected]
> Date: Lundi 4 Mai 2009, 16h26
> 
> Once you get into code generation, the world is your oyster
> :-)
> Yeah, you could generate code that initialised the private
> fields from
> inside the class in a variety of ways - a new method, new
> code in the
> constructor, a new instance initialiser, etc.
> 
> But it definitely makes deployment a little harder (one
> extra build
> step), and code generation is not trivial.

FYI, it look like you can create a new class building its definition into a 
StringBuffer, compile it and load it, all steps involving only memory storage.

From http://www.artima.com/lejava/articles/compiler_api.html
""
For example, one of the benefits of having a compiler API is that you can make 
compilation part of an application-level service. Consider the case when you 
upload JSP code to an app server: The server has to analyze the JSP files, 
generate Java source code files from the JSPs, write those files out to disk, 
invoke an external compiler that then reads the generated Java source code 
files from disk, writes the class files back to disk, and then the app server 
needs to read those class files into memory. With the Compiler API, you can 
keep the compiler running in that app server, and keep all of that in memory. 
That can reduce deployment time, and also eliminates the startup overhead of 
the compiler.
""

So, some code generation maybe done at runtime.

CASE_1 : one may imagine the following: 
- let's enforce developers to use 'public' or 'protected' for field definitions.
- use JSR Compiler API to derivate that class in order to extend the startup() 
method for doing XML/Java mapping.

But it's not a solution for class without associated/delivered source code...

CASE_2 : for that last case, a solution might be (if doable !):
- use ASM - http://asm.ow2.org/ - to transform 'private' fields into 
'protected' fields
- goto the previous case.

Well, IMHO, CASE_1 looks like a good compromise, because OO encapsulation is 
not broken:
- developers do a step forward Pivot while using 'protected' keyword (+ 
annotations) in order to allow easier XML/Java mapping.
- Pivot does half of the job while doing code generation and mapping according 
to annotations.

Any comment/idea ?
Thanks.

Dominique










> Regards, Noel Grandin
> 
> 
> Todd Volkert wrote:
> > This makes me wonder: does the JDK give us any hooks
> into the actual
> > compiler?  Might we be able to compile in an
> instance initializer that
> > did the binding?
> >   
> 
>




Reply via email to