Revision: 9436
Author: [email protected]
Date: Wed Dec 15 12:13:06 2010
Log: Make InstanceRequest usable with value objects by changing the
parameterization to BaseProxy.
Add test for above.
Fix bug in RequestFactoryInterfaceValidator where validateProxy() wouldn't actually validate.
Issue 5678.
Patch by: bobv
Review by: rjrjr

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

http://code.google.com/p/google-web-toolkit/source/detail?r=9436

Added:
/trunk/user/test/com/google/gwt/requestfactory/shared/SimpleValueContext.java
Modified:
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryEditorDriverGenerator.java /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java
 /trunk/user/src/com/google/gwt/requestfactory/shared/InstanceRequest.java
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequest.java /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java

=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleValueContext.java Wed Dec 15 12:13:06 2010
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.requestfactory.shared;
+
+import com.google.gwt.requestfactory.server.SimpleValue;
+
+/**
+ * Tests instance method invocations on value objects.
+ */
+...@service(SimpleValue.class)
+public interface SimpleValueContext extends RequestContext {
+  InstanceRequest<SimpleValueProxy, String> getString();
+}
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java Sun Oct 3 19:15:33 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java Wed Dec 15 12:13:06 2010
@@ -20,6 +20,7 @@
 import com.google.gwt.editor.client.impl.DelegateMap;
 import com.google.gwt.event.shared.EventBus;
 import com.google.gwt.event.shared.HandlerRegistration;
+import com.google.gwt.requestfactory.shared.BaseProxy;
 import com.google.gwt.requestfactory.shared.EntityProxy;
 import com.google.gwt.requestfactory.shared.EntityProxyChange;
 import com.google.gwt.requestfactory.shared.EntityProxyId;
@@ -117,9 +118,9 @@
       // Read-only mode
       return object;
     }
