---------- Forwarded message ----------
From: <[email protected]>
Date: Sun, Apr 10, 2011 at 00:13
Subject: Trying to address issue 6234 (Support RequestFactory service
inheritance on the client) (issue1411802)
To: [email protected]
Cc: [email protected],
[email protected]


Reviewers: ,

Description:
This is a crude attempt to get methold resolving to work in cases where
the RequestContext inherits from a generic super interface and does not
contain the request method itself.

I was not able to get a local environment setup in a reasonable amount
of time or to run the tests without running out of PermGen memory space.
I hope someone else can use this patch and take this on.

With this change we will look up the RequestContext class twice from the
classloader. From my basic understanding of this code this is not going
to matter, since all these calls get cached and therefore there is a
limited number of calls. In order to make it better, though, the
SimpleRequestProcessor could first try to resolve the class (line 425)
and then call the resolveRequestContextMethod with the Class instead of
its name. For that, you would need to change the signature of
resolveRequestContextMethod to take a Class instead of a string for the
RequestContextClass. That was too much refactoring for me without being
able run tests. If I had a working local environment, that would have
been the solution I had tried.

I tried to create a test for this. I have no idea if it works or not.
:-(


Please review this at http://gwt-code-reviews.appspot.com/1411802/

Affected files:
 user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
 user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
 user/src/com/google/gwt/requestfactory/server/ServiceLayerCache.java
 user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
 user/src/com/google/gwt/requestfactory/server/SimpleRequestProcessor.java
 user/test/com/google/gwt/requestfactory/shared/ServiceInheritanceTest.java


Index:
user/test/com/google/gwt/requestfactory/shared/ServiceInheritanceTest.java
===================================================================
---
user/test/com/google/gwt/requestfactory/shared/ServiceInheritanceTest.java
 (revision 9969)
+++
user/test/com/google/gwt/requestfactory/shared/ServiceInheritanceTest.java
 (working copy)
@@ -65,24 +65,34 @@
    Request<Integer> add(int n);
    Request<Integer> subtract(int n);
  }
+  /**
+   * Base implementation of {@link SumServiceBase}
+   */
+  static abstract class GenericBaseImpl<T extends Number> {
+    protected T initialValue;

+    public int add(int n) {
+      return initialValue.intValue() + n;
+    }
+
+    public int subtract(int n) {
+      return initialValue.intValue() - n;
+    }
+
+    public int mulitply(int n) {
+      return initialValue.intValue() * n;
+    }
+  }
+
  /**
   * Base implementation of {@link SumServiceBase}
   */
-  static class BaseImpl {
+  static class BaseImpl extends GenericBaseImpl<Integer> {
    protected int initialValue;

    public BaseImpl() {
      initialValue = 5;
    }
-
-    public Integer add(int n) {
-      return initialValue + n;
-    }
-
-    public Integer subtract(int n) {
-      return initialValue - n;
-    }
  }

  /**
@@ -97,11 +107,6 @@
       */
      initialValue = 8;
    }
-
-    @Override
-    public Integer subtract(int n) {
-      return 0;
-    }
  }

  private static final int TEST_DELAY = 5000;
@@ -149,7 +154,7 @@
    factory.subContext().subtract(3).fire(new Receiver<Integer>() {
      @Override
      public void onSuccess(Integer response) {
-        assertEquals((Integer) 0, response);
+        assertEquals((Integer) 5, response);
        finishTest();
      }
    });
Index:
user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
===================================================================
--- user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
   (revision 9969)
+++ user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
   (working copy)
@@ -142,8 +142,8 @@
  }

  @Override
-  public Method resolveDomainMethod(Method requestContextMethod) {
-    return getNext().resolveDomainMethod(requestContextMethod);
+  public Method resolveDomainMethod(String requestContextClass, Method
requestContextMethod) {
+    return getNext().resolveDomainMethod(requestContextClass,
requestContextMethod);
  }

  @Override
Index:
user/src/com/google/gwt/requestfactory/server/SimpleRequestProcessor.java
===================================================================
---
user/src/com/google/gwt/requestfactory/server/SimpleRequestProcessor.java
(revision 9969)
+++
user/src/com/google/gwt/requestfactory/server/SimpleRequestProcessor.java
(working copy)
@@ -428,7 +428,7 @@
          throw new UnexpectedException("Cannot resolve operation "
              + invocation.getOperation(), null);
        }
-        Method domainMethod = service.resolveDomainMethod(contextMethod);
+        Method domainMethod =
service.resolveDomainMethod(operation[0],contextMethod);
        if (domainMethod == null) {
          throw new UnexpectedException("Cannot resolve domain method "
              + invocation.getOperation(), null);
Index:
user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
===================================================================
--- user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
    (revision 9969)
+++ user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
    (working copy)
@@ -116,8 +116,8 @@
  }

  @Override
-  public Method resolveDomainMethod(Method requestContextMethod) {
-    Class<?> declaringClass = requestContextMethod.getDeclaringClass();
+  public Method resolveDomainMethod(String requestContextClass, Method
requestContextMethod) {
+    Class<?> declaringClass = forName(requestContextClass);
    Class<?> searchIn =

getTop().resolveServiceClass(declaringClass.asSubclass(RequestContext.class));
    Class<?>[] parameterTypes = requestContextMethod.getParameterTypes();
Index: user/src/com/google/gwt/requestfactory/server/ServiceLayerCache.java
===================================================================
--- user/src/com/google/gwt/requestfactory/server/ServiceLayerCache.java
   (revision 9969)
+++ user/src/com/google/gwt/requestfactory/server/ServiceLayerCache.java
   (working copy)
@@ -166,8 +166,9 @@
  }

  @Override
-  public Method resolveDomainMethod(Method requestContextMethod) {
-    return getOrCache(resolveDomainMethod, requestContextMethod,
Method.class, requestContextMethod);
+  public Method resolveDomainMethod(String requestContextClass, Method
requestContextMethod) {
+    return getOrCache(resolveDomainMethod, new Pair<String,
Method>(requestContextClass,
+        requestContextMethod), Method.class, requestContextClass,
requestContextMethod);
  }

  @Override
Index: user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
===================================================================
--- user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
(revision 9969)
+++ user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
(working copy)
@@ -306,10 +306,12 @@
   * declaration. The {@code requestContextMethod} will have been previously
   * resolved by {@link #resolveRequestContextMethod(String, String)}.
   *
+   * @param requestContextClass the fully-qualified binary name of the
+   *          RequestContext
   * @param requestContextMethod a RequestContext method declaration.
   * @return the domain service method that should be invoked
   */
-  public abstract Method resolveDomainMethod(Method requestContextMethod);
+  public abstract Method resolveDomainMethod(String requestContextClass,
Method requestContextMethod);

  /**
   * Return the type of {@link Locator} that should be used to access the
given

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

Reply via email to