It shouldn't be all that hard to change the field initializer, but it 
involves digging into the AST stuff using untyped collections. Here's a 
quick rundown:

The FieldDeclaration has a fragments() list property (since multiple 
fields can be declared in a single statement, I think), and the first 
value in this list is the VariableDeclarationFragment that actually 
declares the field. The VariableDeclarationFragment has a 
setInitializer() method which takes an Expression. You need to create 
the Expression, which in this case would be a ClassInstanceCreation. You 
need to create and set a Type on the ClassInstanceCreation, and to do 
that you need to create a Name using the class name. You create 
everything using the AST, which you can get from the FieldDeclaration.

Hope that's enough to get you started. I suppose you could also take the 
approach used in CollectionMethodsDecorator of compiling a class from 
text and then using the compiled AST, but it's probably easier to just 
construct this simple expression directly.

Let me know if you have too much trouble with this. I should probably 
add a decorator for this purpose anyway.

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Andrea Cisternino wrote:
> Hi Dennis,
>
> Thanks for the reply.
>
>   
>> Munging the generated code in the AST with a ClassDecorator valueAdded()
>> or finish() method is the only way you can currently do this. You should
>> only need to change the initializer for the field to make this work.
>>     
>
> In fact I noticed that I don't need to change the getter/setter
> methods because they properly accept/return a generic List<> and that
> fits perfectly with my idea of providing a customized implementation
> of that interface. One less thing to do!
>
> I'll keep this list posted if I manage to reach something stable enough.
> Andrea.
>   

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to