You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by b p <tr...@yahoo.com> on 2004/01/20 19:08:21 UTC

[betwixt] Collections not set when using .betwixt file

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 <addDefaults/> tag in the .betwixt file.  However, I need a .betwixt file and I would rather not use the <addDefaults/> 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("<?xml version='1.0' ?>\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
<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="attribute">
    <element name='father'>
        <element name='children' property='kids'/>
    </element>
</info>

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

Re: [betwixt] Collections not set when using .betwixt file

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
On 22 Jan 2004, at 18:13, b p wrote:

> 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).

that sounds interesting. we'd need to have a signed grant form from 
your employers before we could accept the code but if the legalese 
doesn't frighten you guys, let me know and i'll

> 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.

fine

> 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?

that's not an easy question to answer (for various reasons).

the first is the question about whether the code's ready. it's unlikely 
that the branch will be ready to release for a while, realistically a 
month and maybe more. there are a lot more interface changes i'm 
planning and i'm not really willing to release and support code that i 
know is going to be deprecated soon. CVS HEAD is stable and ready for a 
0.x release (which indicates that the code's ok but the interfaces are 
not really stable).

the second question is whether there's a suitable release manager. i'm 
not on the pmc at the moment and so i can't/won't cut releases. there 
are other committers who are (mildly) interested in cutting a release 
for betwixt but it isn't a priority for them. if one of them suddenly 
wanted to cut a 0.5 (from HEAD) i'd probably support them.

so the best answer i can give is probably not soon with a HEAD release 
more likely than the branch. (it is worth remembering that lobbying 
will sometime make a difference to these timescales.)

- robert


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [betwixt] Collections not set when using .betwixt file

Posted by b p <tr...@yahoo.com>.
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 <ro...@blueyonder.co.uk> 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!

Re: [betwixt] Collections not set when using .betwixt file

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
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 <ro...@blueyonder.co.uk> 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


Re: [betwixt] Collections not set when using .betwixt file

Posted by b p <tr...@yahoo.com>.
Hi Robert,
Thanks for the update.  Looks like it will work great for my needs.   
 
-Brian
 

robert burrell donkin <ro...@blueyonder.co.uk> 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

Re: [betwixt] Collections not set when using .betwixt file

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
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 <addDefaults/> tag in the .betwixt file.  However, I need a  
> .betwixt file and I would rather not use the <addDefaults/> 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("<?xml version='1.0' ?>\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
> <?xml version="1.0" encoding="UTF-8" ?>
> <info primitiveTypes="attribute">
>     <element name='father'>
>         <element name='children' property='kids'/>
>     </element>
> </info>
>
> 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