Hi Ray,

On Sat, 2005-05-14 at 10:14 +0100, Ray wrote:
> public class DataItem {
> 
>     private DataString name = new DataString();
>     private DataString postcode = new DataString();
> 
>     public DataString getName();
>     public void setName(DataString name);
>     public DataString getPostcode();
>     public void setPostcode(DataString postcode);
> 
> }
> 
> 
> public class DataString {
> 
>     private String value;
> 
>     public String getValue();
>     public void setValue(String name);
> 
>   
> }
> 
> 
> Okay, I have the following XML data
> 
> <Request>
>     <DataItem>
>         <Name>Frederick</Name>
>         <Postcode>xxx112223</Postcode>
>     </DataItem>
> </Request>
> 

I think you could solve this by registering a custom converter that can
convert String objects into DataString objects. 

When Digester needs to call a method that takes a non-string parameter,
but it has just the string data extracted from the XML it uses the
beanutils ConvertUtils library to do the appropriate conversion. It
looks to me like you just need to tell ConvertUtils how to create a
DataString out of a String..

ConvertUtils.register(DataString.class, new Converter()) {
  public Object convert(Class Type, Object value) {
    if (value == null)
        return null;
    else
        return new DataString(value.toString());
  }
}

I presume a DataString has a constructor that takes a String. If not,
obviously creating an empty one and setting the value is also possible.

See here for details on beanutils:
  http://jakarta.apache.org/commons/beanutils

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to