You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Craig R. McClanahan" <cr...@apache.org> on 2003/08/17 04:50:12 UTC

Re: [Digester] NodeCreateRule - doesn't pop() Node in the end()

On Tue, 29 Jul 2003, Nitsche, Thomas wrote:

> Date: Tue, 29 Jul 2003 13:01:58 +0200
> From: "Nitsche, Thomas" <ni...@ifis.uni-passau.de>
> Reply-To: Jakarta Commons Users List <co...@jakarta.apache.org>
> To: commons-user@jakarta.apache.org
> Subject: [Digester] NodeCreateRule - doesn't pop() Node in the end()
>
> I need to use the NodeCreateRule to parse nested Elements with mixed content in my documents.
> As I always got NoSuchMethodExceptions somewhere after the NodeCreateRule executed, I took a look into the source code and found out, that NodeCreateRule does not overwrite the end() method of  org.apache.commons.digester.Rule.
> But because of this, the Node does not get popped from the stack when the closing tag is reached.
> I think this is a bug because NodeCreateRule should behave the same way as ObjectCreateRule does.
>
> It worked fine after I derived the following class and used it instead of NodeCreateRule:
>
> 	public class MyNodeCreateRule extends NodeCreateRule {
>
> 		[ ... all the Contructors calling super(...) ...]
>
> 		public void end() throws Exception {
> 			Object top = digester.pop();
> 		}
> 	}
>
>
> Is this a bug or did I just use this rule in the wrong way?

Sorry for the late response on this (I'm not normally a user of
NodeCreateRule).  I think your analysis of the situation is correct, so I
just applied the corresponding patch to NodeCreateRule itself and things
seem to work as one would expect -- the Node is on the stack for the
duration of the set of rules that all match the initial pattern, and then
it's popped off.  Even the unit tests still continue to work, so I'm
committing the change for people to play with.  It will show up in the
20030817 nightly build of Digester tonight.

Thomas, I'd appreciate it if you could try this out in your application
and report back on success or probems.

> Thomas
>

Craig McClanahan

Re: [betwixt/digester] mapping interfaces to classes

Posted by "Gary S. Cuozzo" <ga...@innovationsw.com>.
robert,
i'd like to say thank you for implementing this feature.  i just got done writing
a bit of test code and it is working just fine.  now to remove my temporary
hack...

:-)
gary.

> -- 
> Gary S. Cuozzo <ga...@innovationsw.com>
> Innovation Software Group, LLC


Re: [betwixt/digester] mapping interfaces to classes

Posted by "Gary S. Cuozzo" <ga...@innovationsw.com>.
> i've committed this change. you'll either need to build from CVS HEAD or 
> wait until the next nightly.
> 
> i've updated the web site with some documentation.
> 
> note that i suspect that may have trouble if you want to set properties 
> which do not exist in the interface - but getting this working is reliant 
> on some refactoring of the read process required to make derived beans 
> work fully. i'm going to take a look at this soon but i can't promise when 
> it'll be done.

thanks robert!  i should be able to try it out tonight or early this week.

gary.



Re: [digester] NullPointerException :Digester.addObjectCreate

Posted by Simon Kitching <si...@ecnetwork.co.nz>.
Hi Jai,

Please send the complete output generated when the exception occurs, ie
the full stack-trace. Without this, it is hard to know what the problem
might be.

Regards,

Simon

On Sat, 2003-08-30 at 07:15, Jai PP wrote:
> I am getting  null pointer exception at
> addObjectCreate. When there are lot of nodes. I am
> using latest 1.5 digester. Pls see the below code, if
> I run this many times or if there are lot of elements
> of A/B then following error is encountered.
> 
> Exception : java.lang.NullPointerException 
> void
> org.apache.commons.digester.Digester.addObjectCreate(java.lang.String,
> java.lang.String)
> 
> Here is what I am doing. When  tag A/B is obtained
> creating an object myBeanClass and calling addSetNext
> every time
> 
> // push the gloabl object
> digester.push(this);
> digester.addObjectCreate(
>             "A/B",
>             myBeanClass);
> // set some bunch of values using 
> digester.addBeanPropertySetter(..);
> digester.addBeanPropertySetter(..);
> ....
> 
> call the add next rules
> 
> digester.addSetNext("A/B", "process");
> 
> 
> public void process(myBeanClass myBeanClassObj)
> {
> }
> 
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


