From d960101e9dfa3f3310e0398ead1fe481a0b36d73 Mon Sep 17 00:00:00 2001 From: Christopher Viel Date: Mon, 7 Apr 2014 16:41:04 -0400 Subject: [PATCH 1/2] Generate REST services based on the presence of @Path. --- .../carstore/client/rest/CarService.java | 3 +- .../carstore/client/rest/CarsService.java | 21 ++++++----- .../client/rest/ManufacturerService.java | 19 +++++----- .../carstore/client/rest/RatingService.java | 20 +++++------ .../carstore/client/rest/SessionService.java | 8 ++--- .../client/rest/StatisticsService.java | 3 +- .../carstore/server/rest/CarResource.java | 2 +- .../server/rest/ManufacturerResource.java | 4 +-- .../carstore/server/rest/RatingResource.java | 4 +-- .../carstore/shared/rest/PathParameter.java | 2 +- .../rest/client/AbstractRestAction.java | 2 +- .../rest/client/RestDispatcherController.java | 2 +- .../rest/rebind/AbstractServiceGenerator.java | 34 ++++++++++++------ .../rest/rebind/ChildServiceGenerator.java | 27 +++++++------- .../rest/rebind/ServiceGenerator.java | 20 +++++------ .../rest/rebind/type/ServiceDefinitions.java | 36 +++++++++---------- .../dispatch/rest/shared/RestAction.java | 3 +- .../dispatch/rest/shared/RestService.java | 11 ++---- 18 files changed, 112 insertions(+), 109 deletions(-) diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarService.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarService.java index fca5e94fb4..efa5e48da7 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarService.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarService.java @@ -21,9 +21,8 @@ import com.gwtplatform.carstore.shared.dto.CarDto; import com.gwtplatform.dispatch.rest.shared.RestAction; -import com.gwtplatform.dispatch.rest.shared.RestService; -public interface CarService extends RestService { +public interface CarService { @GET RestAction get(); diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java index 7a0ee8c7e9..e7cd0cf341 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java @@ -25,28 +25,31 @@ import javax.ws.rs.QueryParam; import com.gwtplatform.carstore.shared.dto.CarDto; -import com.gwtplatform.carstore.shared.rest.PathParameter; -import com.gwtplatform.carstore.shared.rest.ResourcesPath; -import com.gwtplatform.carstore.shared.rest.RestParameter; import com.gwtplatform.dispatch.rest.shared.RestAction; import com.gwtplatform.dispatch.rest.shared.RestService; -@Path(ResourcesPath.CARS) +import static com.gwtplatform.carstore.shared.rest.PathParameter.PATH_ID; +import static com.gwtplatform.carstore.shared.rest.ResourcesPath.CARS; +import static com.gwtplatform.carstore.shared.rest.ResourcesPath.COUNT; +import static com.gwtplatform.carstore.shared.rest.RestParameter.ID; +import static com.gwtplatform.carstore.shared.rest.RestParameter.LIMIT; +import static com.gwtplatform.carstore.shared.rest.RestParameter.OFFSET; + +@Path(CARS) public interface CarsService extends RestService { @GET RestAction> getCars(); @GET - RestAction> getCars(@QueryParam(RestParameter.OFFSET) int offset, - @QueryParam(RestParameter.LIMIT) int limit); + RestAction> getCars(@QueryParam(OFFSET) int offset, @QueryParam(LIMIT) int limit); @GET - @Path(ResourcesPath.COUNT) + @Path(COUNT) RestAction getCarsCount(); @POST RestAction saveOrCreate(CarDto carDto); - @Path(PathParameter.ID) - CarService car(@PathParam(RestParameter.ID) Long carId); + @Path(PATH_ID) + CarService car(@PathParam(ID) Long carId); } diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/ManufacturerService.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/ManufacturerService.java index afbe71eb3e..3d53ba2f57 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/ManufacturerService.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/ManufacturerService.java @@ -26,27 +26,28 @@ import com.gwtplatform.carstore.shared.dto.ManufacturerDto; import com.gwtplatform.carstore.shared.dto.ManufacturerRatingDto; -import com.gwtplatform.carstore.shared.rest.PathParameter; import com.gwtplatform.carstore.shared.rest.ResourcesPath; -import com.gwtplatform.carstore.shared.rest.RestParameter; import com.gwtplatform.dispatch.rest.shared.RestAction; -import com.gwtplatform.dispatch.rest.shared.RestService; -@Path(ResourcesPath.MANUFACTURER) -public interface ManufacturerService extends RestService { +import static com.gwtplatform.carstore.shared.rest.PathParameter.PATH_ID; +import static com.gwtplatform.carstore.shared.rest.ResourcesPath.MANUFACTURER; +import static com.gwtplatform.carstore.shared.rest.RestParameter.ID; + +@Path(MANUFACTURER) +public interface ManufacturerService { @GET RestAction> getManufacturers(); @GET - @Path(PathParameter.ID) - RestAction get(@PathParam(RestParameter.ID) Long id); + @Path(PATH_ID) + RestAction get(@PathParam(ID) Long id); @POST RestAction saveOrCreate(ManufacturerDto manufacturerDto); @DELETE - @Path(PathParameter.ID) - RestAction delete(@PathParam(RestParameter.ID) Long id); + @Path(PATH_ID) + RestAction delete(@PathParam(ID) Long id); @GET @Path(ResourcesPath.RATING) diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/RatingService.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/RatingService.java index 285eb0d772..8d310b6b63 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/RatingService.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/RatingService.java @@ -25,25 +25,25 @@ import javax.ws.rs.PathParam; import com.gwtplatform.carstore.shared.dto.RatingDto; -import com.gwtplatform.carstore.shared.rest.PathParameter; -import com.gwtplatform.carstore.shared.rest.ResourcesPath; -import com.gwtplatform.carstore.shared.rest.RestParameter; import com.gwtplatform.dispatch.rest.shared.RestAction; -import com.gwtplatform.dispatch.rest.shared.RestService; -@Path(ResourcesPath.RATING) -public interface RatingService extends RestService { +import static com.gwtplatform.carstore.shared.rest.PathParameter.PATH_ID; +import static com.gwtplatform.carstore.shared.rest.ResourcesPath.RATING; +import static com.gwtplatform.carstore.shared.rest.RestParameter.ID; + +@Path(RATING) +public interface RatingService { @GET RestAction> getRatings(); @GET - @Path(PathParameter.ID) - RestAction get(@PathParam(RestParameter.ID) Long id); + @Path(PATH_ID) + RestAction get(@PathParam(ID) Long id); @POST RestAction saveOrCreate(RatingDto RatingDto); @DELETE - @Path(PathParameter.ID) - RestAction delete(@PathParam(RestParameter.ID) Long id); + @Path(PATH_ID) + RestAction delete(@PathParam(ID) Long id); } diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/SessionService.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/SessionService.java index ae3f695bae..34b9a7f282 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/SessionService.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/SessionService.java @@ -24,12 +24,12 @@ import com.gwtplatform.carstore.shared.dispatch.LogInRequest; import com.gwtplatform.carstore.shared.dispatch.LogInResult; import com.gwtplatform.carstore.shared.dto.CurrentUserDto; -import com.gwtplatform.carstore.shared.rest.ResourcesPath; import com.gwtplatform.dispatch.rest.shared.RestAction; -import com.gwtplatform.dispatch.rest.shared.RestService; -@Path(ResourcesPath.SESSION) -public interface SessionService extends RestService { +import static com.gwtplatform.carstore.shared.rest.ResourcesPath.SESSION; + +@Path(SESSION) +public interface SessionService { @DELETE RestAction logout(); diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/StatisticsService.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/StatisticsService.java index f1bd47c148..d6c064d83d 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/StatisticsService.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/StatisticsService.java @@ -24,14 +24,13 @@ import com.gwtplatform.dispatch.rest.client.DateFormat; import com.gwtplatform.dispatch.rest.shared.RestAction; -import com.gwtplatform.dispatch.rest.shared.RestService; import static com.gwtplatform.carstore.shared.rest.ResourcesPath.STATS; import static com.gwtplatform.carstore.shared.rest.RestParameter.DATE; import static com.gwtplatform.carstore.shared.rest.RestParameter.DATE_FORMAT; @Path(STATS) -public interface StatisticsService extends RestService { +public interface StatisticsService { @GET RestAction extractYearFromDate(@QueryParam(DATE) @DateFormat(DATE_FORMAT) Date date); } diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/CarResource.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/CarResource.java index bc8121d4c1..7352d46536 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/CarResource.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/CarResource.java @@ -92,7 +92,7 @@ public Response saveOrCreate(CarDto carDto) { return Response.ok(Car.createDto(car)).build(); } - @Path(PathParameter.ID) + @Path(PathParameter.PATH_ID) @DELETE public Response delete(@PathParam(RestParameter.ID) Long id) { carDao.delete(id); diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/ManufacturerResource.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/ManufacturerResource.java index ae92e4e48a..0b7e77d93c 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/ManufacturerResource.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/ManufacturerResource.java @@ -63,7 +63,7 @@ public Response getManufacturers() { return Response.ok(manufacturerDtos).build(); } - @Path(PathParameter.ID) + @Path(PathParameter.PATH_ID) @GET public Response get(@PathParam(RestParameter.ID) Long id) { ManufacturerDto manufacturerDto = Manufacturer.createDto(manufacturerDao.get(id)); @@ -78,7 +78,7 @@ public Response saveOrCreate(ManufacturerDto manufacturerDto) { return Response.ok(Manufacturer.createDto(manufacturer)).build(); } - @Path(PathParameter.ID) + @Path(PathParameter.PATH_ID) @DELETE public Response delete(@PathParam(RestParameter.ID) Long id) { manufacturerDao.delete(id); diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/RatingResource.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/RatingResource.java index ba63f60da6..deb1ff4862 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/RatingResource.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/server/rest/RatingResource.java @@ -52,7 +52,7 @@ public Response getRatings() { return Response.ok(ratingDtos).build(); } - @Path(PathParameter.ID) + @Path(PathParameter.PATH_ID) @GET public Response get(@PathParam(RestParameter.ID) Long id) { RatingDto ratingDto = Rating.createDto(ratingDao.get(id)); @@ -67,7 +67,7 @@ public Response saveOrCreate(RatingDto ratingDto) { return Response.ok(Rating.createDto(rating)).build(); } - @Path(PathParameter.ID) + @Path(PathParameter.PATH_ID) @DELETE public Response delete(@PathParam(RestParameter.ID) Long id) { ratingDao.delete(id); diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/shared/rest/PathParameter.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/shared/rest/PathParameter.java index b9da3e8a92..3f18d579c5 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/shared/rest/PathParameter.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/shared/rest/PathParameter.java @@ -17,5 +17,5 @@ package com.gwtplatform.carstore.shared.rest; public class PathParameter { - public static final String ID = "/{" + RestParameter.ID + "}"; + public static final String PATH_ID = "/{" + RestParameter.ID + "}"; } diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/AbstractRestAction.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/AbstractRestAction.java index 8f7f1a550f..9bfdf610de 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/AbstractRestAction.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/AbstractRestAction.java @@ -27,7 +27,7 @@ /** * Provides a basic implementation of {@link RestAction} to inheritors. This is used by GWTP code-generator to create - * the actions defined by the {@link com.gwtplatform.dispatch.rest.shared.RestService} implementers. + * the actions defined by the services. * * @param the result type */ diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/RestDispatcherController.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/RestDispatcherController.java index fd328d5ca8..48bf797b47 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/RestDispatcherController.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/client/RestDispatcherController.java @@ -19,7 +19,7 @@ import com.google.gwt.core.client.EntryPoint; /** - * This interface is used to initiate the generation of {@link com.gwtplatform.dispatch.rest.shared.RestService}s and + * This interface is used to initiate the generation of services and * {@link com.gwtplatform.dispatch.rest.shared.RestAction}s. *

* Making it an {@link EntryPoint} makes sure GWT kicks off the generation as early as possible. diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/AbstractServiceGenerator.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/AbstractServiceGenerator.java index af0d6e5371..d654899c14 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/AbstractServiceGenerator.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/AbstractServiceGenerator.java @@ -19,6 +19,7 @@ import java.util.List; import javax.inject.Provider; +import javax.ws.rs.Path; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; @@ -30,15 +31,14 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.gwtplatform.dispatch.rest.rebind.type.ActionBinding; import com.gwtplatform.dispatch.rest.rebind.type.ServiceBinding; -import com.gwtplatform.dispatch.rest.rebind.type.ServiceDefinitions; import com.gwtplatform.dispatch.rest.rebind.util.GeneratorUtil; +import com.gwtplatform.dispatch.rest.shared.RestAction; public abstract class AbstractServiceGenerator extends AbstractVelocityGenerator { protected static final String TEMPLATE = "com/gwtplatform/dispatch/rest/rebind/RestService.vm"; private final List actionBindings = Lists.newArrayList(); private final List serviceBindings = Lists.newArrayList(); - private final ServiceDefinitions serviceDefinitions; private final GeneratorFactory generatorFactory; private final JClassType service; @@ -48,12 +48,10 @@ protected AbstractServiceGenerator( Provider velocityContextProvider, VelocityEngine velocityEngine, GeneratorUtil generatorUtil, - ServiceDefinitions serviceDefinitions, GeneratorFactory generatorFactory, JClassType service) { super(typeOracle, logger, velocityContextProvider, velocityEngine, generatorUtil); - this.serviceDefinitions = serviceDefinitions; this.generatorFactory = generatorFactory; this.service = service; } @@ -76,19 +74,33 @@ protected void generateMethods() throws UnableToCompleteException { JMethod[] methods = service.getInheritableMethods(); if (methods != null) { for (JMethod method : methods) { - if (isRestService(method)) { - generateChildRestService(method); - } else { - generateRestAction(method); - } + generateMethodHierarchy(method); } } } - protected boolean isRestService(JMethod method) throws UnableToCompleteException { + protected void generateMethodHierarchy(JMethod method) throws UnableToCompleteException { + if (isAction(method)) { + generateRestAction(method); + } else if (isSubService(method)) { + generateChildRestService(method); + } else { + String methodName = method.getEnclosingType().getQualifiedSourceName() + "#" + method.getName() + "(...)"; + getLogger().die(methodName + " should return either a RestAction<> or a Sub-Resource."); + } + } + + protected boolean isAction(JMethod method) throws UnableToCompleteException { + JClassType actionClass = getTypeOracle().findType(RestAction.class.getName()); + JClassType returnClass = method.getReturnType().isClassOrInterface(); + + return returnClass != null && returnClass.isAssignableTo(actionClass); + } + + protected boolean isSubService(JMethod method) throws UnableToCompleteException { JClassType returnInterface = method.getReturnType().isInterface(); - return returnInterface != null && serviceDefinitions.isService(returnInterface); + return returnInterface != null && method.isAnnotationPresent(Path.class); } protected void generateChildRestService(JMethod method) throws UnableToCompleteException { diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ChildServiceGenerator.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ChildServiceGenerator.java index e93401c002..4156fb0997 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ChildServiceGenerator.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ChildServiceGenerator.java @@ -37,7 +37,6 @@ import com.gwtplatform.dispatch.rest.client.NoXsrfHeader; import com.gwtplatform.dispatch.rest.rebind.type.ChildServiceBinding; import com.gwtplatform.dispatch.rest.rebind.type.ServiceBinding; -import com.gwtplatform.dispatch.rest.rebind.type.ServiceDefinitions; import com.gwtplatform.dispatch.rest.rebind.util.GeneratorUtil; public class ChildServiceGenerator extends AbstractServiceGenerator { @@ -50,17 +49,17 @@ public class ChildServiceGenerator extends AbstractServiceGenerator { private ServiceBinding serviceBinding; @Inject - ChildServiceGenerator(TypeOracle typeOracle, - Logger logger, - Provider velocityContextProvider, - VelocityEngine velocityEngine, - GeneratorUtil generatorUtil, - GeneratorFactory generatorFactory, - ServiceDefinitions serviceDefinitions, - @Assisted JMethod serviceMethod, - @Assisted ServiceBinding parent) { - super(typeOracle, logger, velocityContextProvider, velocityEngine, generatorUtil, serviceDefinitions, - generatorFactory, serviceMethod.getReturnType().isInterface()); + ChildServiceGenerator( + TypeOracle typeOracle, + Logger logger, + Provider velocityContextProvider, + VelocityEngine velocityEngine, + GeneratorUtil generatorUtil, + GeneratorFactory generatorFactory, + @Assisted JMethod serviceMethod, + @Assisted ServiceBinding parent) { + super(typeOracle, logger, velocityContextProvider, velocityEngine, generatorUtil, generatorFactory, + serviceMethod.getReturnType().isInterface()); this.serviceMethod = serviceMethod; this.parent = parent; @@ -122,7 +121,7 @@ private void doGenerate(String implName, PrintWriter printWriter) throws UnableT private boolean isSecured() { return parent.isSecured() - && !serviceMethod.isAnnotationPresent(NoXsrfHeader.class) - && !service.isAnnotationPresent(NoXsrfHeader.class); + && !serviceMethod.isAnnotationPresent(NoXsrfHeader.class) + && !service.isAnnotationPresent(NoXsrfHeader.class); } } diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ServiceGenerator.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ServiceGenerator.java index 65fce21ee1..2beba56140 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ServiceGenerator.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/ServiceGenerator.java @@ -32,7 +32,6 @@ import com.google.inject.assistedinject.Assisted; import com.gwtplatform.dispatch.rest.client.NoXsrfHeader; import com.gwtplatform.dispatch.rest.rebind.type.ServiceBinding; -import com.gwtplatform.dispatch.rest.rebind.type.ServiceDefinitions; import com.gwtplatform.dispatch.rest.rebind.util.GeneratorUtil; public class ServiceGenerator extends AbstractServiceGenerator { @@ -42,16 +41,15 @@ public class ServiceGenerator extends AbstractServiceGenerator { private ServiceBinding serviceBinding; @Inject - ServiceGenerator(TypeOracle typeOracle, - Logger logger, - Provider velocityContextProvider, - VelocityEngine velocityEngine, - GeneratorUtil generatorUtil, - ServiceDefinitions serviceDefinitions, - GeneratorFactory generatorFactory, - @Assisted JClassType service) { - super(typeOracle, logger, velocityContextProvider, velocityEngine, generatorUtil, serviceDefinitions, - generatorFactory, service); + ServiceGenerator( + TypeOracle typeOracle, + Logger logger, + Provider velocityContextProvider, + VelocityEngine velocityEngine, + GeneratorUtil generatorUtil, + GeneratorFactory generatorFactory, + @Assisted JClassType service) { + super(typeOracle, logger, velocityContextProvider, velocityEngine, generatorUtil, generatorFactory, service); this.service = service; path = extractPath(service); diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/type/ServiceDefinitions.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/type/ServiceDefinitions.java index d27961ea84..ac7f02259c 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/type/ServiceDefinitions.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/rebind/type/ServiceDefinitions.java @@ -19,31 +19,26 @@ import java.util.List; import javax.inject.Inject; +import javax.ws.rs.Path; import com.google.common.collect.Lists; import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.gwtplatform.dispatch.rest.rebind.Logger; -import com.gwtplatform.dispatch.rest.rebind.util.GeneratorUtil; -import com.gwtplatform.dispatch.rest.shared.RestService; public class ServiceDefinitions { - private static final String SERVICE_INTERFACE = RestService.class.getName(); - private final TypeOracle typeOracle; private final List services = Lists.newArrayList(); private final Logger logger; - private final GeneratorUtil generatorUtil; @Inject - ServiceDefinitions(Logger logger, - TypeOracle typeOracle, - GeneratorUtil generatorUtil) + ServiceDefinitions( + Logger logger, + TypeOracle typeOracle) throws UnableToCompleteException { this.logger = logger; this.typeOracle = typeOracle; - this.generatorUtil = generatorUtil; findAllServices(); } @@ -53,24 +48,27 @@ public List getServices() { } public boolean isService(JClassType type) throws UnableToCompleteException { - JClassType serviceInterface = generatorUtil.getType(SERVICE_INTERFACE); + boolean isService = type.isAnnotationPresent(Path.class); + + if (isService) { + ensureIsInterface(type); + } - return !SERVICE_INTERFACE.equals(type.getQualifiedSourceName()) && type.isAssignableTo(serviceInterface); + return isService; + } + + private void ensureIsInterface(JClassType type) throws UnableToCompleteException { + if (type.isInterface() == null) { + String typeName = type.getQualifiedSourceName(); + logger.die(typeName + " must be an interface."); + } } private void findAllServices() throws UnableToCompleteException { for (JClassType type : typeOracle.getTypes()) { if (isService(type)) { - verifyIsInterface(type); services.add(type); } } } - - private void verifyIsInterface(JClassType type) throws UnableToCompleteException { - if (type.isInterface() == null) { - String typeName = type.getQualifiedSourceName(); - logger.die(typeName + " must be an interface."); - } - } } diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestAction.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestAction.java index b54b4f7dbd..051e17c02c 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestAction.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestAction.java @@ -24,8 +24,7 @@ /** * An action used by {@link RestDispatch}. *

- * You will usually want to let GWTP generate your actions by creating - * {@link com.gwtplatform.dispatch.rest.shared.RestService}s as explained + * You will usually want to let GWTP generate your actions by creating services as explained * here. * * @param the result type. diff --git a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestService.java b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestService.java index 4f47bae29d..957c7661b7 100644 --- a/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestService.java +++ b/gwtp-core/gwtp-dispatch-rest/src/main/java/com/gwtplatform/dispatch/rest/shared/RestService.java @@ -17,14 +17,9 @@ package com.gwtplatform.dispatch.rest.shared; /** - * Defines {@link RestAction}s to be used with {@link RestDispatch}. All interfaces extending {@link RestService} in - * your classpath will get their implementation generated at compile-time, making it possible to inject them with GIN. - *

- * See this page on how to - * write your services. - *

- * All methods defined here must return a {@link RestAction} and use - * JAX-RS annotations. + * @deprecated Services are generated based on the presence of a {@link javax.ws.rs.Path @Path} annotation. This + * interface should no longer be used and will eventually be deleted. */ +@Deprecated public interface RestService { } From 6d31b21f8e939bd3a1b54a423b337a973ce2bab1 Mon Sep 17 00:00:00 2001 From: Christopher Viel Date: Tue, 8 Apr 2014 06:42:21 -0400 Subject: [PATCH 2/2] Remove rest interface from carstore --- .../java/com/gwtplatform/carstore/client/rest/CarsService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java index e7cd0cf341..4aae28da89 100644 --- a/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java +++ b/gwtp-carstore/src/main/java/com/gwtplatform/carstore/client/rest/CarsService.java @@ -26,7 +26,6 @@ import com.gwtplatform.carstore.shared.dto.CarDto; import com.gwtplatform.dispatch.rest.shared.RestAction; -import com.gwtplatform.dispatch.rest.shared.RestService; import static com.gwtplatform.carstore.shared.rest.PathParameter.PATH_ID; import static com.gwtplatform.carstore.shared.rest.ResourcesPath.CARS; @@ -36,7 +35,7 @@ import static com.gwtplatform.carstore.shared.rest.RestParameter.OFFSET; @Path(CARS) -public interface CarsService extends RestService { +public interface CarsService { @GET RestAction> getCars();