Java enum in Flex3

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Java enum in Flex3

sundaramoorthy kanagarajan
How to convert java enum values into Flex3 object.
Any one went thru this problem?
Please give your experties?

Sundar

Reply | Threaded
Open this post in threaded view
|

RE: Java enum in Flex3

Seth Hodgson
BlazeDS and LCDS roundtrip Java enums to the client and back as Strings. That's the only good option at present, and here's an in-depth explanation: http://greetingsfromoakland.blogspot.com/2009/02/enums.html

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On Behalf Of sunmoorthy1
Sent: Monday, December 29, 2008 1:18 PM
To: [hidden email]
Subject: [flexcoders] Java enum in Flex3

How to convert java enum values into Flex3 object.
Any one went thru this problem?
Please give your experties?

Sundar
Reply | Threaded
Open this post in threaded view
|

RE: Java enum in Flex3

Maciek Sakrejda
Interesting. Any thoughts on Granite Data Services' approach? There is a
custom externalization process for Java Enum objects, and a granite Enum
class in ActionScript that all your (generated) Enums extend. The enum
class takes care of reading/writing. The writeExternal() method just
writes the name of the Enum; readExternal() tries to find the name of
the object in the constants defined by the Enum. The RemoteAlias
metadata is set up as for a standard Java class.

Are we asking for trouble in using this method? Is there something
inherently dangerous here?
--
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

-----Original Message-----
From: Seth Hodgson <[hidden email]>
Reply-To: [hidden email]
To: [hidden email] <[hidden email]>
Subject: RE: [flexcoders] Java enum in Flex3
Date: Wed, 4 Feb 2009 16:20:33 -0800

BlazeDS and LCDS roundtrip Java enums to the client and back as Strings.
That's the only good option at present, and here's an in-depth
explanation: http://greetingsfromoakland.blogspot.com/2009/02/enums.html

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On
Behalf Of sunmoorthy1
Sent: Monday, December 29, 2008 1:18 PM
To: [hidden email]
Subject: [flexcoders] Java enum in Flex3

How to convert java enum values into Flex3 object.
Any one went thru this problem?
Please give your experties?

Sundar






Reply | Threaded
Open this post in threaded view
|

Re: Java enum in Flex3

Josh McDonald-5
I'm kicking off a blaze-ds project this weekend, and I'll be doing typesafe
java<->flex enums, when I figure it out I'll blog about it and post it here
:) It'll probably just require a small amount of custom unmarshalling code,
there's a lot of undocumented flexibility in mx.rpc.*

-Josh

Thu, Feb 5, 2009 at 11:37 AM, Maciek Sakrejda <[hidden email]> wrote:

>   Interesting. Any thoughts on Granite Data Services' approach? There is a
> custom externalization process for Java Enum objects, and a granite Enum
> class in ActionScript that all your (generated) Enums extend. The enum
> class takes care of reading/writing. The writeExternal() method just
> writes the name of the Enum; readExternal() tries to find the name of
> the object in the constants defined by the Enum. The RemoteAlias
> metadata is set up as for a standard Java class.
>
> Are we asking for trouble in using this method? Is there something
> inherently dangerous here?
> --
> Maciek Sakrejda
> Truviso, Inc.
> http://www.truviso.com
>
>
> -----Original Message-----
> From: Seth Hodgson <[hidden email] <shodgson%40adobe.com>>
> Reply-To: [hidden email] <flexcoders%40yahoogroups.com>
> To: [hidden email] <flexcoders%40yahoogroups.com> <
> [hidden email] <flexcoders%40yahoogroups.com>>
> Subject: RE: [flexcoders] Java enum in Flex3
> Date: Wed, 4 Feb 2009 16:20:33 -0800
>
> BlazeDS and LCDS roundtrip Java enums to the client and back as Strings.
> That's the only good option at present, and here's an in-depth
> explanation: http://greetingsfromoakland.blogspot.com/2009/02/enums.html
>
> Best,
> Seth
>
> From: [hidden email] <flexcoders%40yahoogroups.com> [mailto:
> [hidden email] <flexcoders%40yahoogroups.com>] On
> Behalf Of sunmoorthy1
> Sent: Monday, December 29, 2008 1:18 PM
> To: [hidden email] <flexcoders%40yahoogroups.com>
> Subject: [flexcoders] Java enum in Flex3
>
> How to convert java enum values into Flex3 object.
> Any one went thru this problem?
> Please give your experties?
>
> Sundar
>
>  
>



--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  [hidden email]
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/
Reply | Threaded
Open this post in threaded view
|

RE: Java enum in Flex3

Seth Hodgson
In reply to this post by Maciek Sakrejda
Hi Maciek,

I don't know anything about Granite Data Services but a quick google search returns this: http://www.graniteds.org/jira/browse/GDS-228

The reason why they're getting multiple instances of their "enum" AS classes during deserialization is layed out in the post I linked to below - without a readResolve() hook in the Player there's no way to support reading singletons out of the AMF stream.