Re: [digester] NullPointerException :Digester.addObjectCreate

Posted by Jai PP <jp...@yahoo.com>.
I am getting  null pointer exception at
addObjectCreate. When there are lot of nodes. I am
using latest 1.5 digester. Pls see the below code, if
I run this many times or if there are lot of elements
of A/B then following error is encountered.

Exception : java.lang.NullPointerException 
void
org.apache.commons.digester.Digester.addObjectCreate(java.lang.String,
java.lang.String)

Here is what I am doing. When  tag A/B is obtained
creating an object myBeanClass and calling addSetNext
every time

// push the gloabl object
digester.push(this);
digester.addObjectCreate(
            "A/B",
            myBeanClass);
// set some bunch of values using 
digester.addBeanPropertySetter(..);
digester.addBeanPropertySetter(..);
....

call the add next rules

digester.addSetNext("A/B", "process");


public void process(myBeanClass myBeanClassObj)
{
}



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Re: [betwixt/digester] mapping interfaces to classes

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Thursday, August 21, 2003, at 08:46 PM, Gary S. Cuozzo wrote:

>> oops - i forgot this option. this is adding an extra attribute to the
>> .betwixt file that specifies an implementation class - probably a 'class'
>> attribute. (this isn't the same as derived beans.)
>>
>> this should be pretty easy to implement but it's probably not worth
>> contributing to right now since it means changes in the code i've just
>> moved. i might take a look at this once i've committed the changes i'm
>> working on (see below).
>>
>> how does the name 'class' sound for the betwixt attribute name?
>
> sounds just fine to me.  i think this modification will be all i need.

i've committed this change. you'll either need to build from CVS HEAD or 
wait until the next nightly.

i've updated the web site with some documentation.

note that i suspect that may have trouble if you want to set properties 
which do not exist in the interface - but getting this working is reliant 
on some refactoring of the read process required to make derived beans 
work fully. i'm going to take a look at this soon but i can't promise when 
it'll be done.

- robert


Re: [betwixt/digester] mapping interfaces to classes

Posted by "Gary S. Cuozzo" <ga...@innovationsw.com>.
> oops - i forgot this option. this is adding an extra attribute to the 
> .betwixt file that specifies an implementation class - probably a 'class' 
> attribute. (this isn't the same as derived beans.)
> 
> this should be pretty easy to implement but it's probably not worth 
> contributing to right now since it means changes in the code i've just 
> moved. i might take a look at this once i've committed the changes i'm 
> working on (see below).
> 
> how does the name 'class' sound for the betwixt attribute name?

sounds just fine to me.  i think this modification will be all i need.

thanks,
gary.
-- 
Gary S. Cuozzo <ga...@innovationsw.com>
Innovation Software Group, LLC


Re: [betwixt/digester] mapping interfaces to classes

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On Tuesday, August 19, 2003, at 11:47 PM, Gary S. Cuozzo wrote:

>> (my apologies that took me a while to answer, i haven't been a bit ill.)
> sorry to hear you have been ill.  i sure do appreciate the reply.  was
> beginning to think nobody ran across this before, but saw "better
> support for interfaces" on the todo list.  :-)

so much to do, so little time.

>> use derived beans
>> -----------------
>> this means using an attribute of the xml to specify the class to be
>> created. this need a little work (there is no setting to switch on 
>> writing
>> these attributes, there is no beaninfo attribute to customize the
>> attribute name and reading only sets the properties that the interface
>> expresses). i might be persuaded to bring forward adding writing - or you
>> could probably have a go at adding this functionality yourself (its 
>> pretty
>> easy). if you do, then maybe you'd care to submit a patch :)
> this is probably what i was trying to do with .betwixt files (but
> couldn't get it to work).  basically tell betwixt "when you see
> AuthInfo, instantiate GenericAuthInfo" or something like that.
>
> if you give me some clues as to where to start, i would be open to do
> this.  i've got 2 options right now:  create a complete hack of my code
> where i duplicate a class and change the methods to work with betwixt
> (yuk) or make betwixt do what i want.  i'd rather spend my time
> producing something useful to others.

oops - i forgot this option. this is adding an extra attribute to the 
.betwixt file that specifies an implementation class - probably a 'class' 
attribute. (this isn't the same as derived beans.)

this should be pretty easy to implement but it's probably not worth 
contributing to right now since it means changes in the code i've just 
moved. i might take a look at this once i've committed the changes i'm 
working on (see below).

how does the name 'class' sound for the betwixt attribute name?

>> custom bean creator
>> -------------------
>> this is what i've been looking at today. betwixt's bean reading will be
>> refactored to use a chain of bean creators rather than a monolithic 
>> method.
>>   this will allow users to plug their own bean creators to create (say)
>> implementations for their interfaces. i like this approach since it's
>> powerful, elegant and flexible. if you like the sound of this then it'll
>> probably be worth waiting around a few days until it's finished.
> if this will be available in a few days, then i'm game.  sounds like a
> nice flexible solution.  for my app, being able to control it on the
> reading end will allow me to plug-in any implementation that i want.
> keep me posted on development and i'll help test it.  is this something
> that would work via .betwixt files?  or runtime config of the
> beanreader?

i've now completed the code and the testing of the refactored reading code.
  i still need to review the package structure and naming, complete the 
documentation and write some tests to check that the custom hooks work 
correctly. i hope to have this finished within the next 24 hours.

>> strategy interface for creating typed objects
>> ---------------------------------------------
>> the ideas is that a hook would be provided to allow a creater to be
>> registered for a particular type of object. unfortunately, i want to
>> implement this as a bean creator so this is a way down the track.
> i wonder if i follow this correctly...  would the creator be on the side
> that writes the XML?  if so, then that would not be as flexible since it
> would force me to make a decision on the actual implementation to use
> before i actually know what it is.  my guess is that i'm
> misunderstanding what this actually means.

i think i've probably confused you. this is probably easier to explain 
once i've committed the code i've been working on.

>> please let me know how this sounds.
> i like the sound of the first & second solutions.  i'm happy to try and
> help though i'm totally new to betwixt/digester and will have a bit of
> ramp-up time.

thanks for the feedback. one of the problems with betwixt is that it's 
poorly structured and difficult to work on unless you spend a lot of time 
looking at the code. hopefully, it's become better factored but it's a 
long process.

> let me know which solution you are leaning toward.  point me in the
> right direction and i'll lend a hand, even if it is just testing.

cool. i hope to post something a little later.

- robert


Re: [betwixt/digester] mapping interfaces to classes

Posted by "Gary S. Cuozzo" <ga...@innovationsw.com>.
> (my apologies that took me a while to answer, i haven't been a bit ill.)
sorry to hear you have been ill.  i sure do appreciate the reply.  was
beginning to think nobody ran across this before, but saw "better
support for interfaces" on the todo list.  :-)


> use derived beans
> -----------------
> this means using an attribute of the xml to specify the class to be 
> created. this need a little work (there is no setting to switch on writing 
> these attributes, there is no beaninfo attribute to customize the 
> attribute name and reading only sets the properties that the interface 
> expresses). i might be persuaded to bring forward adding writing - or you 
> could probably have a go at adding this functionality yourself (its pretty 
> easy). if you do, then maybe you'd care to submit a patch :)
this is probably what i was trying to do with .betwixt files (but
couldn't get it to work).  basically tell betwixt "when you see
AuthInfo, instantiate GenericAuthInfo" or something like that.

if you give me some clues as to where to start, i would be open to do
this.  i've got 2 options right now:  create a complete hack of my code
where i duplicate a class and change the methods to work with betwixt
(yuk) or make betwixt do what i want.  i'd rather spend my time
producing something useful to others.


> custom bean creator
> -------------------
> this is what i've been looking at today. betwixt's bean reading will be 
> refactored to use a chain of bean creators rather than a monolithic method.
>   this will allow users to plug their own bean creators to create (say) 
> implementations for their interfaces. i like this approach since it's 
> powerful, elegant and flexible. if you like the sound of this then it'll 
> probably be worth waiting around a few days until it's finished.
if this will be available in a few days, then i'm game.  sounds like a
nice flexible solution.  for my app, being able to control it on the
reading end will allow me to plug-in any implementation that i want. 
keep me posted on development and i'll help test it.  is this something
that would work via .betwixt files?  or runtime config of the
beanreader?


> strategy interface for creating typed objects
> ---------------------------------------------
> the ideas is that a hook would be provided to allow a creater to be 
> registered for a particular type of object. unfortunately, i want to 
> implement this as a bean creator so this is a way down the track.
i wonder if i follow this correctly...  would the creator be on the side
that writes the XML?  if so, then that would not be as flexible since it
would force me to make a decision on the actual implementation to use
before i actually know what it is.  my guess is that i'm
misunderstanding what this actually means.


> please let me know how this sounds.
i like the sound of the first & second solutions.  i'm happy to try and
help though i'm totally new to betwixt/digester and will have a bit of
ramp-up time.

let me know which solution you are leaning toward.  point me in the
right direction and i'll lend a hand, even if it is just testing.

thank you for the reply.  a solution to this is currently holding up my
project.  i had started researching other options before creating a
(temporary) hack to my project.

gary.


> 
> - robert
> 
> On Sunday, August 17, 2003, at 05:26 AM, Gary S. Cuozzo wrote:
> 
> > I've been struggling with betwixt and trying to get it work with classes
> > that make use of methods that accept/return interfaces.  Is there any
> > way to tell betwixt (or the underlying digester) when it sees an
> > interface in the xml data that it should actually create an instance of
> > some specific class that implements the interface?  or, i suppose the
> > alternative would be have the xml get generated with the class name as
> > opposed to the interface name.
> >
> > Any help is appreciated,
> > gary.
> > --
> > Gary S. Cuozzo <ga...@innovationsw.com>
> > Innovation Software Group, LLC
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
-- 
Gary S. Cuozzo <ga...@innovationsw.com>
Innovation Software Group, LLC


Re: [betwixt/digester] mapping interfaces to classes

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
hi gary

(my apologies that took me a while to answer, i haven't been a bit ill.)

you're probably not going to like this but the bad news is that it's 
difficult to do what you want to do at the moment. the good news is have 
been looking at some stuff related to this recently and so there's a 
change that it might in sometime soonish.

as i see it, there are three basic strategies to accumplish this (but none 
of these currently work fully in betwixt).

use derived beans
-----------------
this means using an attribute of the xml to specify the class to be 
created. this need a little work (there is no setting to switch on writing 
these attributes, there is no beaninfo attribute to customize the 
attribute name and reading only sets the properties that the interface 
expresses). i might be persuaded to bring forward adding writing - or you 
could probably have a go at adding this functionality yourself (its pretty 
easy). if you do, then maybe you'd care to submit a patch :)

custom bean creator
-------------------
this is what i've been looking at today. betwixt's bean reading will be 
refactored to use a chain of bean creators rather than a monolithic method.
  this will allow users to plug their own bean creators to create (say) 
implementations for their interfaces. i like this approach since it's 
powerful, elegant and flexible. if you like the sound of this then it'll 
probably be worth waiting around a few days until it's finished.

strategy interface for creating typed objects
---------------------------------------------
the ideas is that a hook would be provided to allow a creater to be 
registered for a particular type of object. unfortunately, i want to 
implement this as a bean creator so this is a way down the track.

please let me know how this sounds.

- robert

On Sunday, August 17, 2003, at 05:26 AM, Gary S. Cuozzo wrote:

> I've been struggling with betwixt and trying to get it work with classes
> that make use of methods that accept/return interfaces.  Is there any
> way to tell betwixt (or the underlying digester) when it sees an
> interface in the xml data that it should actually create an instance of
> some specific class that implements the interface?  or, i suppose the
> alternative would be have the xml get generated with the class name as
> opposed to the interface name.
>
> Any help is appreciated,
> gary.
> --
> Gary S. Cuozzo <ga...@innovationsw.com>
> Innovation Software Group, LLC
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


[betwixt/digester] mapping interfaces to classes

Posted by "Gary S. Cuozzo" <ga...@innovationsw.com>.
I've been struggling with betwixt and trying to get it work with classes
that make use of methods that accept/return interfaces.  Is there any
way to tell betwixt (or the underlying digester) when it sees an
interface in the xml data that it should actually create an instance of
some specific class that implements the interface?  or, i suppose the
alternative would be have the xml get generated with the class name as
opposed to the interface name.

Any help is appreciated,
gary.
-- 
Gary S. Cuozzo <ga...@innovationsw.com>
Innovation Software Group, LLC