On Wed, 21 Mar 2001, Steve A Drake wrote:

>  I'd like to initialize a String[] contained in an object with the
> Digestor (i.e. in a database.xml file). Can I do that? If so, what's the
> syntax? Thanks.
> 
> 

How are you planning to represent the data used to populate the String
array?  You can't use multiple attributes with the same name (XML syntax
rule), so it sounds like you would be using nested elements anyway.  If
so, one approach would be to have a method on your object that adds a
String to the existing collection:

        package com.mycompany.mypackage;
        public class MyObject {
                ...
                public void addString(String newString) {
                    ... add newString to my collection ...
                }
                public String[] getStrings() {
                    ... return the collected Strings as an array ...
                }
                ...
        }

Now, assume your data looked like this:

        <data>
                <string>This is the first string</string>
                <string>And this is the second</string>
                <string>And so on ...</string>
        </data>

With this data format, you can use:

        digester.addObjectCreate("data",
          "com.mycompany.mypackage.MyObject");
        digester.addCallMethod("data/string", "addString", 0);

Craig


Reply via email to