users@jaxb.java.net

Re: xjc plugin problem

From: santa T <shaoanqing_at_gmail.com>
Date: Mon, 21 May 2007 11:28:49 +0800

annother way:
setMethodblock.assign(JExpr._this().ref(idFieldVar ), var);

2007/5/18, santa T <shaoanqing_at_gmail.com>:
>
> Thanks
>
> 2007/5/17, Aleksei Valikov <valikov_at_gmx.net>:
> >
> > Hi.
> >
> > - Show quoted text -
> >
> > > I am now writing a xjc plugin adding a property named "id" to the
> > > java file gennerated.
> > >
> > > here is the fragment of java files gennerated with my plugin
> > >
> > > ..........................................
> > > private long id;
> > > public long getId() {
> > > return id;
> > > }
> > >
> > > private void setId(long id) {
> > > id = id;
> > > }
> > > ..........................................
> > > but my expected code is
> > >
> > > ..........................................
> > > private long id;
> > > public long getId() {
> > > return this.id;
> > > }
> > >
> > > private void setId(long id) {
> > > this.id = id;
> > > }
> > > ..........................................
> > >
> > > how can I get code expected?? Thanks.
> > >
> > >
> > > here is the fragment of my plugin:
> > >
> > > ....................................
> > >
> > > @Override
> > > public boolean run(Outline outline, Options opt, ErrorHandler
> > > errorHandler)
> > > throws SAXException {
> > > for (ClassOutline co : outline.getClasses()) {
> > > JCodeModel codeModel = new JCodeModel();
> > > JDefinedClass definedClass = co.implClass;
> > > definedClass.annotate(Entity.class);
> > > JFieldVar idFieldVar = definedClass.field(JMod.PRIVATE,
> > > codeModel.LONG,"id");
> > >
> > > JMethod getMethod = definedClass.method(JMod.PUBLIC,
> > > codeModel.LONG,"getId");
> > > JBlock getMethodblock =getMethod.body();
> > > getMethodblock._return(idFieldVar);
> > >
> > > JMethod setMethod = definedClass.method(JMod.PRIVATE,
> > > codeModel.VOID,"setId");
> > > JVar var =setMethod.param(codeModel.LONG, "id");
> > > JBlock setMethodblock =setMethod.body();
> > > }
> >
> >
> > Something like:
> >
> > @Override
> > public void postProcessModel(Model model, ErrorHandler errorHandler)
> > {
> >
> > for (final CClassInfo classInfo : model.beans().values()) {
> > classInfo.addProperty(new CAttributePropertyInfo(
> > "id", null, CCustomizations.EMPTY, null, "id",
> > CBuiltinLeafInfo.LONG, false));
> > }
> > }
> >
> > Bye.
> > /lexi
>
>
>