Jason: I'll admit I was unable to figure out exactly what Shindig's
approach is, exactly, unfortunately. However there is definitely more
than one way to skin this cat. My current implementation an Action, a
Result and a Handler for each operation. This does result in some
class proliferation, but has the upside of having everything nicely
self-contained.

In my implementation, I actually have a 'Dispatch' class which can be
injected directly, and a separate DispatchServiceServlet which is also
injected the same Dispatch instance and provides access from GWT/RPC.

To hold you over while I get the code sorted, here is a simple example
of what an action/result/handler looks like:

It's just a concrete implementation of ActionHandler. Essentially,
each Action/Result has a single ActionHandler that does the actual
execution on the server side.

getActionType() returns the concrete Action subclass that the handler
supports. For example, a 'Get User' operation might look like this:

public class GetUser implements Action<GetUserResult> {
        private String name;

       // For serialization
        GetUser() {}

        public GetUser( String name ) {
                this.name = name;
        }

        public String getName() {
                return name;
        }
}

public class GetUserResult implements Result {
        private User user;

        // Serialization
        GetUserResult() {}

        public GetUserResult( User user ) {
                this.user = user;
        }

        public User getUser() {
                return user;
        }
}

// This class is server-side only
public GetUserHandler implements ActionHandler<GetUser, GetUserResult>
{
        private final UserDAO dao;

        @Inject
        public GetUserHandler( UserDAO dao ) {
                this.dao = dao;
        }

        public Class<GetUser> getActionType() {
                return GetUser.class;
        }

        public GetUserResult execute( GetUser action ) throws Exception {
                return new GetUserResult( dao.getUser( action.getName() ) );
        }
}

A very simple example, and the actual 'getting' code is wrapped in the
DAO in this case. It could equally be coded directly in, or hooking up
to a non-DB service. Depends how you want to implement it.

David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to