commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Inger, Matthew" <In...@Synygy.com>
Subject RE: [betwixt][lang] Persisting Enum's via Betwixt
Date Thu, 06 May 2004 16:15:28 GMT
Whatever you're reading in has to have a default constructor

To avoid having this directly in your enum itself,
you should be able to create a proxy class for your
enum which can be the object which is serialized.
The TemplateType will be converted to this type upon
write, and the proxy converted back to TemplateType on
read.

public class TemplateTypeProxy implements Serializable {
   private String name;

   public TemplateTypeProxy() {
   }

   public void setName(String name) {
      this.name =name;
   }

   public String getName() {
      return name;
   }

   public Object readObject() {
       if (name.equals(TemplateType.KP.getValue())) {
          return TemplateType.KP;
       else if (name.equals(TemplateType.IC50.getValue())) {
          return TemplateType.IC50;
       else
          return null;
   }
}

public final class TemplateType extends Enum {
    ...

    public Object writeObject() {
       return new TemplateTypeProxy(getValue());
    }
}


This of course, assumes that Betwixt pays attention
to the Serializable interface, and these methods.

-----Original Message-----
From: Eric Pugh [mailto:epugh@upstate.com]
Sent: Thursday, May 06, 2004 9:02 AM
To: Commons-Dev
Subject: [betwixt][lang] Persisting Enum's via Betwixt 


Hi all,

I am attempting to persist my custom Enumeration that extends Enum via
Betwixt, however, I can't seem to get it to read back in.  It writes out
fine, but not back in.  Does anyone have a unit test demonstrating this?
Does this need to be added to Betwixt?

It seems likely maybe I am stumbling over something with statics maybe?  Or
final keyword?

Eric Pugh

xml:

<templateType id="3">
    <enumClass>class
com.upstate.kinaseprofiler.reactiongenerator.TemplateType</enumClass>
    <name>KP</name>
  </templateType>

java:
public final class TemplateType extends Enum
{
    public static final TemplateType KP = new TemplateType("KP");
    public static final TemplateType IC50 = new TemplateType("IC50");

    public TemplateType(String color)
    {
        super(color);
    }

    public static TemplateType getEnum(String type)
    {
        return (TemplateType) getEnum(TemplateType.class, type);
    }
	public static void setEnum(String type)
	{
		this =  getEnum(TemplateType.class, type);
	}
    public static Map getEnumMap()
    {
        return getEnumMap(TemplateType.class);
    }

    public static List getEnumList()
    {
        return getEnumList(TemplateType.class);
    }

    public static Iterator iterator()
    {
        return iterator(TemplateType.class);
    }


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

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


Mime
View raw message