commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Darren Scott" <>
Subject RE: [betwixt] info on .betwixt files, "add" methods, and CyclicReferenceExceptions
Date Thu, 12 Dec 2002 22:07:36 GMT
> > 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

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?

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.

Darren Scott

View raw message