Revision: 7759
Author: [email protected]
Date: Mon Mar 22 07:44:56 2010
Log: No more massive copy paste between our request
objects. Introduces the abstract classes for RequestFactory
and its request object.
Also some clean up to make it more clear what classes will
come from GWT code generators and what will come from
pre-compilation tools. Part of this moves HandleManager to a
more appropriate package, since it won't be generated.
Review at http://gwt-code-reviews.appspot.com/250801
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=7759
Added:
/trunk/bikeshed/src/com/google/gwt/requestfactory/client
/trunk/bikeshed/src/com/google/gwt/requestfactory/client/impl
/trunk/bikeshed/src/com/google/gwt/requestfactory/client/impl/AbstractListJsonRequestObject.java
/trunk/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/impl
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/impl/UrlParameterManager.java
Deleted:
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/UrlParameterManager.java
Modified:
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/EntityListRequest.java
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeKey.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportKey.java
=======================================
--- /dev/null
+++
/trunk/bikeshed/src/com/google/gwt/requestfactory/client/impl/AbstractListJsonRequestObject.java
Mon Mar 22 07:44:56 2010
@@ -0,0 +1,110 @@
+/*
+ * 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.client.impl;
+
+import com.google.gwt.core.client.JsArray;
+import com.google.gwt.requestfactory.shared.EntityKey;
+import com.google.gwt.requestfactory.shared.RequestFactory;
+import com.google.gwt.requestfactory.shared.RequestFactory.Service;
+import com.google.gwt.user.client.ui.HasValueList;
+import com.google.gwt.valuestore.client.ValuesImpl;
+import com.google.gwt.valuestore.shared.Property;
+import com.google.gwt.valuestore.shared.ValueStore;
+import com.google.gwt.valuestore.shared.Values;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Abstract implementation of {...@link RequestFactory.RequestObject} for
methods
+ * returning lists of entities.
+ *
+ * @param <T> the type of entities returned
+ * @param <R> this request type
+ */
+public abstract class AbstractListJsonRequestObject<T extends
EntityKey<T>, R extends AbstractListJsonRequestObject<T, R>>
+ implements RequestFactory.RequestObject {
+
+ private final T key;
+ private final Service requestService;
+ @SuppressWarnings("unused")
+ // That's next
+ private final ValueStore valueStore;
+
+ private final Set<Property<T, ?>> properties = new
HashSet<Property<T, ?>>();
+
+ private HasValueList<Values<T>> watcher;
+
+ public AbstractListJsonRequestObject(T key, ValueStore valueStore,
+ RequestFactory.Service requestService) {
+ this.requestService = requestService;
+ this.valueStore = valueStore;
+ this.key = key;
+ }
+
+ public void fire() {
+ requestService.fire(this);
+ }
+
+ public R forProperties(Collection<Property<T, ?>> properties) {
+ for (Property<T, ?> property : properties) {
+ forProperty(property);
+ }
+ return getThis();
+ }
+
+ public R forProperty(Property<T, ?> property) {
+ properties.add(property);
+ return getThis();
+ }
+
+ /**
+ * @return the properties
+ */
+ public Set<Property<T, ?>> getProperties() {
+ return properties;
+ }
+
+ public void handleResponseText(String text) {
+ // DeltaValueStore deltaStore = valueStore.edit();
+ JsArray<ValuesImpl<T>> valueArray = ValuesImpl.arrayFromJson(text);
+ List<Values<T>> valueList = new
ArrayList<Values<T>>(valueArray.length());
+ for (int i = 0; i < valueArray.length(); i++) {
+ ValuesImpl<T> values = valueArray.get(i);
+ values.setPropertyHolder(key);
+ // deltaStore.setValue(propertyHolder, properties, values);
+ valueList.add(values);
+ }
+
+ // valueStore.subscribe(watcher, valueList, properties);
+ // deltaStore.commit();
+ watcher.setValueList(valueList);
+ }
+
+ public R to(HasValueList<Values<T>> watcher) {
+ this.watcher = watcher;
+ return getThis();
+ }
+
+ /**
+ * Subclasses must override to return {...@code this}, to allow
builder-style
+ * methods to do the same.
+ */
+ protected abstract R getThis();
+}
=======================================
--- /dev/null
+++
/trunk/bikeshed/src/com/google/gwt/requestfactory/client/impl/RequestFactoryJsonImpl.java
Mon Mar 22 07:44:56 2010
@@ -0,0 +1,155 @@
+/*
+ * 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.client.impl;
+
+import com.google.gwt.http.client.Request;
+import com.google.gwt.http.client.RequestBuilder;
+import com.google.gwt.http.client.RequestCallback;
+import com.google.gwt.http.client.RequestException;
+import com.google.gwt.http.client.Response;
+import com.google.gwt.requestfactory.shared.RequestFactory;
+import com.google.gwt.requestfactory.shared.SyncRequest;
+import com.google.gwt.sample.expenses.gen.MethodName;
+import com.google.gwt.user.client.ui.HasValue;
+import com.google.gwt.user.client.ui.HasValueList;
+import com.google.gwt.valuestore.client.ValuesImpl;
+import com.google.gwt.valuestore.shared.DeltaValueStore;
+import com.google.gwt.valuestore.shared.Property;
+import com.google.gwt.valuestore.shared.ValueStore;
+import com.google.gwt.valuestore.shared.Values;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Base implementation of RequestFactory.
+ */
+public class RequestFactoryJsonImpl implements RequestFactory,
+ RequestFactory.Service {
+
+ private final ValueStore valueStore = new ValueStore() {
+
+ public void addValidation() {
+ throw new UnsupportedOperationException();
+ }
+
+ public DeltaValueStore edit() {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T, V> void subscribe(HasValue<V> watcher, T propertyOwner,
+ Property<T, V> property) {
+ throw new UnsupportedOperationException();
+ }
+
+ public <T, V> void subscribe(HasValueList<Values<T>> watcher,
+ T propertyOwner, Set<Property<T, ?>> properties) {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+
+ @SuppressWarnings("deprecation")
+ public void fire(final RequestObject requestObject) {
+ RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
+ requestObject.getRequestUrl());
+ builder.setCallback(new RequestCallback() {
+
+ public void onError(Request request, Throwable exception) {
+ // shell.error.setInnerText(SERVER_ERROR);
+ }
+
+ public void onResponseReceived(Request request, Response response) {
+ if (200 == response.getStatusCode()) {
+ String text = response.getText();
+ requestObject.handleResponseText(text);
+ } else {
+ // shell.error.setInnerText(SERVER_ERROR + " ("
+ // + response.getStatusText() + ")");
+ }
+ }
+
+ });
+
+ try {
+ builder.send();
+ } catch (RequestException e) {
+ // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage() +
+ // ")");
+ }
+ }
+
+ public ValueStore getValueStore() {
+ return valueStore;
+ }
+
+ /**
+ * @param deltaValueStore
+ * @return
+ */
+ public SyncRequest syncRequest(final List<Values<?>> deltaValueStore) {
+ return new SyncRequest() {
+
+ public void fire() {
+
+ RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
+ "/expenses/data?methodName=" + MethodName.SYNC.name());
+
+ StringBuilder requestData = new StringBuilder("[");
+ boolean first = true;
+ for (Values<?> v : deltaValueStore) {
+ ValuesImpl<?> impl = (ValuesImpl<?>) v;
+ if (first) {
+ first = false;
+ } else {
+ requestData.append(",");
+ }
+ requestData.append(impl.toJson());
+ }
+ requestData.append("]");
+
+ builder.setRequestData(requestData.toString());
+ builder.setCallback(new RequestCallback() {
+
+ public void onError(Request request, Throwable exception) {
+ // shell.error.setInnerText(SERVER_ERROR);
+ }
+
+ public void onResponseReceived(Request request, Response
response) {
+ if (200 == response.getStatusCode()) {
+ // String text = response.getText();
+ // parse the return value.
+
+ // publish this value to all subscribers that are interested.
+ } else {
+ // shell.error.setInnerText(SERVER_ERROR + " ("
+ // + response.getStatusText() + ")");
+ }
+ }
+ });
+
+ try {
+ builder.send();
+ } catch (RequestException e) {
+ // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage()
+
+ // ")");
+ }
+ // values.subscribe(watcher, future, properties);
+ }
+
+ };
+ }
+}
=======================================
--- /dev/null
+++
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/impl/UrlParameterManager.java
Mon Mar 22 07:44:56 2010
@@ -0,0 +1,82 @@
+/*
+ * 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.Map;
+
+/**
+ * An utitlity class to manage the encoding and decoding of parameters.
+ *
+ * TODO: add appropriate unit tests.
+ */
+public class UrlParameterManager {
+
+ private static final String TOKEN = "param";
+
+ public static Object[] getObjectsFromFragment(
+ Map<String, String[]> parameterMap, Class<?> parameterClasses[]) {
+ assert parameterClasses != null;
+ Object args[] = new Object[parameterClasses.length];
+ for (int i = 0; i < parameterClasses.length; i++) {
+ args[i] = encodeParameterValue(parameterClasses[i].getName(),
+ parameterMap.get("param" + i));
+ }
+ return args;
+ }
+
+ /**
+ * Returns the string that encodes the values. The string has a leading
&.
+ *
+ * @param values
+ * @return
+ */
+ public static String getUrlFragment(Object values[]) {
+ assert values != null;
+ StringBuffer fragment = new StringBuffer();
+ for (int i = 0; i < values.length; i++) {
+ Object value = values[i];
+ fragment.append("&");
+ fragment.append(TOKEN);
+ fragment.append(i);
+ fragment.append("=");
+ fragment.append(value.toString());
+ }
+ return fragment.toString();
+ }
+
+ /**
+ * Encodes parameter value.
+ *
+ */
+ private static Object encodeParameterValue(String parameterType,
+ String parameterValues[]) {
+ assert parameterValues != null;
+ assert parameterValues.length == 1;
+ String parameterValue = parameterValues[0];
+ if ("java.lang.String".equals(parameterType)) {
+ return parameterValue;
+ }
+ if ("java.lang.Integer".equals(parameterType)
+ || "int".equals(parameterType)) {
+ return new Integer(parameterValue);
+ }
+ if ("java.lang.Long".equals(parameterType) |
| "long".equals(parameterType)) {
+ return new Long(parameterValue);
+ }
+ throw new IllegalArgumentException("Unknown parameter type: "
+ + parameterType);
+ }
+}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/UrlParameterManager.java
Thu Mar 18 15:14:08 2010
+++ /dev/null
@@ -1,82 +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.sample.expenses.gen;
-
-import java.util.Map;
-
-/**
- * An utitlity class to manage the encoding and decoding of parameters.
- *
- * TODO: add appropriate unit tests.
- */
-public class UrlParameterManager {
-
- private static final String TOKEN = "param";
-
- public static Object[] getObjectsFromFragment(
- Map<String, String[]> parameterMap, Class<?> parameterClasses[]) {
- assert parameterClasses != null;
- Object args[] = new Object[parameterClasses.length];
- for (int i = 0; i < parameterClasses.length; i++) {
- args[i] = encodeParameterValue(parameterClasses[i].getName(),
- parameterMap.get("param" + i));
- }
- return args;
- }
-
- /**
- * Returns the string that encodes the values. The string has a leading
&.
- *
- * @param values
- * @return
- */
- public static String getUrlFragment(Object values[]) {
- assert values != null;
- StringBuffer fragment = new StringBuffer();
- for (int i = 0; i < values.length; i++) {
- Object value = values[i];
- fragment.append("&");
- fragment.append(TOKEN);
- fragment.append(i);
- fragment.append("=");
- fragment.append(value.toString());
- }
- return fragment.toString();
- }
-
- /**
- * Encodes parameter value.
- *
- */
- private static Object encodeParameterValue(String parameterType,
- String parameterValues[]) {
- assert parameterValues != null;
- assert parameterValues.length == 1;
- String parameterValue = parameterValues[0];
- if ("java.lang.String".equals(parameterType)) {
- return parameterValue;
- }
- if ("java.lang.Integer".equals(parameterType)
- || "int".equals(parameterType)) {
- return new Integer(parameterValue);
- }
- if ("java.lang.Long".equals(parameterType) |
| "long".equals(parameterType)) {
- return new Long(parameterValue);
- }
- throw new IllegalArgumentException("Unknown parameter type: "
- + parameterType);
- }
-}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/EntityListRequest.java
Fri Mar 19 10:26:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/EntityListRequest.java
Mon Mar 22 07:44:56 2010
@@ -27,9 +27,7 @@
*
* @param <E> The type held by the returned list
*/
-public interface EntityListRequest<E> {
- void fire();
-
+public interface EntityListRequest<E> extends RequestFactory.RequestObject
{
EntityListRequest<E> forProperties(Collection<Property<E, ?>>
properties);
EntityListRequest<E> forProperty(Property<E, ?> property);
=======================================
---
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java
Mon Mar 15 08:44:11 2010
+++
/trunk/bikeshed/src/com/google/gwt/requestfactory/shared/RequestFactory.java
Mon Mar 22 07:44:56 2010
@@ -1,12 +1,12 @@
/*
* 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
@@ -24,10 +24,33 @@
* Marker interface for the RequestFactory code generator.
*/
public interface RequestFactory {
+
+ /**
+ * Implemented by the request objects created by this factory.
+ */
+ interface RequestObject {
+ void fire();
+
+ String getRequestData(String data);
+
+ /**
+ * @deprecated Here only until we can move everything into the post
data
+ */
+ String getRequestUrl();
+
+ void handleResponseText(String responseText);
+ }
+
+ /**
+ * Implemented by the RPC service backing this factory.
+ */
+ interface Service {
+ void fire(RequestObject request);
+ }
ValueStore getValueStore();
- // TODO actually a DeltaValueStore, interim hack
+ // TODO actually a DeltaValueStore, List is an interim hack
SyncRequest syncRequest(final List<Values<?>> deltaValueStore);
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java
Fri Mar 19 10:26:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/EmployeeRequestImpl.java
Mon Mar 22 07:44:56 2010
@@ -15,107 +15,55 @@
*/
package com.google.gwt.sample.expenses.gen;
-import com.google.gwt.core.client.JsArray;
-import com.google.gwt.http.client.Request;
-import com.google.gwt.http.client.RequestBuilder;
-import com.google.gwt.http.client.RequestCallback;
-import com.google.gwt.http.client.RequestException;
-import com.google.gwt.http.client.Response;
+import
com.google.gwt.requestfactory.client.impl.AbstractListJsonRequestObject;
import com.google.gwt.requestfactory.shared.EntityListRequest;
+import com.google.gwt.requestfactory.shared.RequestFactory.Service;
import com.google.gwt.sample.expenses.shared.EmployeeKey;
import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
-import com.google.gwt.user.client.ui.HasValueList;
-import com.google.gwt.valuestore.client.ValuesImpl;
-import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.shared.ValueStore;
-import com.google.gwt.valuestore.shared.Values;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
/**
- * "Generated" from static methods of {...@link
com.google.gwt.sample.expenses.server.domain.Employee}.
+ * "Code generated" implementation of
{ExpenseRequestFactory.EmployeeRequest}
+ * <p>
+ * IRL this will be generated as a side effect of a call to
+ * GWT.create(ExpenseRequestFactory.class)
*/
-public class EmployeeRequestImpl implements
ExpenseRequestFactory.EmployeeRequest {
-
- @SuppressWarnings("unused") // TODO next step is to use it
- private ValueStore valueStore;
-
- public EmployeeRequestImpl(ValueStore valueStore) {
- this.valueStore = valueStore;
+public class EmployeeRequestImpl implements
+ ExpenseRequestFactory.EmployeeRequest {
+
+ private abstract class Request extends
+ AbstractListJsonRequestObject<EmployeeKey, Request> implements
+ EntityListRequest<EmployeeKey> {
+
+ Request() {
+ super(EmployeeKey.get(), valueStore, requestService);
+ }
+
+ @Override
+ protected Request getThis() {
+ return this;
+ }
}
- public EntityListRequest<EmployeeKey> findAllEmployees() {
-
-
- return new EntityListRequest<EmployeeKey>() {
- private HasValueList<Values<EmployeeKey>> watcher;
- private Set<Property<EmployeeKey, ?>> properties = new
HashSet<Property<EmployeeKey, ?>>();
-
- public void fire() {
- // TODO: accumulate and batch fire requests, e.g. once batch per
event loop
- // TODO: cache and short circuit find requests
- RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
- "/expenses/data?methodName=" +
MethodName.FIND_ALL_EMPLOYEES.name());
- builder.setCallback(new RequestCallback() {
-
- public void onError(Request request, Throwable exception) {
- // shell.error.setInnerText(SERVER_ERROR);
- }
-
- public void onResponseReceived(Request request, Response
response) {
- if (200 == response.getStatusCode()) {
- String text = response.getText();
-// DeltaValueStore deltaStore = valueStore.edit();
- JsArray<ValuesImpl<EmployeeKey>> valueArray =
ValuesImpl.arrayFromJson(text);
- List<Values<EmployeeKey>> valueList = new
ArrayList<Values<EmployeeKey>>(
- valueArray.length());
- for (int i = 0; i < valueArray.length(); i++) {
- ValuesImpl<EmployeeKey> values = valueArray.get(i);
- values.setPropertyHolder(EmployeeKey.get());
-// deltaStore.setValue(propertyHolder, properties, values);
- valueList.add(values);
- }
-
-// valueStore.subscribe(watcher, valueList, properties);
-// deltaStore.commit();
- watcher.setValueList(valueList);
- } else {
- // shell.error.setInnerText(SERVER_ERROR + " ("
- // + response.getStatusText() + ")");
- }
- }
- });
-
- try {
- builder.send();
- } catch (RequestException e) {
- // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage()
+
- // ")");
- }
+ private final ValueStore valueStore;
+ public final Service requestService;
+
+ public EmployeeRequestImpl(ValueStore valueStore, Service
requestService) {
+ this.valueStore = valueStore;
+ this.requestService = requestService;
+ }
+
+ public EntityListRequest<EmployeeKey> findAllEmployees() {
+ return new Request() {
+ public String getRequestData(String data) {
+ // TODO Dear Amit: your code here
+ throw new UnsupportedOperationException();
}
- public EntityListRequest<EmployeeKey> forProperties(
- Collection<Property<EmployeeKey, ?>> properties) {
- for (Property<EmployeeKey, ?> property : properties) {
- forProperty(property);
- }
- return this;
- }
-
- public EntityListRequest<EmployeeKey> forProperty(
- Property<EmployeeKey, ?> property) {
- properties.add(property);
- return this;
- }
-
- public EntityListRequest<EmployeeKey> to(
- HasValueList<Values<EmployeeKey>> watcher) {
- this.watcher = watcher;
- return this;
+ @SuppressWarnings("deprecation")
+ public String getRequestUrl() {
+ return "/expenses/data?methodName="
+ + MethodName.FIND_ALL_EMPLOYEES.name();
}
};
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java
Fri Mar 19 10:26:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/ExpenseRequestFactoryImpl.java
Mon Mar 22 07:44:56 2010
@@ -15,131 +15,32 @@
*/
package com.google.gwt.sample.expenses.gen;
-import com.google.gwt.http.client.Request;
-import com.google.gwt.http.client.RequestBuilder;
-import com.google.gwt.http.client.RequestCallback;
-import com.google.gwt.http.client.RequestException;
-import com.google.gwt.http.client.Response;
-import com.google.gwt.requestfactory.shared.SyncRequest;
+import com.google.gwt.requestfactory.client.impl.RequestFactoryJsonImpl;
import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
-import com.google.gwt.user.client.ui.HasValue;
-import com.google.gwt.user.client.ui.HasValueList;
-import com.google.gwt.valuestore.client.ValuesImpl;
import com.google.gwt.valuestore.shared.DeltaValueStore;
-import com.google.gwt.valuestore.shared.Property;
-import com.google.gwt.valuestore.shared.ValueStore;
-import com.google.gwt.valuestore.shared.Values;
-
-import java.util.List;
-import java.util.Set;
/**
- * "Generated" factory for requests against
+ * "Code generated" factory for requests against
* com.google.gwt.sample.expenses.domain.
* <p>
- * IRL would be an interface that was generated by a JPA-savvy script, and
the
- * following implementation would in turn be generated by a call to
+ * IRL this will be generated by a call to
* GWT.create(ExpenseRequestFactory.class)
*/
-public class ExpenseRequestFactoryImpl implements ExpenseRequestFactory {
- public final ValueStore values = new ValueStore() {
-
- public void addValidation() {
- // TODO Auto-generated method stub
- }
-
- public DeltaValueStore edit() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public <T, V> void subscribe(HasValue<V> watcher, T propertyOwner,
- Property<T, V> property) {
- // TODO Auto-generated method stub
- }
-
- public <T, V> void subscribe(HasValueList<Values<T>> watcher,
- T propertyOwner, Set<Property<T, ?>> properties) {
- // TODO Auto-generated method stub
- }};
-
+public class ExpenseRequestFactoryImpl extends RequestFactoryJsonImpl
implements
+ ExpenseRequestFactory {
public EmployeeRequest employeeRequest() {
- return new EmployeeRequestImpl(values);
+ return new EmployeeRequestImpl(getValueStore(), this);
}
public EmployeeRequest employeeRequest(DeltaValueStore deltas) {
- return new EmployeeRequestImpl(deltas);
- }
-
- public ValueStore getValueStore() {
- return values;
+ return new EmployeeRequestImpl(deltas, this);
}
public ReportRequest reportRequest() {
- return new ReportRequestImpl(values);
+ return new ReportRequestImpl(getValueStore(), this);
}
public ReportRequest reportRequest(DeltaValueStore deltas) {
- return new ReportRequestImpl(deltas);
- }
-
- /**
- * @param deltaValueStore
- * @return
- */
- public SyncRequest syncRequest(final List<Values<?>> deltaValueStore) {
- return new SyncRequest() {
-
- public void fire() {
-
- // TODO: need some way to track that this request has been issued
so that
- // we don't issue another request that arrives while we are
waiting for
- // the response.
- RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
- "/expenses/data?methodName=" + MethodName.SYNC.name());
-
- StringBuilder requestData = new StringBuilder("[");
- boolean first = true;
- for (Values<?> v : deltaValueStore) {
- ValuesImpl<?> impl = (ValuesImpl<?>) v;
- if (first) {
- first = false;
- } else {
- requestData.append(",");
- }
- requestData.append(impl.toJson());
- }
- requestData.append("]");
-
- builder.setRequestData(requestData.toString());
- builder.setCallback(new RequestCallback() {
-
- public void onError(Request request, Throwable exception) {
- // shell.error.setInnerText(SERVER_ERROR);
- }
-
- public void onResponseReceived(Request request, Response
response) {
- if (200 == response.getStatusCode()) {
- // String text = response.getText();
- // parse the return value.
-
- // publish this value to all subscribers that are interested.
- } else {
- // shell.error.setInnerText(SERVER_ERROR + " ("
- // + response.getStatusText() + ")");
- }
- }
- });
-
- try {
- builder.send();
- } catch (RequestException e) {
- // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage()
+
- // ")");
- }
- // values.subscribe(watcher, future, properties);
- }
-
- };
+ return new ReportRequestImpl(deltas, this);
}
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java
Mon Mar 22 05:12:31 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/gen/ReportRequestImpl.java
Mon Mar 22 07:44:56 2010
@@ -15,176 +15,74 @@
*/
package com.google.gwt.sample.expenses.gen;
-import com.google.gwt.core.client.JsArray;
-import com.google.gwt.http.client.Request;
-import com.google.gwt.http.client.RequestBuilder;
-import com.google.gwt.http.client.RequestCallback;
-import com.google.gwt.http.client.RequestException;
-import com.google.gwt.http.client.Response;
+import
com.google.gwt.requestfactory.client.impl.AbstractListJsonRequestObject;
import com.google.gwt.requestfactory.shared.EntityListRequest;
+import com.google.gwt.requestfactory.shared.RequestFactory.Service;
+import com.google.gwt.requestfactory.shared.impl.UrlParameterManager;
import com.google.gwt.sample.expenses.shared.EmployeeKey;
import com.google.gwt.sample.expenses.shared.ExpenseRequestFactory;
import com.google.gwt.sample.expenses.shared.ReportKey;
-import com.google.gwt.user.client.ui.HasValueList;
-import com.google.gwt.valuestore.client.ValuesImpl;
-import com.google.gwt.valuestore.shared.Property;
import com.google.gwt.valuestore.shared.ValueRef;
import com.google.gwt.valuestore.shared.ValueStore;
-import com.google.gwt.valuestore.shared.Values;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
/**
- * "Generated" from static methods of
- * {...@link com.google.gwt.sample.expenses.server.domain.Employee}.
+ * "Code generated" implementation of {ExpenseRequestFactory.ReportRequest}
+ * <p>
+ * IRL this will be generated as a side effect of a call to
+ * GWT.create(ExpenseRequestFactory.class)
*/
public class ReportRequestImpl implements
ExpenseRequestFactory.ReportRequest {
- @SuppressWarnings("unused")
- public ReportRequestImpl(ValueStore values) {
- }
-
- public EntityListRequest<ReportKey> findReportsByEmployee(
- final ValueRef<EmployeeKey, String> id) {
-
- return new EntityListRequest<ReportKey>() {
- Set<Property<ReportKey, ?>> properties = new
HashSet<Property<ReportKey, ?>>();
- private HasValueList<Values<ReportKey>> watcher;
-
- public void fire() {
-
- // TODO: need some way to track that this request has been issued
so
- // that we don't issue another request that arrives while we are
waiting
- // for the response.
- RequestBuilder builder = new RequestBuilder(
- RequestBuilder.GET,
- "/expenses/data?methodName="
- + MethodName.FIND_REPORTS_BY_EMPLOYEE.name()
- + UrlParameterManager.getUrlFragment(new Object[]
{id.get()}));
- builder.setCallback(new RequestCallback() {
-
- public void onError(Request request, Throwable exception) {
- // shell.error.setInnerText(SERVER_ERROR);
- }
-
- public void onResponseReceived(Request request, Response
response) {
- if (200 == response.getStatusCode()) {
- String text = response.getText();
- JsArray<ValuesImpl<ReportKey>> valueArray =
ValuesImpl.arrayFromJson(text);
- List<Values<ReportKey>> valueList = new
ArrayList<Values<ReportKey>>(
- valueArray.length());
- for (int i = 0; i < valueArray.length(); i++) {
- ValuesImpl<ReportKey> values = valueArray.get(i);
- values.setPropertyHolder(ReportKey.get());
- valueList.add(values);
- }
- watcher.setValueList(valueList);
- } else {
- // shell.error.setInnerText(SERVER_ERROR + " ("
- // + response.getStatusText() + ")");
- }
- }
- });
-
- try {
- builder.send();
- } catch (RequestException e) {
- // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage()
+
- // ")");
- }
-
- // values.subscribe(watcher, future, properties);
+ private abstract class Request extends
+ AbstractListJsonRequestObject<ReportKey, Request> implements
+ EntityListRequest<ReportKey> {
+
+ Request() {
+ super(ReportKey.get(), valueStore, requestService);
+ }
+
+ @Override
+ protected Request getThis() {
+ return this;
+ }
+ }
+
+ private final ValueStore valueStore;
+ private final Service requestService;
+
+ public ReportRequestImpl(ValueStore valueStore, Service requestService) {
+ this.valueStore = valueStore;
+ this.requestService = requestService;
+ }
+
+ public EntityListRequest<ReportKey> findAllReports() {
+ return new Request() {
+ public String getRequestData(String data) {
+ // TODO Dear Amit: your code here
+ throw new UnsupportedOperationException();
}
- public EntityListRequest<ReportKey> forProperties(
- Collection<Property<ReportKey, ?>> properties) {
- for (Property<ReportKey, ?> property : properties) {
- forProperty(property);
- }
- return this;
- }
-
- public EntityListRequest<ReportKey>
forProperty(Property<ReportKey, ?> property) {
- properties.add(property);
- return this;
- }
-
- public EntityListRequest<ReportKey>
to(HasValueList<Values<ReportKey>> watcher) {
- this.watcher = watcher;
- return this;
+ @SuppressWarnings("deprecation")
+ public String getRequestUrl() {
+ return "/expenses/data?methodName="
+ + MethodName.FIND_ALL_REPORTS.name();
}
};
- }
-
- public EntityListRequest<ReportKey> findAllReports() {
- return new EntityListRequest<ReportKey>() {
- private HasValueList<Values<ReportKey>> watcher;
-
- public void fire() {
-
- // TODO: need someway to track that this request has been issued
so that
- // we don't issue another request that arrives while we are
waiting for
- // the response.
- RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
- "/expenses/data?methodName=" +
MethodName.FIND_ALL_REPORTS.name());
- builder.setCallback(new RequestCallback() {
-
- public void onError(Request request, Throwable exception) {
- // shell.error.setInnerText(SERVER_ERROR);
- }
-
- public void onResponseReceived(Request request, Response
response) {
- if (200 == response.getStatusCode()) {
- String text = response.getText();
- JsArray<ValuesImpl<ReportKey>> valueArray =
ValuesImpl.arrayFromJson(text);
- // Handy for FireBug snooping
-// Document.get().getBody().setPropertyJSO("foo", valueArray);
- List<Values<ReportKey>> valueList = new
ArrayList<Values<ReportKey>>(
- valueArray.length());
- for (int i = 0; i < valueArray.length(); i++) {
- ValuesImpl<ReportKey> values = valueArray.get(i);
- values.setPropertyHolder(ReportKey.get());
- valueList.add(values);
- }
- watcher.setValueList(valueList);
- } else {
- // shell.error.setInnerText(SERVER_ERROR + " ("
- // + response.getStatusText() + ")");
- }
- }
- });
-
- try {
- builder.send();
- } catch (RequestException e) {
- // shell.error.setInnerText(SERVER_ERROR + " (" + e.getMessage()
+
- // ")");
- }
-
- // values.subscribe(watcher, future, properties);
- }
-
- public EntityListRequest<ReportKey> forProperties(
- Collection<Property<ReportKey, ?>> properties) {
- for (Property<ReportKey, ?> property : properties) {
- forProperty(property);
- }
- return this;
+ };
+
+ public EntityListRequest<ReportKey> findReportsByEmployee(
+ final ValueRef<EmployeeKey, String> id) {
+ return new Request() {
+ public String getRequestData(String data) {
+ // TODO Dear Amit: your code here
+ throw new UnsupportedOperationException();
}
- public EntityListRequest<ReportKey> forProperty(
- Property<ReportKey, ?> property) {
- return this;
- }
-
- public EntityListRequest<ReportKey> to(
- HasValueList<Values<ReportKey>> watcher) {
- this.watcher = watcher;
- return this;
+ @SuppressWarnings("deprecation")
+ public String getRequestUrl() {
+ return "/expenses/data?methodName="
+ + MethodName.FIND_REPORTS_BY_EMPLOYEE.name()
+ + UrlParameterManager.getUrlFragment(new Object[] {id.get()});
}
};
}
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java
Fri Mar 19 10:26:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/server/ExpensesDataServlet.java
Mon Mar 22 07:44:56 2010
@@ -16,8 +16,8 @@
package com.google.gwt.sample.expenses.server;
import com.google.gwt.requestfactory.shared.EntityKey;
+import com.google.gwt.requestfactory.shared.impl.UrlParameterManager;
import com.google.gwt.sample.expenses.gen.MethodName;
-import com.google.gwt.sample.expenses.gen.UrlParameterManager;
import com.google.gwt.sample.expenses.server.domain.Report;
import com.google.gwt.sample.expenses.server.domain.Storage;
import com.google.gwt.sample.expenses.shared.ReportKey;
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeKey.java
Fri Mar 19 10:26:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/EmployeeKey.java
Mon Mar 22 07:44:56 2010
@@ -15,10 +15,10 @@
*/
package com.google.gwt.sample.expenses.shared;
+import com.google.gwt.requestfactory.shared.EntityKey;
import com.google.gwt.requestfactory.shared.Id;
import com.google.gwt.requestfactory.shared.LongString;
import com.google.gwt.requestfactory.shared.ServerType;
-import com.google.gwt.requestfactory.shared.EntityKey;
import com.google.gwt.requestfactory.shared.Version;
import com.google.gwt.valuestore.shared.Property;
@@ -26,9 +26,12 @@
import java.util.Set;
/**
- * "Generated" proxy of
- * {...@link com.google.gwt.sample.expenses.server.domain.Employee
domain.Employee}
- * .
+ * "API Generated" key for proxy {...@link
com.google.gwt.valuestore.shared.Values
+ * Values} of {...@link com.google.gwt.sample.expenses.server.domain.Employee
+ * domain.Employee}.
+ * <p>
+ * IRL this class will be generated by a JPA-savvy tool run before
+ * compilation.
*/
@ServerType(com.google.gwt.sample.expenses.server.domain.Employee.class)
public class EmployeeKey implements EntityKey<EmployeeKey> {
@@ -87,7 +90,7 @@
public Property<EmployeeKey, String> getUserName() {
return userName;
}
-
+
@Version
public Property<EmployeeKey, Integer> getVersion() {
return version;
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
Fri Mar 19 10:26:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ExpenseRequestFactory.java
Mon Mar 22 07:44:56 2010
@@ -22,8 +22,11 @@
import com.google.gwt.valuestore.shared.ValueRef;
/**
- * Generated for the service methods of
+ * "API generated" for the service methods of
* com.google.gwt.sample.expenses.server.domain.
+ * <p>
+ * IRL this interface will be generated by a JPA-savvy tool run before
+ * compilation.
*/
public interface ExpenseRequestFactory extends RequestFactory {
=======================================
---
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportKey.java
Fri Mar 19 10:26:09 2010
+++
/trunk/bikeshed/src/com/google/gwt/sample/expenses/shared/ReportKey.java
Mon Mar 22 07:44:56 2010
@@ -15,10 +15,10 @@
*/
package com.google.gwt.sample.expenses.shared;
+import com.google.gwt.requestfactory.shared.EntityKey;
import com.google.gwt.requestfactory.shared.Id;
import com.google.gwt.requestfactory.shared.LongString;
import com.google.gwt.requestfactory.shared.ServerType;
-import com.google.gwt.requestfactory.shared.EntityKey;
import com.google.gwt.requestfactory.shared.Version;
import com.google.gwt.valuestore.shared.Property;
@@ -27,8 +27,12 @@
import java.util.Set;
/**
- * "Generated" proxy of
- * {...@link com.google.gwt.sample.expenses.server.domain.Report
domain.Report}.
+ * "API Generated" key for proxy {...@link
com.google.gwt.valuestore.shared.Values
+ * Values} of {...@link com.google.gwt.sample.expenses.server.domain.Report
+ * domain.Employee}.
+ * <p>
+ * IRL this class will be generated by a JPA-savvy tool run before
+ * compilation.
*/
@ServerType(com.google.gwt.sample.expenses.server.domain.Report.class)
public class ReportKey implements EntityKey<ReportKey> {
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
To unsubscribe from this group, send email to
google-web-toolkit-contributors+unsubscribegooglegroups.com or reply to this email with
the words "REMOVE ME" as the subject.