commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Galbraith-TM" <>
Subject [lang] improving usefullness of enums for remoting
Date Fri, 15 Jul 2005 19:42:24 GMT
I have an enum class that defines several error codes, and is passed between server and client

I want to be able to update the enum class to define new error objects on the server, without
having to redeploy the new enum class to all the clients, which likely won't directly reference
the new error code enum objects directly.

>From looking at the code, the readResolve() method in the current enum implementation
doesn't support this...

I think this code, in the enum class, would allow me to optionally override the remoteExtension()
method to do what I want...any thoughts?

     * <p>Handle the deserialization of the class to ensure that multiple
     * copies are not wastefully created, or illegal enum types created.</p>
     * @return the resolved object
    protected Object readResolve() {
        Entry entry = (Entry) cEnumClasses.get(getEnumClass());
        if (entry == null) {
            return remoteExtension(this);
        Enum resolved = (Enum);
        return resolved != null ?  resolved : remoteExtension(this);

     * <p>If you want to allow new enum values to be created
     * when deserializing enum objects, override this method with
     * the appropriate code to add the new enum to the collection.</p>
     * <pre>
     * // sample for deserialization of most simple enums
     * protected Enum remoteExtension(Enum newEnum) {
     *     return new Enum(newEnum.getName());
     * }
     * </pre>
     * @return the newly resolved object
    protected Enum remoteExtension(Enum newEnum) {
        return null;

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

View raw message