Reviewers: bobv, to.broyer_gmail.com,
Description:
Add ServiceLayer#resolveServiceClass to resolve issue 5807.
Formerly reviewed at 1370803
Please review this at http://gwt-code-reviews.appspot.com/1385802/
Affected files:
M user/src/com/google/gwt/requestfactory/server/LocatorServiceLayer.java
M user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
M user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
M user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
Index:
user/src/com/google/gwt/requestfactory/server/LocatorServiceLayer.java
===================================================================
--- user/src/com/google/gwt/requestfactory/server/LocatorServiceLayer.java
(revision 9813)
+++ user/src/com/google/gwt/requestfactory/server/LocatorServiceLayer.java
(working copy)
@@ -52,7 +52,9 @@
Class<? extends ServiceLocator> locatorType =
getTop().resolveServiceLocator(contextMethod, domainMethod);
ServiceLocator locator = newInstance(locatorType,
ServiceLocator.class);
- return locator.getInstance(domainMethod.getDeclaringClass());
+ // Enclosing class may be a parent class, so invoke on service class
+ Class<?> serviceClass = getTop().resolveServiceClass(contextMethod);
+ return locator.getInstance(serviceClass);
}
@Override
Index:
user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
===================================================================
--- user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
(revision 9813)
+++ user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
(working copy)
@@ -117,22 +117,7 @@
@Override
public Method resolveDomainMethod(Method requestContextMethod) {
- Class<?> enclosing = requestContextMethod.getDeclaringClass();
-
- Class<?> searchIn = null;
- Service s = enclosing.getAnnotation(Service.class);
- if (s != null) {
- searchIn = s.value();
- }
- ServiceName sn = enclosing.getAnnotation(ServiceName.class);
- if (sn != null) {
- searchIn = forName(sn.value());
- }
- if (searchIn == null) {
- die(null, "The %s type %s did not specify a service type",
RequestContext.class
- .getSimpleName(), enclosing.getCanonicalName());
- }
-
+ Class<?> searchIn = getTop().resolveServiceClass(requestContextMethod);
Class<?>[] parameterTypes = requestContextMethod.getParameterTypes();
Class<?>[] domainArgs = new Class<?>[parameterTypes.length];
for (int i = 0, j = domainArgs.length; i < j; i++) {
@@ -179,6 +164,26 @@
}
@Override
+ public Class<?> resolveServiceClass(Method requestContextMethod) {
+ Class<?> enclosing = requestContextMethod.getDeclaringClass();
+
+ Class<?> searchIn = null;
+ Service s = enclosing.getAnnotation(Service.class);
+ if (s != null) {
+ searchIn = s.value();
+ }
+ ServiceName sn = enclosing.getAnnotation(ServiceName.class);
+ if (sn != null) {
+ searchIn = forName(sn.value());
+ }
+ if (searchIn == null) {
+ die(null, "The %s type %s did not specify a service type",
RequestContext.class
+ .getSimpleName(), enclosing.getCanonicalName());
+ }
+ return searchIn;
+ }
+
+ @Override
public String resolveTypeToken(Class<? extends BaseProxy> clazz) {
return clazz.getName();
}
Index: user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
===================================================================
--- user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
(revision 9813)
+++ user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
(working copy)
@@ -333,6 +333,15 @@
public abstract Method resolveRequestContextMethod(String
requestContextClass, String methodName);
/**
+ * Given a {@link RequestContext} method, find the service class
referenced in
+ * the {@link Service} or {@link ServiceName} annotation.
+ *
+ * @param requestContextMethod a RequestContext method declaration
+ * @return the type of service to use
+ */
+ public abstract Class<?> resolveServiceClass(Method
requestContextMethod);
+
+ /**
* Given a RequestContext method declaration, resolve the
* {@link ServiceLocator} that should be used when invoking the domain
method.
* This method will only be called if {@link
#requiresServiceLocator(Method)}
@@ -373,4 +382,4 @@
* @return the violations associated with the domain object
*/
public abstract <T> Set<ConstraintViolation<T>> validate(T domainObject);
-}
\ No newline at end of file
+}
Index:
user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
===================================================================
---
user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
(revision 9813)
+++
user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
(working copy)
@@ -156,6 +156,11 @@
}
@Override
+ public Class<?> resolveServiceClass(Method requestContextMethod) {
+ return getNext().resolveServiceClass(requestContextMethod);
+ }
+
+ @Override
public Class<? extends ServiceLocator> resolveServiceLocator(Method
contextMethod,
Method domainMethod) {
return getNext().resolveServiceLocator(contextMethod, domainMethod);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors