Revision: 8492
Author: [email protected]
Date: Thu Aug 5 21:58:49 2010
Log: Another step towards making instance methods real. The interface on
the client is pretty much what it needs to be.
EmployeeRequest has a method like
RequestObject<Void> remove(EmployeeRecord record);
However, there is a hack in place to get it to work on the server. (The
hack was already there, this patch just moves it around.)
Patch by: amitmanjhi
Review by: rjrjr (desk review)
Review at http://gwt-code-reviews.appspot.com/710803
http://code.google.com/p/google-web-toolkit/source/detail?r=8492
Added:
/trunk/user/src/com/google/gwt/requestfactory/shared/RequestData.java
Deleted:
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/JsonRequestDataUtil.java
Modified:
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileReportEntry.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/request/EmployeeRequest.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/request/ReportRequest.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeDetailsActivity.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditActivity.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportDetailsActivity.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditActivity.java
/trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
/trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
/trunk/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
/trunk/user/src/com/google/gwt/requestfactory/shared/RequestObject.java
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestDataManager.java
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/requestfactory/shared/RequestData.java
Thu Aug 5 21:58:49 2010
@@ -0,0 +1,69 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p>
+ * <span style="color:red">Experimental API: This class is still under
rapid
+ * development, and is very likely to be deleted. Use it at your own risk.
+ * </span>
+ * </p>
+ * A class that encapsulates the parameters and method name to be invoked
on the
+ * server.
+ *
+ * TODO: add appropriate unit tests.
+ */
+public class RequestData {
+
+ public static final String CONTENT_TOKEN = "contentData";
+ public static final String OPERATION_TOKEN = "operation";
+ public static final String PARAM_TOKEN = "param";
+
+ // TODO: non-final is a hack for now.
+ private String operation;
+ private final Object[] parameters;
+
+ public RequestData(String operation, Object[] parameters) {
+ this.operation = operation;
+ this.parameters = parameters;
+ }
+
+ /**
+ * Returns the string that encodes the request data.
+ *
+ */
+ public Map<String, String> getRequestMap(String contentData) {
+ Map<String, String> requestMap = new HashMap<String, String>();
+ // nasty hack, remove.
+ if (operation.endsWith("persist") || operation.endsWith("remove")) {
+ operation = RequestFactory.SYNC;
+ }
+ requestMap.put(OPERATION_TOKEN, operation);
+ if (parameters != null) {
+ for (int i = 0; i < parameters.length; i++) {
+ Object value = parameters[i];
+ requestMap.put(PARAM_TOKEN + i, value.toString());
+ }
+ }
+ if (contentData != null) {
+ requestMap.put(CONTENT_TOKEN, contentData);
+ }
+ return requestMap;
+ }
+}
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/JsonRequestDataUtil.java
Fri Jul 30 17:29:09 2010
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.impl;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * <p>
- * <span style="color:red">Experimental API: This class is still under
rapid
- * development, and is very likely to be deleted. Use it at your own risk.
- * </span>
- * </p>
- * An utility class to manage the encoding and decoding of parameters and
- * methodNames.
- *
- * TODO: add appropriate unit tests.
- */
-public class JsonRequestDataUtil {
-
- public static final String CONTENT_TOKEN = "contentData";
- public static final String OPERATION_TOKEN = "operation";
- public static final String PARAM_TOKEN = "param";
-
- /**
- * Returns the string that encodes the request data.
- *
- */
- public static Map<String, String> getRequestMap(String operation,
- Object values[], String content) {
- Map<String, String> requestMap = new HashMap<String, String>();
- requestMap.put(OPERATION_TOKEN, operation);
- if (values != null) {
- for (int i = 0; i < values.length; i++) {
- Object value = values[i];
- requestMap.put(PARAM_TOKEN + i, value.toString());
- }
- }
- if (content != null) {
- requestMap.put(CONTENT_TOKEN, content);
- }
- return requestMap;
- }
-
-
-}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.java
Fri Jul 30 11:32:15 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/ExpenseDetails.java
Thu Aug 5 15:15:34 2010
@@ -951,7 +951,7 @@
setNotesEditState(false, true, pendingNotes);
// Submit the delta.
- RequestObject<Void> editRequest =
expensesRequestFactory.reportRequest().persist();
+ RequestObject<Void> editRequest =
expensesRequestFactory.reportRequest().persist(report);
DeltaValueStore deltas = editRequest.getDeltaValueStore();
deltas.set(ReportRecord.notes, report, pendingNotes);
editRequest.fire(new Receiver<Void>() {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileReportEntry.java
Thu Aug 5 10:04:19 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/client/MobileReportEntry.java
Thu Aug 5 15:15:34 2010
@@ -85,7 +85,7 @@
public void create(Long reporterId) {
report = (ReportRecord) requestFactory.create(ReportRecord.class);
- requestObject = requestFactory.reportRequest().persist();
+ requestObject = requestFactory.reportRequest().persist(report);
DeltaValueStore deltas = requestObject.getDeltaValueStore();
deltas.set(ReportRecord.reporterKey, report, reporterId.toString());
displayReport();
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/request/EmployeeRequest.java
Fri Jul 30 17:29:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/request/EmployeeRequest.java
Thu Aug 5 15:15:34 2010
@@ -66,17 +66,15 @@
RecordListRequest<EmployeeRecord> findEmployeeEntriesByDepartment(
String department, int firstResult, int maxResults);
- // TODO: a hack for now...
/**
* @return a request object
*/
@Instance
- RequestObject<Void> persist();
-
- // TODO: a hack for now.
+ RequestObject<Void> persist(EmployeeRecord record);
+
/**
* @return a request object
*/
@Instance
- RequestObject<Void> remove();
-}
+ RequestObject<Void> remove(EmployeeRecord record);
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/request/ReportRequest.java
Fri Jul 30 17:29:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/request/ReportRequest.java
Thu Aug 5 15:15:34 2010
@@ -73,16 +73,15 @@
RecordListRequest<ReportRecord> findReportsByEmployee(
PropertyReference<String> id);
- // TODO: persist() and remove() methods are hacks for now.
/**
* @return a request object
*/
@Instance
- RequestObject<Void> persist();
+ RequestObject<Void> persist(ReportRecord record);
/**
* @return a request object
*/
@Instance
- RequestObject<Void> remove();
-}
+ RequestObject<Void> remove(ReportRecord record);
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeDetailsActivity.java
Fri Jul 30 17:29:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeDetailsActivity.java
Thu Aug 5 15:15:34 2010
@@ -79,7 +79,7 @@
return;
}
- RequestObject<Void> deleteRequest =
requests.employeeRequest().remove();
+ RequestObject<Void> deleteRequest =
requests.employeeRequest().remove(view.getValue());
DeltaValueStore deltas = deleteRequest.getDeltaValueStore();
deltas.delete(view.getValue());
deleteRequest.fire(new Receiver<Void>() {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditActivity.java
Thu Aug 5 10:04:19 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/employee/EmployeeEditActivity.java
Thu Aug 5 15:15:34 2010
@@ -58,7 +58,7 @@
public EmployeeEditActivity(Long id, RecordEditView<EmployeeRecord> view,
ExpensesRequestFactory requests,
PlaceController<ScaffoldPlace> placeController) {
- super(view, id, requests, requests.employeeRequest().persist());
+ super(view, id, requests);
this.requests = requests;
this.placeController = placeController;
}
@@ -78,4 +78,8 @@
protected Class getRecordClass() {
return EmployeeRecord.class;
}
-}
+
+ protected void setRequestObject(EmployeeRecord record) {
+ requestObject = requests.employeeRequest().persist(record);
+ }
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportDetailsActivity.java
Fri Jul 30 17:29:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportDetailsActivity.java
Thu Aug 5 15:15:34 2010
@@ -79,7 +79,7 @@
return;
}
- RequestObject<Void> deleteRequest = requests.reportRequest().remove();
+ RequestObject<Void> deleteRequest =
requests.reportRequest().remove(view.getValue());
// TODO: fix this.
DeltaValueStore deltas = deleteRequest.getDeltaValueStore();
deltas.delete(view.getValue());
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditActivity.java
Thu Aug 5 10:04:19 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gwt/ui/report/ReportEditActivity.java
Thu Aug 5 15:15:34 2010
@@ -58,7 +58,7 @@
public ReportEditActivity(Long id, RecordEditView<ReportRecord> view,
ExpensesRequestFactory requests,
PlaceController<ScaffoldPlace> placeController) {
- super(view, id, requests, requests.reportRequest().persist());
+ super(view, id, requests);
this.requests = requests;
this.placeController = placeController;
}
@@ -77,4 +77,8 @@
protected Class getRecordClass() {
return ReportRecord.class;
}
-}
+
+ protected void setRequestObject(ReportRecord record) {
+ requestObject = requests.reportRequest().persist(record);
+ }
+}
=======================================
---
/trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java
Thu Aug 5 10:04:19 2010
+++
/trunk/user/src/com/google/gwt/app/place/AbstractRecordEditActivity.java
Thu Aug 5 15:15:34 2010
@@ -39,6 +39,8 @@
public abstract class AbstractRecordEditActivity<R extends Record>
implements
Activity, RecordEditView.Delegate {
+ protected RequestObject<Void> requestObject;
+
private final boolean creating;
private final RecordEditView<R> view;
@@ -47,23 +49,22 @@
private final RequestFactory requests;
private Display display;
- private RequestObject<Void> requestObject;
public AbstractRecordEditActivity(RecordEditView<R> view, Long id,
- RequestFactory requests, RequestObject<Void> requestObject) {
-
+ RequestFactory requests) {
this.view = view;
this.creating = 0L == id;
this.id = id;
this.requests = requests;
- this.requestObject = requestObject;
}
public void cancelClicked() {
String unsavedChangesWarning = mayStop();
if ((unsavedChangesWarning == null)
|| Window.confirm(unsavedChangesWarning)) {
- requestObject.reset(); // silence the next mayStop() call when place
+ if (requestObject != null) {
+ requestObject.reset(); // silence the next mayStop() call when
place
+ }
// changes
if (creating) {
display.showActivityWidget(null);
@@ -90,6 +91,7 @@
}
public void saveClicked() {
+ assert requestObject != null;
DeltaValueStore theDeltas = requestObject.getDeltaValueStore();
if (!theDeltas.isChanged()) {
return;
@@ -140,7 +142,6 @@
this.display = display;
view.setDelegate(this);
- view.setDeltaValueStore(requestObject.getDeltaValueStore());
view.setCreating(creating);
if (creating) {
@@ -178,10 +179,14 @@
*/
protected abstract Class<? extends Record> getRecordClass();
+ protected abstract void setRequestObject(R record);
+
private void doStart(final Display display, R record) {
+ setRequestObject(record);
view.setEnabled(true);
view.setValue(record);
view.showErrors(null);
display.showActivityWidget(view);
+ view.setDeltaValueStore(requestObject.getDeltaValueStore());
}
}
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
Thu Aug 5 10:04:19 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
Thu Aug 5 15:15:34 2010
@@ -27,7 +27,6 @@
import com.google.gwt.requestfactory.shared.RequestFactory;
import com.google.gwt.requestfactory.shared.RequestObject;
import com.google.gwt.requestfactory.shared.RequestEvent.State;
-import com.google.gwt.requestfactory.shared.impl.JsonRequestDataUtil;
import com.google.gwt.user.client.Window.Location;
import com.google.gwt.valuestore.shared.Record;
import com.google.gwt.valuestore.shared.impl.RecordJsoImpl;
@@ -107,16 +106,9 @@
GWT.getHostPageBaseURL() + RequestFactory.URL);
builder.setHeader(
"Content-Type", RequestFactory.JSON_CONTENT_TYPE_UTF8);
- // TODO: do something better here...
- if (requestObject.getDeltaValueStore().isChanged()) {
-
builder.setRequestData(ClientRequestHelper.getRequestString(JsonRequestDataUtil.getRequestMap(
- RequestFactory.SYNC,
- null,
- ((DeltaValueStoreJsonImpl)
requestObject.getDeltaValueStore()).toJson())));
- } else {
- builder.setRequestData(requestObject.getRequestData());
- }
builder.setHeader("pageurl", Location.getHref());
+
builder.setRequestData(ClientRequestHelper.getRequestString(requestObject.getRequestData().getRequestMap(
+ ((DeltaValueStoreJsonImpl)
requestObject.getDeltaValueStore()).toJson())));
builder.setCallback(new RequestCallback() {
public void onError(Request request, Throwable exception) {
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
Thu Aug 5 10:04:19 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/rebind/RequestFactoryGenerator.java
Thu Aug 5 15:15:34 2010
@@ -43,13 +43,12 @@
import com.google.gwt.requestfactory.client.impl.AbstractLongRequest;
import com.google.gwt.requestfactory.client.impl.AbstractShortRequest;
import com.google.gwt.requestfactory.client.impl.AbstractVoidRequest;
-import com.google.gwt.requestfactory.client.impl.ClientRequestHelper;
import com.google.gwt.requestfactory.client.impl.RequestFactoryJsonImpl;
import
com.google.gwt.requestfactory.server.ReflectionBasedOperationRegistry;
import com.google.gwt.requestfactory.shared.RecordListRequest;
import com.google.gwt.requestfactory.shared.RecordRequest;
+import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.RequestFactory;
-import com.google.gwt.requestfactory.shared.impl.JsonRequestDataUtil;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
import com.google.gwt.valuestore.shared.Property;
@@ -281,7 +280,7 @@
}
requestSelectors.add(method);
}
-
+
// In addition to the request selectors in the generated interface,
there
// are a few which are in RequestFactory which also need to have
// implementations generated. Hard coding the addition of these here
for now
@@ -296,25 +295,27 @@
// write create(Class..)
JClassType recordToTypeInterface =
generatorContext.getTypeOracle().findType(
RecordToTypeMap.class.getName());
- String recordToTypeMapName = recordToTypeInterface.getName() + "Impl";
+ String recordToTypeMapName = recordToTypeInterface.getName() + "Impl";
sw.println("public " + Record.class.getName() + " create(Class token)
{");
sw.indent();
sw.println("return create(token, new " + recordToTypeMapName + "());");
sw.outdent();
sw.println("}");
-
+
// write a method for each request builder and generate it
for (JMethod requestSelector : requestSelectors) {
String returnTypeName =
requestSelector.getReturnType().getQualifiedSourceName();
- String nestedImplName = requestSelector.getName().replace('.', '_')
+ String nestedImplName =
capitalize(requestSelector.getName().replace('.',
+ '_'))
+ "Impl";
- String nestedImplPackage =
-
generatorContext.getTypeOracle().findType(returnTypeName).getPackage().getName();
+ String nestedImplPackage = generatorContext.getTypeOracle().findType(
+ returnTypeName).getPackage().getName();
sw.println("public " + returnTypeName + " " +
requestSelector.getName()
+ "() {");
sw.indent();
- sw.println("return new " + nestedImplPackage + "." + nestedImplName
+ "(this);");
+ sw.println("return new " + nestedImplPackage + "." + nestedImplName
+ + "(this);");
sw.outdent();
sw.println("}");
sw.println();
@@ -393,8 +394,7 @@
ClassSourceFileComposerFactory f = new ClassSourceFileComposerFactory(
packageName, implName);
- f.addImport(ClientRequestHelper.class.getName());
- f.addImport(JsonRequestDataUtil.class.getName());
+ f.addImport(RequestData.class.getName());
f.addImport(mainType.getQualifiedSourceName() + "Impl");
f.addImplementedInterface(selectorInterface.getQualifiedSourceName());
@@ -471,12 +471,11 @@
sw.println("return new " + requestClassName + "(factory" +
enumArgument
+ ") {");
sw.indent();
- sw.println("public String getRequestData() {");
+ String requestDataName = RequestData.class.getSimpleName();
+ sw.println("public " + requestDataName + " getRequestData() {");
sw.indent();
- sw.println("return " + ClientRequestHelper.class.getSimpleName()
- + ".getRequestString(" +
JsonRequestDataUtil.class.getSimpleName()
- + ".getRequestMap(\"" + operationName + "\", "
- + getParametersAsString(method) + ", null));");
+ sw.println("return new " + requestDataName + "(\"" + operationName
+ + "\", " + getParametersAsString(method, typeOracle) + ");");
sw.outdent();
sw.println("}");
sw.outdent();
@@ -522,7 +521,7 @@
* Returns the string representation of the parameters to be passed to
the
* server side method.
*/
- private String getParametersAsString(JMethod method) {
+ private String getParametersAsString(JMethod method, TypeOracle
typeOracle) {
StringBuilder sb = new StringBuilder();
for (JParameter parameter : method.getParameters()) {
if (sb.length() > 0) {
@@ -535,6 +534,11 @@
if
("com.google.gwt.valuestore.shared.PropertyReference".equals(parameter.getType().getQualifiedBinaryName()))
{
sb.append(".get()");
}
+ JClassType classType = parameter.getType().isClass();
+ if (classType != null
+ &&
classType.isAssignableTo(typeOracle.findType(Record.class.getName()))) {
+ sb.append(".getId()");
+ }
}
return "new Object[] {" + sb.toString() + "}";
}
@@ -598,7 +602,7 @@
private boolean isShortRequest(TypeOracle typeOracle, JClassType
requestType) {
return
requestType.isParameterized().getTypeArgs()[0].isAssignableTo(typeOracle.findType(Short.class.getName()));
}
-
+
private boolean isVoidRequest(TypeOracle typeOracle, JClassType
requestType) {
return
requestType.isParameterized().getTypeArgs()[0].isAssignableTo(typeOracle.findType(Void.class.getName()));
}
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Wed Aug 4 22:08:44 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/server/JsonRequestProcessor.java
Thu Aug 5 15:15:34 2010
@@ -16,8 +16,8 @@
package com.google.gwt.requestfactory.server;
import com.google.gwt.requestfactory.shared.DataTransferObject;
+import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.RequestFactory;
-import com.google.gwt.requestfactory.shared.impl.JsonRequestDataUtil;
import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.shared.Record;
import com.google.gwt.valuestore.shared.WriteOperation;
@@ -349,7 +349,7 @@
Iterator<?> keys = jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next().toString();
- if (key.startsWith(JsonRequestDataUtil.PARAM_TOKEN)) {
+ if (key.startsWith(RequestData.PARAM_TOKEN)) {
parameterMap.put(key, jsonObject.getString(key));
}
}
@@ -479,9 +479,9 @@
RequestDefinition operation;
JSONObject topLevelJsonObject = new JSONObject(jsonRequestString);
- String operationName =
topLevelJsonObject.getString(JsonRequestDataUtil.OPERATION_TOKEN);
+ String operationName =
topLevelJsonObject.getString(RequestData.OPERATION_TOKEN);
if (operationName.equals(RequestFactory.SYNC)) {
- return
sync(topLevelJsonObject.getString(JsonRequestDataUtil.CONTENT_TOKEN));
+ return sync(topLevelJsonObject.getString(RequestData.CONTENT_TOKEN));
} else {
operation = getOperation(operationName);
Class<?> domainClass = Class.forName(operation.getDomainClassName());
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
Wed Aug 4 14:25:37 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/server/RequestFactoryServlet.java
Thu Aug 5 15:15:34 2010
@@ -54,6 +54,7 @@
*/
@SuppressWarnings("serial")
public class RequestFactoryServlet extends HttpServlet {
+
private static final String JSON_CHARSET = "UTF-8";
private static final String JSON_CONTENT_TYPE = "application/json";
@@ -78,7 +79,7 @@
} else {
response.setHeader("userId", String.format("%d",
userInfo.getId()));
response.setStatus(HttpServletResponse.SC_OK);
- JsonRequestProcessor requestProcessor = new JsonRequestProcessor();
+ RequestProcessor<String> requestProcessor = new
JsonRequestProcessor();
requestProcessor.setOperationRegistry(new
ReflectionBasedOperationRegistry(
new DefaultSecurityProvider()));
response.setHeader(
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
Fri Jul 30 17:29:09 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
Thu Aug 5 15:15:34 2010
@@ -15,8 +15,8 @@
*/
package com.google.gwt.requestfactory.server;
+import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.RequestFactory;
-import com.google.gwt.requestfactory.shared.impl.JsonRequestDataUtil;
import com.google.gwt.valuestore.shared.WriteOperation;
import org.apache.commons.httpclient.HttpClient;
@@ -88,8 +88,8 @@
IOException, JSONException {
PostMethod post = new PostMethod(url);
JSONObject request = new JSONObject();
- request.put(JsonRequestDataUtil.OPERATION_TOKEN, RequestFactory.SYNC);
- request.put(JsonRequestDataUtil.CONTENT_TOKEN, contentData);
+ request.put(RequestData.OPERATION_TOKEN, RequestFactory.SYNC);
+ request.put(RequestData.CONTENT_TOKEN, contentData);
post.setRequestBody(request.toString());
HttpClient client = new HttpClient();
int status = client.executeMethod(post);
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/shared/RequestObject.java
Fri Jul 30 11:32:15 2010
+++ /trunk/user/src/com/google/gwt/requestfactory/shared/RequestObject.java
Thu Aug 5 15:15:34 2010
@@ -36,7 +36,7 @@
// can get access to a DeltaValueStore only in the context of a
RequestObject.
DeltaValueStore getDeltaValueStore();
- String getRequestData();
+ RequestData getRequestData();
void handleResponseText(String responseText);
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestDataManager.java
Thu Jun 24 14:48:00 2010
+++
/trunk/user/src/com/google/gwt/requestfactory/shared/impl/RequestDataManager.java
Thu Aug 5 15:15:34 2010
@@ -15,7 +15,6 @@
*/
package com.google.gwt.requestfactory.shared.impl;
-import java.util.HashMap;
import java.util.Map;
/**
@@ -31,10 +30,6 @@
*/
public class RequestDataManager {
- public static final String CONTENT_TOKEN = "contentData";
- public static final String OPERATION_TOKEN = "operation";
- public static final String PARAM_TOKEN = "param";
-
public static Object[] getObjectsFromParameterMap(
Map<String, String> parameterMap, Class<?> parameterClasses[]) {
assert parameterClasses != null;
@@ -45,26 +40,6 @@
}
return args;
}
-
- /**
- * Returns the string that encodes the request data.
- *
- */
- public static Map<String, String> getRequestMap(String operation,
- Object values[], String content) {
- Map<String, String> requestMap = new HashMap<String, String>();
- requestMap.put(OPERATION_TOKEN, operation);
- if (values != null) {
- for (int i = 0; i < values.length; i++) {
- Object value = values[i];
- requestMap.put(PARAM_TOKEN + i, value.toString());
- }
- }
- if (content != null) {
- requestMap.put(CONTENT_TOKEN, content);
- }
- return requestMap;
- }
/**
* Encodes parameter value.
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Wed Aug 4 22:08:44 2010
+++
/trunk/user/test/com/google/gwt/requestfactory/server/JsonRequestProcessorTest.java
Thu Aug 5 15:15:34 2010
@@ -15,8 +15,8 @@
*/
package com.google.gwt.requestfactory.server;
+import com.google.gwt.requestfactory.shared.RequestData;
import com.google.gwt.requestfactory.shared.RequestFactory;
-import com.google.gwt.requestfactory.shared.impl.JsonRequestDataUtil;
import com.google.gwt.valuestore.server.SimpleFoo;
import com.google.gwt.valuestore.shared.SimpleEnum;
import com.google.gwt.valuestore.shared.SimpleFooRecord;
@@ -95,10 +95,10 @@
try {
// fetch object
JSONObject foo = (JSONObject) requestProcessor.processJsonRequest("{
\""
- + JsonRequestDataUtil.OPERATION_TOKEN + "\": \""
+ + RequestData.OPERATION_TOKEN + "\": \""
+
com.google.gwt.valuestore.shared.SimpleFooRequest.class.getName()
+ ReflectionBasedOperationRegistry.SCOPE_SEPARATOR
- + "findSimpleFooById\", " + "\"" +
JsonRequestDataUtil.PARAM_TOKEN
+ + "findSimpleFooById\", " + "\"" + RequestData.PARAM_TOKEN
+ "0\": \"999\" }");
assertEquals(foo.getInt("id"), 999);
assertEquals(foo.getInt("intId"), 42);
@@ -124,8 +124,8 @@
JSONObject operation = new JSONObject();
operation.put(WriteOperation.UPDATE.toString(), arr);
JSONObject sync = new JSONObject();
- sync.put(JsonRequestDataUtil.OPERATION_TOKEN, RequestFactory.SYNC);
- sync.put(JsonRequestDataUtil.CONTENT_TOKEN, operation.toString());
+ sync.put(RequestData.OPERATION_TOKEN, RequestFactory.SYNC);
+ sync.put(RequestData.CONTENT_TOKEN, operation.toString());
JSONObject result = (JSONObject)
requestProcessor.processJsonRequest(sync.toString());
// check modified fields and no violations
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors