I now have it working, pretty similar to how I described.
In my class I just extended PersistentTagsHandler - and I found that the
method:
public static String fieldList( ClassDoc clazz, String inclTag, String
exclTag, boolean name_value_out ) throws XDocletException
pretty much did almost everything I needed already so I just copied and
amended it...
.....which got me to thinking that there is some duplicated effort in
there....
Would it be possible to factor this method out so that it in turn calls
another method which returns something like a HashMap of persistent fields
with their types? And then the fieldList method could be cut down to just
call the method and iterate over the returned HashMap.....?
That way my sub-class too could call this new method and iterate over the
HashMap to return something like: 'java.lang.String' + key
???? (unless this already exists and I missed it???)
Thanks
Chris
-=-=-=
PS - I also had to add a method: ifDoesntJustContainStrings else I found I
could end up with 2 identical methods!
-----Original Message-----
From: Shaw, Chris
Sent: 21 February 2002 10:01
To: 'xdoclet-user'
Subject: RE: [Xdoclet-user] Data Object and Strings
So, in a nutshell....(excuse the dodgy file naming!)
I can have my dataobject-custom.j file in the directory where I run Ant
from.....which will look something like the following.... (so far, anyway)
<XDtTagDef:tagDef namespace="CNS" handler="ecb.project.CNSTagsHandler"/>
public
<XDtClass:classOf><XDtEjbDataObj:dataObjectClass/></XDtClass:classOf>(<XDtCN
S:methodStringList/>) {
<XDtEjbPersistent:forAllPersistentFields superclasses="false">
this.<XDtMethod:propertyName/> =
<XDtMethod:setterMethod/>(<XDtMethod:propertyName/>);
</XDtEjbPersistent:forAllPersistentFields>
}
<XDtEjbPersistent:forAllPersistentFields superclasses="false">
<XDtMethod:ifHasMethod name="<XDtMethod:setterMethod/>"
parameters="<XDtMethod:methodType/>">
<XDtMethod:ifDoesntHaveMethod name="<XDtMethod:setterMethod/>"
parameters="java.lang.String">
<XDtMethod:ifDoesntHaveMethod name="<XDtMethod:setterMethod/>"
parameters="java.sql.Date">
public void <XDtMethod:setterMethod/>(java.lang.String
<XDtMethod:propertyName/>) {
this.<XDtMethod:propertyName/> = new
<XDtMethod:methodType/>(<XDtMethod:propertyName/>);
}
</XDtMethod:ifDoesntHaveMethod>
<XDtMethod:ifHasMethod name="<XDtMethod:setterMethod/>"
parameters="java.sql.Date">
public void <XDtMethod:setterMethod/>(java.lang.String
<XDtMethod:propertyName/>) {
java.util.StringTokenizer tokens = new
java.util.StringTokenizer(<XDtMethod:propertyName/>, "/", false);
this.<XDtMethod:propertyName/> = (java.sql.Date) (new
java.util.GregorianCalendar(Integer.parseInt(tokens.nextToken()),
Integer.parseInt(tokens.nextToken()),Integer.parseInt(tokens.nextToken())).g
etTime());
}
</XDtMethod:ifHasMethod>
</XDtMethod:ifDoesntHaveMethod>
</XDtMethod:ifHasMethod>
</XDtEjbPersistent:forAllPersistentFields>
...whereby the key is my tag <XDtCNS:methodStringList/> - which relates to
the method methodStringList() in the class ecb.project.CNSTagsHandler
and this class will look something like...
package ecb.project;
public class CNSTagsHandler extends xdoclet.template.TemplateTagHandler {
public String methodStringList() throws xdoclet.XDocletException {
// to do: generate comma-separated list of persistent fields
prefixed
// by java.lang.String
}
}
...okay, I still have the *hard* part left to do....but thanks to the way
that XDoclet has been written and documented, it wasn't too painful to get
this far!
Chris
-=-=-=
-----Original Message-----
From: Ara Abrahamian [mailto:[EMAIL PROTECTED]]
Sent: 20 February 2002 20:50
To: Shaw, Chris; 'xdoclet-user'
Subject: RE: [Xdoclet-user] Data Object and Strings
Write a template tag. Don't do the looping/checking in the template.
It's easy, and you can register the template tag quite easily by
XDtTag:tagDef (check docs for more info).
Ara.
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:xdoclet-user-
> [EMAIL PROTECTED]] On Behalf Of Shaw, Chris
> Sent: Wednesday, February 20, 2002 4:16 PM
> To: 'xdoclet-user'
> Subject: RE: [Xdoclet-user] Data Object and Strings
>
> Hi,
>
> I was thinking along the lines of having a 'string-only'
constructor....in
> addition to the current one(s)...(maybe it is better, if parsing
through
> XML, to just call a set method for each parameter as they are found
anyway
> but...)
>
> So I was working on the premise that I would need a comma-separated
list
> as
> the arguments passed in...
> public ObjectData(java.lang.String paramOne, java.lang.String
paramTwo,
> etc)
>
> and then in this constructor, as you suggested, I would simply call
> overriden methods (for which the arguments are obviously not already a
> String as they don't need to be overriden).
>
> The problem here is knowing which argument is the last one and hence
not
> printing the last comma....
>
> C.
> --
>
>
>
> -----Original Message-----
> From: Dmitri Colebatch [mailto:[EMAIL PROTECTED]]
> Sent: 20 February 2002 13:32
> To: Shaw, Chris; 'xdoclet-user'
> Subject: Re: [Xdoclet-user] Data Object and Strings
>
>
> Why not
>
> <XDtEjbPersistent:forAllPersistentFields superclasses="false">
> java.lang.String <XDtMethod:propertyName/>AsString;
> </XDtEjbPersistent:forAllPersistentFields>)
>
> also remember that if this is to go in the dataobject class, you will
have
> namespace issues if you use <XDtMethod:propertyName /> - hence my
> appending
> of 'AsString' to the name.
>
> cheers
> dim
>
> ----- Original Message -----
> From: "Shaw, Chris" <[EMAIL PROTECTED]>
> To: "'xdoclet-user'" <[EMAIL PROTECTED]>
> Sent: Wednesday, February 20, 2002 8:42 PM
> Subject: RE: [Xdoclet-user] Data Object and Strings
>
>
> > Hi,
> >
> > Quick question...(?)
> > Is it possible to do something like the following? (or am I tackling
it
> > wrong?)
> >
> > (<XDtEjbPersistent:forAllPersistentFields superclasses="false">
> > java.lang.String <XDtMethod:propertyName/>
> >
> >
>
<**ifNotLastPeristentFieldThenPrintThis**>,</**ifNotLastPeristentFieldTh
en
> Pr
> > intThis**>
> > </XDtEjbPersistent:forAllPersistentFields>)
> >
> > Thanks
> >
> > Chris
> > -=-=-=
> >
> > -----Original Message-----
> > From: Ara Abrahamian [mailto:[EMAIL PROTECTED]]
> > Sent: 19 February 2002 18:49
> > To: Shaw, Chris; 'xdoclet-user'
> > Subject: RE: [Xdoclet-user] Data Object and Strings
> >
> >
> > Write a template and decide on the type what to do. You have to do a
lot
> > of if/elses and handle each type differently. You can also write
> > decoders (like the way Soap converts types from string to java,
using a
> > set of demarshallers).
> >
> > In my application I'm doing the reverse: I construct an
> > XmlConfiguration, passing in a Class, load an xml file, look at the
> > Class and for each attribute I try to do a
getMethod("get"+attrname),
> > then I check the type of the return type and in a big if/else
convert
> > the string to the return type of the method and do a
"set"+attrname()
> > passing in the converted value. I handle it in runtime, and based on
the
> > assumption that there's get/set for attributes of the xml file in
the
> > bean. It's pricier in runtime obviously. You may be interested to
handle
> > it using Castor XML for example. It's also absolutely possible to
> > implement using a specialized xdoclet template files. Depends on
your
> > taste :o) If I were to implement it now I would write a template
(I'm
> > writing templates each day for various automation cases I face in
our
> > app!!), using the strategy dataobject generation uses. Actually the
> > tricky part is the type conversion part because there's no generic
way
> > to handle it and you should tackle it case by case for each type.
> >
> > Cheers,
> > Ara.
> >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
[mailto:xdoclet-user-
> > > [EMAIL PROTECTED]] On Behalf Of Shaw, Chris
> > > Sent: Tuesday, February 19, 2002 5:49 PM
> > > To: xdoclet-user
> > > Subject: [Xdoclet-user] Data Object and Strings
> > >
> > > Hi,
> > >
> > > The project I am working on receives input (in a variety of ways)
as
> > XML.
> > > Naturally, data will be in string format.....
> > >
> > > Does anyone have any ideas on how best to get String parameters as
> > Java
> > > Objects (String, Integer, Date etc) into the XDoclet-generated
Data
> > > Object....?
> > >
> > > Simple field validation (type/constraints) is automatically
> > handled....so
> > > the only thing left (apart from complex validation) is to create
the
> > > correct
> > > types.
> > >
> > > By default the XDoclet generated Data Object already knows the
correct
> > > type
> > > for an Object...
> > > For example I could have:
> > >
> > > setRefNumber(java.lang.Integer refNumber) {
> > > this.refNumber = refNumber;
> > > }
> > >
> > > What I really want, for *all* my object attributes, is something
> > like...
> > > setRefNumberFromString(java.lang.String refNumber) {
> > > this.refNumber = new Integer(refNumber);
> > > )
> > >
> > > How can this best be achieved in the current framework? (or are
there
> > > better
> > > ways of doing this?)
> > > I want to try and generate as much as possible and avoid having to
> > > hand-write such trivial things.....something the XDoclet concept
> > alreadt
> > > plays a *big* part in.
> > >
> > > Thanks
> > >
> > > Chris
> > > -=-=-=
> > >
> > > Any e-mail message from the European Central Bank (ECB) is sent in
> > good
> > > faith but shall neither be binding nor construed as constituting a
> > > commitment by the ECB except where provided for in a written
> > agreement.
> > > This e-mail is intended only for the use of the recipient(s) named
> > above.
> > > Any unauthorised disclosure, use or dissemination, either in whole
or
> > in
> > > part, is prohibited.
> > > If you have received this e-mail in error, please notify the
sender
> > > immediately via e-mail and delete this e-mail from your system.
> > >
> > >
> > > _______________________________________________
> > > Xdoclet-user mailing list
> > > [EMAIL PROTECTED]
> > > https://lists.sourceforge.net/lists/listinfo/xdoclet-user
> >
> >
> > _________________________________________________________
> > Do You Yahoo!?
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> > Any e-mail message from the European Central Bank (ECB) is sent in
good
> faith but shall neither be binding nor construed as constituting a
> commitment by the ECB except where provided for in a written
agreement.
> > This e-mail is intended only for the use of the recipient(s) named
> above.
> Any unauthorised disclosure, use or dissemination, either in whole or
in
> part, is prohibited.
> > If you have received this e-mail in error, please notify the sender
> immediately via e-mail and delete this e-mail from your system.
> >
> >
> > _______________________________________________
> > Xdoclet-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/xdoclet-user
> >
>
> Any e-mail message from the European Central Bank (ECB) is sent in
good
> faith but shall neither be binding nor construed as constituting a
> commitment by the ECB except where provided for in a written
agreement.
> This e-mail is intended only for the use of the recipient(s) named
above.
> Any unauthorised disclosure, use or dissemination, either in whole or
in
> part, is prohibited.
> If you have received this e-mail in error, please notify the sender
> immediately via e-mail and delete this e-mail from your system.
>
>
> _______________________________________________
> Xdoclet-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/xdoclet-user
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
Any e-mail message from the European Central Bank (ECB) is sent in good faith but
shall neither be binding nor construed as constituting a commitment by the ECB except
where provided for in a written agreement.
This e-mail is intended only for the use of the recipient(s) named above. Any
unauthorised disclosure, use or dissemination, either in whole or in part, is
prohibited.
If you have received this e-mail in error, please notify the sender immediately via
e-mail and delete this e-mail from your system.
_______________________________________________
Xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user