Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 80400 invoked from network); 22 Jan 2004 18:13:59 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 22 Jan 2004 18:13:59 -0000 Received: (qmail 89001 invoked by uid 500); 22 Jan 2004 18:13:43 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 88949 invoked by uid 500); 22 Jan 2004 18:13:43 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 88835 invoked from network); 22 Jan 2004 18:13:42 -0000 Received: from unknown (HELO web11701.mail.yahoo.com) (216.136.172.67) by daedalus.apache.org with SMTP; 22 Jan 2004 18:13:42 -0000 Message-ID: <20040122181345.18989.qmail@web11701.mail.yahoo.com> Received: from [12.110.19.201] by web11701.mail.yahoo.com via HTTP; Thu, 22 Jan 2004 10:13:45 PST Date: Thu, 22 Jan 2004 10:13:45 -0800 (PST) From: b p Subject: Re: [betwixt] Collections not set when using .betwixt file To: Jakarta Commons Users List In-Reply-To: <8D411612-4C52-11D8-8DC1-003065DC754C@blueyonder.co.uk> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-379869736-1074795225=:18820" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --0-379869736-1074795225=:18820 Content-Type: text/plain; charset=us-ascii Hi Robert, I have not noticed a major problem with performance at this point, but that is partially because I have created my own Introspector. Basically, I created an Introspector that reads a single mapping file that has the equivalent of all the .betwixt files (this allows me to go to and from multiple XML formats by just sending a different mapping file to the Introspector). As part of processing the mapping file, the XMLBeanInfo's are created and put in the registry. So I take a one time hit (at startup) to process the entire mapping file and do any reflection that is required, but then every time I read or write something, I already have a fully loaded registry of XMLBeanInfos. If you are interested in that kind of an Introspector, I have spoken to my employer and I can donate the code (although I don't have it completely stable and tested yet). With regards to using a byte code manipulator to generate XMLBeanInfos, that is not something I could work on now (at least not on my employer's time). However, that may change in a few months if we decide to continue with betwixt (so far, so good) and are ready to start looking more closely at performance and optimizations. One question I have had is regarding the road map for betwixt. The last official release (alpha) was quite a while back. Are there plans for another release in the near future? -Brian robert burrell donkin wrote: cool. there is one more thing i'd like to mention: betwixt is slow. one reason why it's slow is that it uses reflection. if you do run into performance issues, then generating XMLBeanInfo's is probably the answer (either as source or using a byte code library such as http://sourceforge.net/projects/cglib/). i'm probably not going to be able to get round to this any time soon but if you (or any other volunteer ;) fancies taking this one on, post to this list and i'll be glad to help as much as i can. - robert On 21 Jan 2004, at 16:13, b p wrote: > Hi Robert, > Thanks for the update. Looks like it will work great for my needs. > > -Brian > > > robert burrell donkin wrote: > hi brian > > many thanks for the test case. > > (i had a bit of an accident whilst chopping onions for my tea today and > can't type very well so my apologies if i'm a little short and haven't > added the usual tests and documentation.) > > there is a reason why the default adders are set in addDefaults: it > allows users to set custom adders on a per-property basis. however, i'm > not too sure whether this is working right now. > > so, what i've added is support for a couple of extra attributes on > addDefaults. setting add-properties='false' will prevent any extra > properties from being added. i hope you'll forgive me if i direct you > to the test case rather than explain too much more. > > i hope that this will provide a workable solution. if not, then don't > be afraid to speak up. > > - robert > > On 20 Jan 2004, at 18:08, b p wrote: > >> Hi Robert, >> I've run into a issue with collections that I can work around, but I >> am hoping can be solved more cleanly with a fairly simple modification >> to the ElementRule class. >> >> Here's the situation. I have a bean that includes a composite >> property as well as some properties that I do not want written to XML >> or set when XML is read. Therefore, I created a .betwixt file that >> includes the composite property, but does not include the property I >> want ignored. When I create XML from the bean, it looks exactly >> right. However, when I read it back in, the bean does not have the >> composite property set. >> >> The composite property is set if I have no .betwixt file or include >> the tag in the .betwixt file. However, I need a >> .betwixt file and I would rather not use the tag >> because if I do, I'll have to explicitly "hide" all the properties I >> want ignored in the .betwixt file. For maintenance reasons, I'd >> rather be able to just write the .betwixt file once and not have to >> change it if new properties are added to the bean that do not pertain >> to the XML generation/reading. >> >> I included below a test case and a patch that causes the test case to >> pass and doesn't break any other unit tests (I tested against your >> refactoring branch). >> >> Is there a better way to solve this problem? If not, would it be >> possible to commit the patch? >> >> Thanks again for the continued help. >> Brian >> >> >> Test Case: >> >> TestLoopType.java >> package org.apache.commons.betwixt.dotbetwixt; >> >> import junit.framework.Test; >> import junit.framework.TestSuite; >> import junit.framework.TestCase; >> import junit.textui.TestRunner; >> >> import java.util.ArrayList; >> import java.util.List; >> import java.io.StringWriter; >> import java.io.StringReader; >> >> import org.apache.commons.betwixt.io.BeanWriter; >> import org.apache.commons.betwixt.io.BeanReader; >> >> /** >> * @author Brian Pugh >> */ >> public class TestLoopType extends TestCase { >> >> public void testSimpleList() throws Exception { >> Father father = new Father(); >> father.setSpouse("Julie"); >> father.addKid("John"); >> father.addKid("Jane"); >> >> StringWriter outputWriter = new StringWriter(); >> >> outputWriter.write("\n"); >> BeanWriter beanWriter = new BeanWriter(outputWriter); >> beanWriter.enablePrettyPrint(); >> beanWriter.getBindingConfiguration().setMapIDs(true); >> beanWriter.write(father); >> >> BeanReader beanReader = new BeanReader(); >> >> // Configure the reader >> beanReader.registerBeanClass(Father.class); >> StringReader xmlReader = new StringReader(outputWriter.toString()); >> >> //Parse the xml >> Father result = (Father)beanReader.parse(xmlReader); >> >> assertNotNull("Unexpected null list of children!", >> result.getKids()); >> assertEquals("got wrong number of children", >> father.getKids().size(), result.getKids().size()); >> assertNull("Spouse should not get set because it is not in the >> .betwixt file", result.getSpouse()); >> } >> >> public static Test suite() { >> return new TestSuite(TestLoopType.class); >> } >> >> public static void main(String[] args) { >> TestRunner.run(suite()); >> } >> >> >> } >> >> >> Father.java >> package org.apache.commons.betwixt.dotbetwixt; >> >> import java.util.List; >> import java.util.ArrayList; >> >> /** >> * @author Brian Pugh >> */ >> public class Father { >> >> private List kids; >> private String spouse; >> >> public String getSpouse() { >> return spouse; >> } >> >> public void setSpouse(String spouse) { >> this.spouse = spouse; >> } >> >> public List getKids() { >> return kids; >> } >> >> public void addKid(String kid) { >> if (this.kids == null) { >> this.kids = new ArrayList(); >> } >> this.kids.add(kid); >> } >> >> } >> >> Father.betwixt >> >> >> >> >> >> >> >> Patch: >> >> ? >> betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/Father.betwixt >> ? betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/Father.java >> ? >> betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/ >> TestLoopType.java >> Index: >> betwixt/src/java/org/apache/commons/betwixt/digester/ >> AddDefaultsRule.java >> =================================================================== >> RCS file: >> /home/cvspublic/jakarta-commons/betwixt/src/java/org/apache/commons/ >> betwixt/digester/AddDefaultsRule.java,v >> retrieving revision 1.9.2.3 >> diff -u -r1.9.2.3 AddDefaultsRule.java >> --- >> betwixt/src/java/org/apache/commons/betwixt/digester/ >> AddDefaultsRule.java 18 Jan 2004 19:21:17 -0000 1.9.2.3 >> +++ >> betwixt/src/java/org/apache/commons/betwixt/digester/ >> AddDefaultsRule.java 20 Jan 2004 17:42:09 -0000 >> @@ -128,10 +128,7 @@ >> } >> } >> >> - // default any addProperty() methods >> - getXMLIntrospector().defaultAddMethods( >> - >> getRootElementDescriptor(), >> - beanClass ); >> + >> } >> >> >> Index: >> betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java >> =================================================================== >> RCS file: >> /home/cvspublic/jakarta-commons/betwixt/src/java/org/apache/commons/ >> betwixt/digester/ElementRule.java,v >> retrieving revision 1.13.2.4 >> diff -u -r1.13.2.4 ElementRule.java >> --- >> betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java >> 18 Jan 2004 22:25:22 -0000 1.13.2.4 >> +++ >> betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java >> 20 Jan 2004 17:42:10 -0000 >> @@ -201,6 +201,14 @@ >> */ >> public void end(String name, String namespace) { >> Object top = digester.pop(); >> + // default any addProperty() methods >> + Object parent = digester.peek(); >> + if ( parent instanceof XMLBeanInfo ) { >> + XMLBeanInfo beanInfo = (XMLBeanInfo) parent; >> + getXMLIntrospector().defaultAddMethods( >> + >> beanInfo.getElementDescriptor(), >> + beanClass ); >> + } >> } >> >> >> --------------------------------- >> Do you Yahoo!? >> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-user-help@jakarta.apache.org > > > --------------------------------- > Do you Yahoo!? > Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org --------------------------------- Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! --0-379869736-1074795225=:18820--