i haven't used the code but it did prove very useful. the version i committed uses instance equality (==) rather than equals to determine whether a bean is it's own ancester. it also uses the stack implementation in jakarta-commons-collections for greater backwards compatibility. in addition, i've tried to protect the ways that subclasses can access the stack.
- robert
On Saturday, December 14, 2002, at 12:23 AM, Darren Scott wrote:
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 :)- robertI 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 71a72import java.util.Stack;106a108,109/** Stack containing ID attribute values for beans seen so far inthis 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 ) {216a220idStack.push( bean );249a254idStack.push( bean );256a262,264// about to finish writing this bean - no needto remember it any moreidStack.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 -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]. org> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]. org>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
