Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 29197 invoked by uid 98); 12 Dec 2002 22:30:53 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 29164 invoked from network); 12 Dec 2002 22:30:50 -0000 Received: from daedalus.apache.org (HELO apache.org) (63.251.56.142) by nagoya.betaversion.org with SMTP; 12 Dec 2002 22:30:50 -0000 Received: (qmail 28546 invoked by uid 500); 12 Dec 2002 22:29:36 -0000 Received: (qmail 28539 invoked from network); 12 Dec 2002 22:29:35 -0000 Received: from pcow057o.blueyonder.co.uk (HELO blueyonder.co.uk) (195.188.53.94) by daedalus.apache.org with SMTP; 12 Dec 2002 22:29:35 -0000 Received: from pcow057o.blueyonder.co.uk ([127.0.0.1]) by blueyonder.co.uk with Microsoft SMTPSVC(5.5.1877.757.75); Thu, 12 Dec 2002 22:29:16 +0000 Received: from localhost (unverified [80.194.24.21]) by pcow057o.blueyonder.co.uk (Content Technologies SMTPRS 4.2.9) with ESMTP id for ; Thu, 12 Dec 2002 22:29:16 +0000 Date: Thu, 12 Dec 2002 22:29:37 +0000 Subject: Re: [betwixt] info on .betwixt files, "add" methods, and CyclicReferenceExceptions Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v482) From: robert burrell donkin To: "Jakarta Commons Users List" Content-Transfer-Encoding: 7bit In-Reply-To: <002301c2a22a$e474c820$03f019ac@coachhouse1> Message-Id: <32A8D3E8-0E21-11D7-B2A8-003065DC754C@blueyonder.co.uk> X-Mailer: Apple Mail (2.482) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 stack.search()) 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