Revision: 8402
Author: [email protected]
Date: Wed Jul 21 07:51:31 2010
Log: Support composition as well as extension.

This makes it much easier to do framework-y things
like AOP interceptors, Java Proxies, wrappers, etc.

Review at http://gwt-code-reviews.appspot.com/653801

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8402

Modified:
 /trunk/user/src/com/google/gwt/rpc/server/RpcServlet.java
 /trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java

=======================================
--- /trunk/user/src/com/google/gwt/rpc/server/RpcServlet.java Mon Jan 25 08:22:37 2010 +++ /trunk/user/src/com/google/gwt/rpc/server/RpcServlet.java Wed Jul 21 07:51:31 2010
@@ -56,9 +56,26 @@
private final Map<String, SoftReference<ClientOracle>> clientOracleCache = new HashMap<String, SoftReference<ClientOracle>>();

   /**
-   * The default constructor.
+   * The implementation of the service.
+   */
+  private final Object delegate;
+
+  /**
+   * The default constructor used by service implementations that
+   * extend this class.  The servlet will delegate AJAX requests to
+   * the appropriate method in the subclass.
    */
   public RpcServlet() {
+    this.delegate = this;
+  }
+
+  /**
+   * The wrapping constructor used by service implementations that are
+   * separate from this class.  The servlet will delegate AJAX
+   * requests to the appropriate method in the given object.
+   */
+  public RpcServlet(Object delegate) {
+    this.delegate = delegate;
   }

   /**
@@ -138,10 +155,10 @@
     assert stream != null : "stream";

     try {
-      RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(),
+ RPCRequest rpcRequest = RPC.decodeRequest(payload, delegate.getClass(),
           clientOracle);
       onAfterRequestDeserialized(rpcRequest);
-      RPC.invokeAndStreamResponse(this, rpcRequest.getMethod(),
+      RPC.invokeAndStreamResponse(delegate, rpcRequest.getMethod(),
           rpcRequest.getParameters(), clientOracle, stream);
     } catch (RemoteException ex) {
throw new SerializationException("An exception was sent from the client",
=======================================
--- /trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java Thu Mar 11 08:37:52 2010 +++ /trunk/user/src/com/google/gwt/user/server/rpc/RemoteServiceServlet.java Wed Jul 21 07:51:31 2010
@@ -122,9 +122,26 @@
private final Map<String, SerializationPolicy> serializationPolicyCache = new HashMap<String, SerializationPolicy>();

   /**
-   * The default constructor.
+   * The implementation of the service.
+   */
+  private final Object delegate;
+
+  /**
+   * The default constructor used by service implementations that
+   * extend this class.  The servlet will delegate AJAX requests to
+   * the appropriate method in the subclass.
    */
   public RemoteServiceServlet() {
+    this.delegate = this;
+  }
+
+  /**
+   * The wrapping constructor used by service implementations that are
+   * separate from this class.  The servlet will delegate AJAX
+   * requests to the appropriate method in the given object.
+   */
+  public RemoteServiceServlet(Object delegate) {
+    this.delegate = delegate;
   }

public final SerializationPolicy getSerializationPolicy(String moduleBaseURL,
@@ -185,9 +202,9 @@
     checkPermutationStrongName();

     try {
- RPCRequest rpcRequest = RPC.decodeRequest(payload, this.getClass(), this); + RPCRequest rpcRequest = RPC.decodeRequest(payload, delegate.getClass(), this);
       onAfterRequestDeserialized(rpcRequest);
-      return RPC.invokeAndEncodeResponse(this, rpcRequest.getMethod(),
+      return RPC.invokeAndEncodeResponse(delegate, rpcRequest.getMethod(),
           rpcRequest.getParameters(), rpcRequest.getSerializationPolicy(),
           rpcRequest.getFlags());
     } catch (IncompatibleRemoteServiceException ex) {

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to