Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 18739 invoked from network); 23 Mar 2006 11:22:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Mar 2006 11:22:15 -0000 Received: (qmail 27861 invoked by uid 500); 23 Mar 2006 11:22:03 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 27813 invoked by uid 500); 23 Mar 2006 11:22:03 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: 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 27802 invoked by uid 99); 23 Mar 2006 11:22:03 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Mar 2006 03:22:03 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [192.151.27.10] (HELO mailhub.hp.com) (192.151.27.10) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Mar 2006 03:22:02 -0800 Received: from [127.0.0.1] (179.Red-81-47-192.staticIP.rima-tde.net [81.47.192.179]) by mailhub.hp.com (Postfix) with ESMTP id 6D91327140 for ; Thu, 23 Mar 2006 06:21:40 -0500 (EST) Message-ID: <442284BB.2060607@hp.com> Date: Thu, 23 Mar 2006 12:21:31 +0100 From: =?ISO-8859-1?Q?Marcos_Truchado_Mart=EDn?= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.0.1) Gecko/20060130 SeaMonkey/1.0 MIME-Version: 1.0 To: Jakarta Commons Users List Subject: betwixt and mixed collections Content-Type: multipart/mixed; boundary="------------050206060303070207080901" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------050206060303070207080901 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Hi all, I�m having a problem trying to parse mixed collections. This is what I obtaint if I parse my bean to a XML file: atr1 atr2 atr21 otherelemt1 otherelemt2 otherelemt3 otherelemt4 This is correct and it�s the result I�m expecting. The problem comes when I try to parse this XML into a bean. Betwixt seems not to recognice the type of the elements under the Vector and it create instances of Object instead the right ones. If I parse the above XML into a bean and then into a XML again I obtaint: Every element is parsed as Object. The source code I�m using (including the dot betwixt files) is attached to this mail. Note that if I turn on MapIDs property under the binding configuration the result is correct but I get some id="number" attributes that must not be there for my needs. Thanks in advance. --------------050206060303070207080901 Content-Type: text/plain; name="Parser.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Parser.java" package testbetwixt; public class Parser { public static void main(String[] args) { Container c = new Container(); ElementImpl1 e1 = new ElementImpl1(); e1.setAtr1("atr1"); e1.setAtr2("atr2"); ElementImpl2 e2 = new ElementImpl2(); e2.setAtr1("atr21"); e2.addOtherElement("otherelemt1"); e2.addOtherElement("otherelemt2"); e2.addOtherElement("otherelemt3"); e2.addOtherElement("otherelemt4"); c.addElement(e1); c.addElement(e2); try { System.out.println(c.toXML()); System.out.println("<======================>"); System.out.println(Container.parseXML(c.toXML()).toXML()); } catch(Exception e) { e.printStackTrace(); } } } --------------050206060303070207080901 Content-Type: text/xml; name="Container.betwixt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Container.betwixt" --------------050206060303070207080901 Content-Type: text/plain; name="Container.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Container.java" package testbetwixt; import java.beans.IntrospectionException; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.util.Collection; import java.util.Vector; import org.apache.commons.betwixt.io.BeanReader; import org.apache.commons.betwixt.io.BeanWriter; import org.xml.sax.SAXException; public class Container { private Vector elements; public Container() { this.elements = new Vector(); } public void addElement(Object element) { this.elements.add(element); } public Collection getElements() { return this.elements; } public String toXML() throws IOException, IntrospectionException, SAXException { StringWriter outputWriter = new StringWriter(); outputWriter.write("\n"); BeanWriter beanWriter = new BeanWriter(outputWriter); beanWriter.getBindingConfiguration().setMapIDs(false); beanWriter.enablePrettyPrint(); beanWriter.write("container", this); String ret = outputWriter.toString(); outputWriter.close(); return ret; } public static Container parseXML(String xml) throws IOException, SAXException, IntrospectionException { StringReader xmlReader = new StringReader(xml); BeanReader beanReader = new BeanReader(); beanReader.getBindingConfiguration().setMapIDs(false); beanReader.registerBeanClass("container", Container.class); return (Container) beanReader.parse(xmlReader); } } --------------050206060303070207080901 Content-Type: text/xml; name="ElementImpl1.betwixt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ElementImpl1.betwixt" --------------050206060303070207080901 Content-Type: text/plain; name="ElementImpl1.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ElementImpl1.java" package testbetwixt; public class ElementImpl1 { private String atr1; private String atr2; public ElementImpl1() { this.atr1 = ""; this.atr2 = ""; } public void setAtr1(String atr1) { this.atr1 = atr1; } public String getAtr1() { return atr1; } public void setAtr2(String atr2) { this.atr2 = atr2; } public String getAtr2() { return atr2; } } --------------050206060303070207080901 Content-Type: text/xml; name="ElementImpl2.betwixt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ElementImpl2.betwixt" --------------050206060303070207080901 Content-Type: text/plain; name="ElementImpl2.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ElementImpl2.java" package testbetwixt; import java.util.Iterator; import java.util.Vector; public class ElementImpl2 { private String atr1; private Vector moreElements; public ElementImpl2() { this.atr1 = ""; this.moreElements = new Vector(); } public void setAtr1(String atr1) { this.atr1 = atr1; } public String getAtr1() { return atr1; } public void addOtherElement(String elemento) { this.moreElements.add(elemento); } public Iterator getOtherElementIterator() { return this.moreElements.iterator(); } } --------------050206060303070207080901 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org --------------050206060303070207080901--