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 git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9436 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java b/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java index 773851e..26fc76c 100644 --- a/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java +++ b/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryEditorDelegate.java
@@ -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;
diff --git a/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryEditorDriverGenerator.java b/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryEditorDriverGenerator.java index 84e5f78..1d309b7 100644 --- a/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryEditorDriverGenerator.java +++ b/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryEditorDriverGenerator.java
@@ -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);
diff --git a/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java b/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java index fb10d5e..f558697 100644 --- a/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java +++ b/user/src/com/google/gwt/requestfactory/server/RequestFactoryInterfaceValidator.java
@@ -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);
diff --git a/user/src/com/google/gwt/requestfactory/shared/InstanceRequest.java b/user/src/com/google/gwt/requestfactory/shared/InstanceRequest.java index b52a001..27e5055 100644 --- a/user/src/com/google/gwt/requestfactory/shared/InstanceRequest.java +++ b/user/src/com/google/gwt/requestfactory/shared/InstanceRequest.java
@@ -20,15 +20,15 @@ * — 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}<T> */ Request<T> using(P instanceObject);
diff --git a/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequest.java b/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequest.java index aceb3a1..2a20f06 100644 --- a/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequest.java +++ b/user/src/com/google/gwt/requestfactory/shared/impl/AbstractRequest.java
@@ -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.
diff --git a/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java b/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java index 1763de6..b116e1c 100644 --- a/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java +++ b/user/test/com/google/gwt/requestfactory/client/RequestFactoryTest.java
@@ -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; @@ -2310,6 +2311,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); SimpleFooRequest req = simpleFooRequest();
diff --git a/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java b/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java index acd0863..8298f8d 100644 --- a/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java +++ b/user/test/com/google/gwt/requestfactory/shared/SimpleRequestFactory.java
@@ -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(); }
diff --git a/user/test/com/google/gwt/requestfactory/shared/SimpleValueContext.java b/user/test/com/google/gwt/requestfactory/shared/SimpleValueContext.java new file mode 100644 index 0000000..9b269b3 --- /dev/null +++ b/user/test/com/google/gwt/requestfactory/shared/SimpleValueContext.java
@@ -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(); +}