You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steve A Drake <sa...@comet.ucar.edu> on 2001/03/22 00:11:22 UTC

config String[] with Digestor

 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.


Re: config String[] with Digestor

Posted by Martin Cooper <ma...@tumbleweed.com>.
One possibility would be to have an XML syntax like this:

  <your-object>
    <your-object-element>The first string</your-object-element>
    <your-object-element>The second string</your-object-element>
    etc.
  </your-object>

Then you configure the digester to call a method each time it sees a
<your-object-element>, and that method appends the string to the end of your
string array.

--
Martin Cooper


----- Original Message -----
From: "Steve A Drake" <sa...@comet.ucar.edu>
To: <st...@jakarta.apache.org>
Sent: Wednesday, March 21, 2001 3:11 PM
Subject: config String[] with Digestor


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



Re: config String[] with Digestor

Posted by "Craig R. McClanahan" <cr...@apache.org>.

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