commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Dudziak <tom...@gmail.com>
Subject Re: [Betwixt] Java 5.0 enum
Date Sat, 07 Jan 2006 18:28:07 GMT
On 1/7/06, vachevil-basic@yahoo.com <vachevil-basic@yahoo.com> wrote:

> Is there any way to support a JDK 5.0 Enum in Betwixt?  At the moment it jus defines:
>     <entityType>
>       <declaringClass>net......EntityType</declaringClass>
>     </entityType>
>
> without any of the selected value.

I think, a converter will help you there:

for reading:

BeanReader reader = ...

reader.getBindingConfiguration().setObjectStringConverter(new
EnumStringConverter());


for writing:

BeanWriter writer = ...

writer.getBindingConfiguration().setObjectStringConverter(new
EntityTypeStringConverter());


and the converter itself something like:

public class EntityTypeStringConverter extends ConvertUtilsObjectStringConverter
{
  public String objectToString(Object object, Class type, Context context)
  {
    return EntityType.class.equals(type) ?
               ((EntityType)object).name() :
               super.objectToString(object, type, context);
  }

  public Object stringToObject(String value, Class type, Context context) {
    return EntityType.class.equals(type) ?
               Enum.valueOf(EntityType.class, value) :
               super.stringToObject(value, type, context);
  }
}

To use this, I think you have to define a .betwixt file or a mapping
file and map the property returning the enum to an XML attribute.

Tom

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


Mime
View raw message