-    if (object instanceof EntityProxy) {
+    if (object instanceof BaseProxy) {
       @SuppressWarnings("unchecked")
-      T toReturn = (T) request.edit((EntityProxy) object);
+      T toReturn = (T) request.edit((BaseProxy) object);
       return toReturn;
     }
     return object;
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryEditorDriverGenerator.java Thu Dec 9 12:12:52 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryEditorDriverGenerator.java Wed Dec 15 12:13:06 2010
@@ -25,7 +25,7 @@
 import com.google.gwt.requestfactory.client.RequestFactoryEditorDriver;
import com.google.gwt.requestfactory.client.impl.AbstractRequestFactoryEditorDriver; import com.google.gwt.requestfactory.client.impl.RequestFactoryEditorDelegate;
-import com.google.gwt.requestfactory.shared.EntityProxy;
+import com.google.gwt.requestfactory.shared.BaseProxy;
 import com.google.gwt.user.rebind.SourceWriter;

 import java.util.List;
@@ -37,13 +37,13 @@
 public class RequestFactoryEditorDriverGenerator extends
     AbstractEditorDriverGenerator {

-  private JClassType entityProxyType;
+  private JClassType baseProxyType;

   @Override
   public String generate(TreeLogger logger, GeneratorContext context,
       String typeName) throws UnableToCompleteException {
-    entityProxyType = context.getTypeOracle().findType(
-        EntityProxy.class.getCanonicalName());
+    baseProxyType = context.getTypeOracle().findType(
+        BaseProxy.class.getCanonicalName());
     return super.generate(logger, context, typeName);
   }

@@ -65,7 +65,7 @@
   @Override
   protected String mutableObjectExpression(EditorData data,
       String sourceObjectExpression) {
-    if (entityProxyType.isAssignableFrom(data.getPropertyOwnerType())) {
+    if (baseProxyType.isAssignableFrom(data.getPropertyOwnerType())) {
       return String.format("((%s) request.edit((%s)))",
           data.getPropertyOwnerType().getQualifiedSourceName(),
           sourceObjectExpression);
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java Tue Dec 14 07:17:57 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java Wed Dec 15 12:13:06 2010
@@ -738,10 +738,10 @@
    *          EntityProxy or ValueProxy subtype
    */
   public void validateProxy(String binaryName) {
-    if (fastFail(binaryName)) {
-      return;
-    }
-
+    /*
+     * Don't call fastFail() here or the proxy may not be validated, since
+     * validateXProxy delegates to validateProxy() which would re-check.
+     */
Type proxyType = Type.getObjectType(BinaryName.toInternalName(binaryName));
     if (isAssignable(parentLogger, entityProxyIntf, proxyType)) {
       validateEntityProxy(binaryName);
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/InstanceRequest.java Thu Oct 14 18:28:29 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/InstanceRequest.java Wed Dec 15 12:13:06 2010
@@ -20,15 +20,15 @@
  * &mdash; rather it vends one. There is no way to get an instance method's
* {...@link Request#fire} without assigning an instance by calling {...@link #using}.
  *
- * @param <P> the instance type of EntityProxy
+ * @param <P> the instance type of BaseProxy
  * @param <T> the type eventually returned by the method invocation
  */
-public interface InstanceRequest<P extends EntityProxy, T> {
+public interface InstanceRequest<P extends BaseProxy, T> {

   /**
    * Provide the instance on which the request will be invoked.
-   *
-   * @param instanceObject an {...@link EntityProxy} instance of type P
+   *
+   * @param instanceObject an {...@link BaseProxy} instance of type P
    * @return an instance of {...@link Request}&lt;T&gt;
    */
   Request<T> using(P instanceObject);
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequest.java Mon Nov 22 08:01:19 2010 +++ /trunk/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequest.java Wed Dec 15 12:13:06 2010
@@ -16,7 +16,7 @@
 package com.google.gwt.requestfactory.shared.impl;

 import com.google.gwt.autobean.shared.Splittable;
-import com.google.gwt.requestfactory.shared.EntityProxy;
+import com.google.gwt.requestfactory.shared.BaseProxy;
 import com.google.gwt.requestfactory.shared.InstanceRequest;
 import com.google.gwt.requestfactory.shared.Receiver;
 import com.google.gwt.requestfactory.shared.Request;
@@ -36,7 +36,7 @@
  * @param <T> return type
  */
 public abstract class AbstractRequest<T> implements Request<T>,
-    InstanceRequest<EntityProxy, T> {
+    InstanceRequest<BaseProxy, T> {

   /**
    * Used by generated subtypes.
@@ -82,7 +82,7 @@
    * This method comes from the {...@link InstanceRequest} interface. Instance
    * methods place the instance in the first parameter slot.
    */
-  public Request<T> using(EntityProxy instanceObject) {
+  public Request<T> using(BaseProxy instanceObject) {
     getRequestData().getParameters()[0] = instanceObject;
     /*
* Instance methods enqueue themselves when their using() method is called.
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Wed Dec 8 12:37:05 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java Wed Dec 15 12:13:06 2010
@@ -27,6 +27,7 @@
 import com.google.gwt.requestfactory.shared.SimpleEnum;
 import com.google.gwt.requestfactory.shared.SimpleFooProxy;
 import com.google.gwt.requestfactory.shared.SimpleFooRequest;
+import com.google.gwt.requestfactory.shared.SimpleValueContext;
 import com.google.gwt.requestfactory.shared.SimpleValueProxy;
 import com.google.gwt.requestfactory.shared.Violation;
 import com.google.gwt.requestfactory.shared.impl.SimpleEntityProxyId;
@@ -2309,6 +2310,20 @@
           }
         });
   }
+
+  public void testValueMethodInvocation() {
+    delayTestFinish(DELAY_TEST_FINISH);
+    SimpleValueContext ctx = req.simpleValueContext();
+    SimpleValueProxy p = ctx.create(SimpleValueProxy.class);
+    p.setString("Hello World!");
+    ctx.getString().using(p).fire(new Receiver<String>() {
+      @Override
+      public void onSuccess(String response) {
+        assertEquals("Hello World!", response);
+        finishTestAndReset();
+      }
+    });
+  }

   public void testValueObjectCreateSetRetrieveUpdate() {
     delayTestFinish(DELAY_TEST_FINISH);
=======================================
--- /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java Tue Dec 7 22:33:06 2010 +++ /trunk/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java Wed Dec 15 12:13:06 2010
@@ -20,7 +20,7 @@
  * UserInformation and Logging services.
  */
 public interface SimpleRequestFactory extends BasicRequestFactory {
-
+
   InstanceServiceRequest instanceServiceRequest();

   InstanceServiceRequestByName instanceServiceRequestByName();
@@ -29,5 +29,7 @@

   SimpleFooRequest simpleFooRequest();

+  SimpleValueContext simpleValueContext();
+
   UnicodeTestRequest unicodeTestRequest();
 }

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

Reply via email to