commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frost, Gary [IT]" <>
Subject RE: [Betwixt] object mapping question
Date Tue, 20 May 2003 05:06:28 GMT
I believe the convention with type-safe enums it to ensure that you include
a toString method that provides a string representation of the given enum
instance.  And also to provide a 
	public static <<TypeSafeEnumClass>> valueOf(String value)

That returns the TypeSafeEnumClass instance whose string representation
matches the supplied parameter (IllegalArgumentException otherwise).

public final class MyEnum
	private String stringValue;
	private MyEnum(String stringValue)
		this.stringValue = stringValue;

	private static final String _FOO = "FOO";
	private static final String _BAR = "BAR";

	public static final MyEnum FOO = new MyEnum(_FOO);
	public static final MyEnum BAR = new MyEnum(_BAR);

	public String toString()
		return stringValue;

	public static MyEnum valueOf(String stringValue)
		if (_FOO.equals(stringValue))
			return FOO;	
		if (_BAR.equals(stringValue))
			return BAR;
		throw new IllegalArgumentException("Invalid stringValue for

-----Original Message-----
From: Larry Young []
Sent: Tuesday, 20 May 2003 7:23 AM
Subject: [Betwixt] object mapping question


         I have a situation where I'm using the "type-safe enum" pattern 
where an immutable object represents an enumerable value.  These objects 
never have public accessor/mutator methods since they are immutable, and 
their ctor's are private so that the enclosing class can limit the list of 
legal enum values.  The object itself represents a particular enumerable 
value, so simple "==" is used for testing.

         One of the beans that I want to use with betwixt has a data member 
which is one of these type-safe enum objects.  My bean has "set/get" 
methods for the enum object, but that object has no set/get methods of its 
own, so all I get in the XML is an empty tag.

         Is there a way to tell betwixt that for a particular datamember, 
use a particular mapping for its values?  Or, is there a class that betwixt 
will use where I can extend and provide the custom mapping?

         As a small side note, how does betwixt handle other immutable 
types like Integer, Long, String?

         Any help is greatly appreciated.

--- regards ---

Larry Young
The Dalmatian Group  

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message