Hi Mario,

For a class:

public class Data {
          public static enum Directions { NORTH, SOUTH, EAST, WEST }

          private Directions dir;

          public Data(String s) {
                dir = Directions.valueOf(s);
          }

           public String toString() {
                        return dir.toString();
            }

                public Directions getDir() {
                        return dir;
                }

                public void setDir(Directions dir) {
                        this.dir = dir;
                }
}

You can have a coder:

public class DataCoder implements IStreamCoder {
        public String getPeerClassName() {
                return Data.class.getName();
        }

        public void writeObject(IObjectOutputStream out, Object data) {
                try {
                        out.writeObject(((Data) data).getDir().name());
                } catch (IOException e) {
                        e.printStackTrace();
                }

        }

        public Object readObject(IObjectInputStream in) throws IOException {
                String o = (String) in.readObject();
                Data p = new Data(o);
                return p;
        }

}

Basically, you need to pass enough info in writeObject so that you can
construct the corresponding enum value.

I hope this helps.

Thanks and regards,

Janak

>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] Behalf Of Mario H.
>Castillo
>Sent: Monday, October 09, 2006 8:51 PM
>To: [EMAIL PROTECTED] Com
>Subject: Re: [ULC-developer] Inner class encoder
>
>
>Hi Janak,
>
>If I do not build a coder for the static enum member I get this error from
>ULC:
>
>17  09.10.2006 11:16:52.640 1,000 SEVERE Thread[ULC Communication
>Controller
>Thread,6,main] com.ulcjava.base.client.UISession$k_ run exception occured
>[com.ulcjava.base.client.ConnectorException: error while sending requests
> at
>com.ulcjava.base.development.DevelopmentConnector.sendRequests(Deve
>lopmentConnector.java:0)
> at com.ulcjava.base.client.UISession$k_.run(UISession$k_.java:11)
> at java.lang.Thread.run(Thread.java:595)
>Caused by: com.ulcjava.base.shared.internal.IllegalArgumentException: No
>coder registered for class
>mo.ide.ulc.shared.propertyinspector.PropertyFactory$PropertyIds
> at
>com.ulcjava.base.shared.internal.UlcObjectOutputStream.a(UlcObjectO
>utputStream.java:4)
> at
>com.ulcjava.base.shared.internal.UlcObjectOutputStream.writeObject(
UlcObjectOutputStream.java:105)
>
>Where "PropertyIds"  is a enum static member in PropertyFactory.
>
>public class PropertyFactory {
>
>     public static enum PropertyIds {
>        Dummy
>    };
>
>}
>
>Mario
>----- Original Message -----
>From: "Janak Mulani" <[EMAIL PROTECTED]>
>To: "Mario H. Castillo" <[EMAIL PROTECTED]>
>Cc: "[EMAIL PROTECTED] Com" <[EMAIL PROTECTED]>
>Sent: Monday, October 09, 2006 9:04 AM
>Subject: RE: [ULC-developer] Inner class encoder
>
>
>> Hi Mario,
>>
>> I don't understand why you want to write a coder for the enum type.
>>
>> As I said in my earlier mail you need to define a coder for the
>class that
>> defines the enum within it. I.e. you should define a coder for
>your class
>> A.
>>
>> Your class A will have members of type PropertyIds and when you
>> serialize/deserialize A and these members will be written/read correctly.
>>
>> Therefore, the only reason you should make your enum type public is when
>> you
>> want to use thei type (A.PropertyIds) in another class.
>>
>> BTW, the following does not make sense and is syntactically wrong too:
>>
>>>Class a{
>>>    String name
>>>
>>>    static enum propertyids b{
>>>        Dummy;
>>>    }
>>> }
>>>
>>
>> Thanks and regards,
>>
>> Janak
>>
>>>-----Original Message-----
>>>From: [EMAIL PROTECTED]
>>>[mailto:[EMAIL PROTECTED] Behalf Of Mario H.
>>>Castillo
>>>Sent: Thursday, October 05, 2006 10:22 PM
>>>To: [EMAIL PROTECTED] Com
>>>Subject: [ULC-developer] Inner class encoder
>>>
>>>
>>>Janak,
>>>
>>>If I have the following module :
>>>
>>>Class a{
>>>    String name
>>>
>>>    static enum propertyids b{
>>>        Dummy;
>>>    }
>>> }
>>>
>>>
>>>How do write the coder for the inner "class propertyids" since I
>>>need access
>>>to the private class a.propertyids? For now, I made it public, but if
>>>I continue like this, I will have to expose all kinds of internals
>>>to build
>>>these coders. Any suggestions?
>>>
>>>Class a{
>>>    String name
>>>
>>>    public static enum propertyids b{
>>>        Dummy;
>>>    }
>>> }
>>>
>>>Mario
>>>Abacus Research
>>>
>>>_______________________________________________
>>>ULC-developer mailing list
>>>[email protected]
>>>http://lists.canoo.com/mailman/listinfo/ulc-developer
>>
>
>_______________________________________________
>ULC-developer mailing list
>[email protected]
>http://lists.canoo.com/mailman/listinfo/ulc-developer

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to