commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert burrell donkin <>
Subject Re: [betwixt] info on .betwixt files, "add" methods, and CyclicReferenceExceptions
Date Thu, 12 Dec 2002 22:29:37 GMT

On Thursday, December 12, 2002, at 10:07 PM, Darren Scott wrote:

>>> The cyclic checking isn't that advanced yet. The scenario that A
>>> refers to another A is covered however. Since the cyclic stuff also
>>> has some relation when you use id's (and I am not into id's that
>>> much), I probably have to have some help with the id
>> handling. Time to
>>> read some specs on that :)
>> yeh. i've been wanting to improve this for some time now.
>> your understanding of a cyclic graph is correct. the problem
>> is that at
>> the moment, betwixt is pretty dumb and will throw a cycle reference
>> exception if it encounters the same bean if id's aren't been written.
>> i have played about with various ways of improving the
>> situation but they' ve all proved unsatisfactory. probably
>> the basic betwixt design needs to
>> be improved.
> I've been looking into this a bit more, particularly at the main write()
> method in AbstractBeanWriter.  I think the use of a HashMap to store a
> record of previous visits to beans in the graph may be the cause of the
> problem. As this only stores a single reference to whether the bean has
> been seen anywhere before, this covers both genuine cyclic references
> and multiple non-cyclic references, which is incorrect (does this make
> sense?!)
> Wouldn't a stack based implementation be more suitable i.e. every time
> we recurse further down the graph by calling write() again, we push the
> current bean on the stack and when we work our way back up the graph and
> leave the write() method, we pop the bean off the stack. This way when
> we check whether the bean has been seen before (using we
> are only checking for genuine cyclic references and not just multiple
> (non-cyclic) references. When we get back to where we started, the stack
> will be empty ready for the next bean...
> Does this solution sound reasonable?

the way i see it, there are two different issues:

1. ID-IDREF support. the hash map is useful for this implementation. 
(there is still quite a lot of work to do on this.)

2. detecting cycles properly. i agree that this is best done with a stack.

> I've almost got this working (I'm not getting CyclicReferenceExceptions
> any more but I seem to have broken something else as my XML doesn't pay
> any attention to the .betwixt files!) As soon as I've got a working
> solution I'll post again.

i have been down this road before. i did start playing around with stacks 
but betwixt is hard to change without breaking things.

i have some time this weekend and i was going to take a look at this 
(provided that i can build maven by then). if you don't have the time to 
track down the problems by then, if you post your diff's (cvs diff -u, 
please) i'll (try to) finish the work off.

- robert

View raw message