commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Darren Scott" <dar...@darrenscott.com>
Subject RE: [betwixt] info on .betwixt files, "add" methods, and CyclicReferenceExceptions
Date Sat, 14 Dec 2002 00:23:49 GMT
> as i said, i had planned to take a look at creating a fix in 
> any case. if 
> you do make progress before then let me know so that i can 
> look at adding 
> some other features instead :)
> 
> - robert

I think I've got a fix for unexpected CyclicReferenceExceptions. Robert
asked me to provide a cvs diff -u for the fix - I've never used -u on
diff before and it seemed to produce a LOT of output, so here's output
from a regular diff between my working copy and the top of the source
tree (1.6):

RCS file:
/home/cvspublic/jakarta-commons/betwixt/src/java/org/apache/commons/betw
ixt/io/AbstractBeanWriter.java,v
retrieving revision 1.6
diff -w -r1.6 AbstractBeanWriter.java
71a72
> import java.util.Stack;
106a108,109
>     /** Stack containing ID attribute values for beans seen so far in
this graph */
>     protected Stack idStack = new Stack();
183c186
<             log.trace( "Writing bean graph (qualified name '" +
qualifiedName + "'" );
---
>             log.trace( "Writing bean graph (qualified name '" +
qualifiedName + "')" );
210c213
<                     if ( ref == null ) {
---
>                     if ( idStack.search( bean ) == -1 ) {
216a220
>                             idStack.push( bean );
249a254
>                             idStack.push( bean );
256a262,264
> 
>                         // about to finish writing this bean - no need
to remember it any more
>                         idStack.pop();

Basically, as well as recording bean IDs in a Hashmap, we now also
maintain a stack of beans currently being written. Each time we see a
new bean we add the bean to the stack before recursing further down the
graph by calling write(). When we leave the write() method, we pop the
bean off the stack as we are no longer interested in it (at least for
the purposes of checking for cycles). The decision as to whether a cycle
exists is then based on whether the bean is already in the stack - if it
is, we have already seen it as part of this graph and hence there is a
cycle. This means that multiple occurences that are not part of a cycle
no longer produce a CyclicReferenceException.

Give it a go and let me know if you think it works.

Regards,

Darren



Mime
View raw message