commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ravindra Wankar <rwan...@celoxis.com>
Subject Re: Reading XML as bean collection using Betwixt
Date Tue, 16 Oct 2007 17:19:17 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Chris,<br>
<br>
Thanks for the info. However, I think my case is slightly different.
What I'm trying to do is not have to write the Configuration class that
has the addEntry() and getEntry() methods and instead use an ArrayList
directly. ie I'd like Betwixt to create an ArrayList and populate it
with my POJOs using the add() method of the list.<br>
<br>
-- Ravi<br>
<br>
Christian Grobmeier wrote:
<blockquote
 cite="mid:ded132f10710160735l658a20d4h5843143d95cee4a2@mail.gmail.com"
 type="cite">
  <pre wrap="">Sorry if you get this twice, my email seems not  to get through to the
list,
so i sent it again.



Hi Ravi,
i had the same problems and figured out that i need those .betwixt files.
Imagine a configuration having different entrys.

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;info primitiveTypes="attribute"&gt;
       &lt;element name="configuration" class=''de.grobmeier.Configuration'&gt;
               &lt;element name="entry"
                                property="entry"
                                class='de.grobmeier.Entry'&gt;
                       &lt;addDefaults/&gt;
               &lt;/element&gt;
               &lt;addDefaults/&gt;
       &lt;/element&gt;
&lt;/info&gt;

Here is my Configuration class:

public class Configuration {
   private List&lt;Entry&gt; entries= new ArrayList&lt;Entry&gt;();
public List&lt;Entry&gt; getEntry() {
       return entries;
   }

   public void addEntry(_entry) {
       entries.add(_entry);
   }
}

Mind that addEntry Method please.
My Entry-Class is a simple POJO. I figured out i need a betwixt file
here to, altough i thought this was mapped "by default", however, its
similar to this:

&lt;info primitiveTypes="attribute"&gt;
       &lt;element
               name="entry"
               property="entry"
               class='de.grobmeier.Entry'&gt;
               &lt;attribute name='key' property='key'/&gt;
               &lt;attribute name='value' property='value'/&gt;

      &lt;/element&gt;
&lt;/info&gt;

I had to register only the configuration class:
beanReader.registerBeanClass("configuration", Configuration.class);
           configuration = (Configuration)beanReader.parse(reader);

Hope this helps,
Best,
Chris

On 10/16/07, Ravindra Wankar <a class="moz-txt-link-rfc2396E" href="mailto:rwankar@celoxis.com">&lt;rwankar@celoxis.com&gt;</a>
wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">
 No. I'm trying to get all the person objects into an ArrayList.

 Thanks
 Ravi.


 Eckenfellner Klaus wrote:
 Does your collection-bean have adder-functions for the person-beans?

please see example at
<a class="moz-txt-link-freetext" href="http://commons.apache.org/betwixt/guide/examples.html">http://commons.apache.org/betwixt/guide/examples.html</a>
(bottom of page).

Ravindra Wankar wrote:


 How do I convert an XML to bean collection?

XML:
&lt;persons&gt;
 &lt;person&gt;
 &lt;name&gt;A&lt;/name&gt;
 &lt;age&gt;21&lt;/age&gt;
 &lt;/person&gt;
 &lt;person&gt;
 &lt;name&gt;B&lt;/name&gt;
 &lt;age&gt;25&lt;/age&gt;
 &lt;/person&gt;
 &lt;person&gt;
 &lt;name&gt;C&lt;/name&gt;
 &lt;age&gt;32&lt;/age&gt;
 &lt;/person&gt;
&lt;/persons&gt;

Java code:

beanReader.registerBeanClass("persons", ArrayList.class);
beanReader.registerBeanClass("persons/person", Person.class);
ArrayList persons = (ArrayList)beanReader.parse(xmlReader);

I get an empty list. I'm using Betwixt 0.8, Digester 1.8, BeanUtils 1.7

Thanks
- Ravi.

---------------------------------------------------------------------
To unsubscribe, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-unsubscribe@commons.apache.org">user-unsubscribe@commons.apache.org</a>
For additional commands, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-help@commons.apache.org">user-help@commons.apache.org</a>




---------------------------------------------------------------------
To unsubscribe, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-unsubscribe@commons.apache.org">user-unsubscribe@commons.apache.org</a>
For additional commands, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-help@commons.apache.org">user-help@commons.apache.org</a>



---------------------------------------------------------------------
To unsubscribe, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-unsubscribe@commons.apache.org">user-unsubscribe@commons.apache.org</a>
For additional commands, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-help@commons.apache.org">user-help@commons.apache.org</a>
    </pre>
  </blockquote>
  <pre wrap=""><!---->
---------------------------------------------------------------------
To unsubscribe, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-unsubscribe@commons.apache.org">user-unsubscribe@commons.apache.org</a>
For additional commands, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:user-help@commons.apache.org">user-help@commons.apache.org</a>

  </pre>
</blockquote>
<br>
</body>
</html>

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


Mime
View raw message