This means that you have potentially many duplicate instances of each enum value floating around in the AVM. It looks like they've defined an equals() method as an attempt to work around this, but while that's a standard method defined on Java's base Object class there is no equals() method defined in the core ECMAScript/ActionScript libraries. If I were using client side enums in ActionScript, I'd expect simple equality checks to work correctly and they won't with this approach.

Each of these classes will also add a bit to your swf size, but that's a minor concern unless you're using tons of enums :)

I don't know what other value these classes may provide, perhaps some help with data validation, but be careful in your code anywhere you're expecting them to actually be singletons because they generally won't be.

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On Behalf Of Maciek Sakrejda
Sent: Wednesday, February 04, 2009 5:38 PM
To: [hidden email]
Subject: RE: [flexcoders] Java enum in Flex3

Interesting. Any thoughts on Granite Data Services' approach? There is a
custom externalization process for Java Enum objects, and a granite Enum
class in ActionScript that all your (generated) Enums extend. The enum
class takes care of reading/writing. The writeExternal() method just
writes the name of the Enum; readExternal() tries to find the name of
the object in the constants defined by the Enum. The RemoteAlias
metadata is set up as for a standard Java class.

Are we asking for trouble in using this method? Is there something
inherently dangerous here?
--
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

-----Original Message-----
From: Seth Hodgson <[hidden email]>
Reply-To: [hidden email]
To: [hidden email] <[hidden email]>
Subject: RE: [flexcoders] Java enum in Flex3
Date: Wed, 4 Feb 2009 16:20:33 -0800

BlazeDS and LCDS roundtrip Java enums to the client and back as Strings.
That's the only good option at present, and here's an in-depth
explanation: http://greetingsfromoakland.blogspot.com/2009/02/enums.html

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On
Behalf Of sunmoorthy1
Sent: Monday, December 29, 2008 1:18 PM
To: [hidden email]
Subject: [flexcoders] Java enum in Flex3

How to convert java enum values into Flex3 object.
Any one went thru this problem?
Please give your experties?

Sundar

Reply | Threaded
Open this post in threaded view
|

RE: Java enum in Flex3

Maciek Sakrejda
Thanks, Seth. I'd read the article, but your e-mail clarifies the
issues. I've looked over our usage and I think we're safe for now, but
this is sort of a time bomb, and it might make sense to fall back to
just Strings. The only alternative I see is ensuring to use .equals()
everywhere, which is tricky, especially when dealing with collections
and other data structures (since they'll already be using the standard
'==' equality checks).
--
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

-----Original Message-----
From: Seth Hodgson <[hidden email]>
Reply-To: [hidden email]
To: [hidden email] <[hidden email]>
Subject: RE: [flexcoders] Java enum in Flex3
Date: Wed, 4 Feb 2009 21:14:29 -0800

Hi Maciek,

I don't know anything about Granite Data Services but a quick google
search returns this: http://www.graniteds.org/jira/browse/GDS-228

The reason why they're getting multiple instances of their "enum" AS
classes during deserialization is layed out in the post I linked to
below - without a readResolve() hook in the Player there's no way to
support reading singletons out of the AMF stream.

This means that you have potentially many duplicate instances of each
enum value floating around in the AVM. It looks like they've defined an
equals() method as an attempt to work around this, but while that's a
standard method defined on Java's base Object class there is no equals()
method defined in the core ECMAScript/ActionScript libraries. If I were
using client side enums in ActionScript, I'd expect simple equality
checks to work correctly and they won't with this approach.

Each of these classes will also add a bit to your swf size, but that's a
minor concern unless you're using tons of enums :)

I don't know what other value these classes may provide, perhaps some
help with data validation, but be careful in your code anywhere you're
expecting them to actually be singletons because they generally won't
be.

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On
Behalf Of Maciek Sakrejda
Sent: Wednesday, February 04, 2009 5:38 PM
To: [hidden email]
Subject: RE: [flexcoders] Java enum in Flex3

Interesting. Any thoughts on Granite Data Services' approach? There is a
custom externalization process for Java Enum objects, and a granite Enum
class in ActionScript that all your (generated) Enums extend. The enum
class takes care of reading/writing. The writeExternal() method just
writes the name of the Enum; readExternal() tries to find the name of
the object in the constants defined by the Enum. The RemoteAlias
metadata is set up as for a standard Java class.

Are we asking for trouble in using this method? Is there something
inherently dangerous here?
--
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

-----Original Message-----
From: Seth Hodgson <[hidden email]>
Reply-To: [hidden email]
To: [hidden email] <[hidden email]>
Subject: RE: [flexcoders] Java enum in Flex3
Date: Wed, 4 Feb 2009 16:20:33 -0800

BlazeDS and LCDS roundtrip Java enums to the client and back as Strings.
That's the only good option at present, and here's an in-depth
explanation: http://greetingsfromoakland.blogspot.com/2009/02/enums.html

Best,
Seth

From: [hidden email] [mailto:[hidden email]] On
Behalf Of sunmoorthy1
Sent: Monday, December 29, 2008 1:18 PM
To: [hidden email]
Subject: [flexcoders] Java enum in Flex3

How to convert java enum values into Flex3 object.
Any one went thru this problem?
Please give your experties?

Sundar