Permalink
Browse files

Re-implement the Guice support to make it much more easier to use

  • Loading branch information...
1 parent b4912d8 commit fab8fb7727e3e8b7ffda7ba75f71193835212c49 @jfarcand jfarcand committed Jun 14, 2011
Showing with 295 additions and 471 deletions.
  1. +2 −2 README.md
  2. +0 −12 restsimple-api/src/main/java/org/sonatype/restsimple/api/DefaultServiceDefinition.java
  3. +2 −0 restsimple-api/src/main/java/org/sonatype/restsimple/spi/NegotiationTokenGenerator.java
  4. +15 −1 restsimple-api/src/main/java/org/sonatype/restsimple/spi/ServiceDefinitionConfig.java
  5. +1 −1 restsimple-api/src/main/java/org/sonatype/restsimple/spi/ServiceDefinitionGenerator.java
  6. +0 −112 restsimple-jaxrs/src/main/java/org/sonatype/restsimple/jaxrs/guice/JaxrsModule.java
  7. +75 −47 ...src/main/java/org/sonatype/restsimple/jaxrs/guice/{JaxrsConfig.java → RestSimpleJaxrsModule.java}
  8. +6 −1 ...imple-jaxrs/src/main/java/org/sonatype/restsimple/jaxrs/impl/JAXRSServiceDefinitionGenerator.java
  9. +1 −5 ...simple-jaxrs/src/main/java/org/sonatype/restsimple/jaxrs/impl/JAXRSServiceDefinitionProvider.java
  10. +2 −2 ...le-jaxrs/src/test/java/org/sonatype/restsimple/jaxrs/test/addressBook/AddressBookJaxrsConfig.java
  11. +2 −2 restsimple-jaxrs/src/test/java/org/sonatype/restsimple/jaxrs/test/nativejaxrs/NativeJaxrsConfig.java
  12. +2 −2 restsimple-jaxrs/src/test/java/org/sonatype/restsimple/jaxrs/test/petstore/PetstoreJaxrsConfig.java
  13. +2 −2 ...rc/test/java/org/sonatype/restsimple/jaxrs/test/serviceDiscovery/ServiceDiscoveryJaxrsConfig.java
  14. +164 −42 ...sitebricks/src/main/java/org/sonatype/restsimple/sitebricks/guice/RestSimpleSitebricksModule.java
  15. +0 −187 restsimple-sitebricks/src/main/java/org/sonatype/restsimple/sitebricks/guice/SitebricksConfig.java
  16. +6 −1 ...s/src/main/java/org/sonatype/restsimple/sitebricks/impl/SitebricksServiceDefinitionGenerator.java
  17. +1 −6 ...ks/src/main/java/org/sonatype/restsimple/sitebricks/impl/SitebricksServiceDefinitionProvider.java
  18. +2 −2 ...rc/test/java/org/sonatype/restsimple/sitebricks/test/addressBook/AddressBookSitebricksConfig.java
  19. +2 −2 ...rc/test/java/org/sonatype/restsimple/sitebricks/test/nativesitebricks/NativeSitebricksConfig.java
  20. +2 −2 ...icks/src/test/java/org/sonatype/restsimple/sitebricks/test/petstore/PetstoreSitebricksConfig.java
  21. +2 −2 ...va/org/sonatype/restsimple/sitebricks/test/serviceDiscovery/ServiceDiscoverySitebricksConfig.java
  22. +6 −38 restsimple-webdriver/src/main/java/org/sonatype/restsimple/WebDriver.java
View
@@ -215,7 +215,7 @@ Currently RestSimple supports Sitebricks and JAX-RS. It is possible to extend a
@Override
protected Injector getInjector() {
- return Guice.createInjector(new SitebricksConfig() {
+ return Guice.createInjector(new RestSimpleSitebricksModule() {
@Override
public List<ServiceDefinition> defineServices(Injector injector) {
@@ -279,7 +279,7 @@ There is many ways to deploy a ServiceDefinition. First, you need to decide whic
@Override
protected Injector getInjector() {
- return Guice.createInjector(new JaxrsConfig() {
+ return Guice.createInjector(new RestSimpleJaxrsModule() {
private final MediaType JSON = new MediaType(PetstoreAction.APPLICATION, PetstoreAction.JSON);
@@ -11,9 +11,6 @@
*******************************************************************************/
package org.sonatype.restsimple.api;
-import com.google.inject.Inject;
-import org.sonatype.restsimple.spi.ServiceHandlerMapper;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -27,17 +24,10 @@
private final List<MediaType> mediaTypeToProduce = new ArrayList<MediaType>();
private final List<MediaType> mediaTypeToConsume = new ArrayList<MediaType>();
private final List<ServiceHandler> serviceHandlers = new ArrayList<ServiceHandler>();
- private final ServiceHandlerMapper serviceHandlerMapper;
private final AtomicBoolean configured = new AtomicBoolean(false);
private final List<Class<?>> extensions = new ArrayList<Class<?>>();
public DefaultServiceDefinition() {
- this(new ServiceHandlerMapper());
- }
-
- @Inject
- public DefaultServiceDefinition(ServiceHandlerMapper serviceHandlerMapper) {
- this.serviceHandlerMapper = serviceHandlerMapper;
}
@Override
@@ -47,7 +37,6 @@ public String toString() {
", mediaTypeToProduce=" + mediaTypeToProduce +
", mediaTypeToConsume=" + mediaTypeToConsume +
", serviceHandlers=" + serviceHandlers +
- ", serviceHandlerMapper=" + serviceHandlerMapper +
'}';
}
@@ -66,7 +55,6 @@ public ServiceDefinition withPath(String path) {
@Override
public ServiceDefinition withHandler(ServiceHandler serviceHandler) {
serviceHandlers.add(serviceHandler);
- serviceHandlerMapper.addServiceHandler(path, serviceHandler);
return this;
}
@@ -11,13 +11,15 @@
*******************************************************************************/
package org.sonatype.restsimple.spi;
+import com.google.inject.ImplementedBy;
import org.sonatype.restsimple.api.MediaType;
import java.util.List;
/**
* Server side component for implementing a version or content negotiation challenge between a client and a server.
*/
+@ImplementedBy( RFC2295NegotiationTokenGenerator.class )
public interface NegotiationTokenGenerator {
/**
@@ -46,8 +46,22 @@
/**
* Scan for native REST resource located in the package name
*
- * @param packageName the package name
+ * @param packageName the package name
*/
ServiceDefinitionConfig scan(Package packageName);
+ /**
+ * Add a Rest resource.
+ *
+ * @param className the class name
+ */
+ ServiceDefinitionConfig addClass(Class<?> className);
+
+ /**
+ * Add a Rest resource.
+ *
+ * @param instance the class name
+ */
+ ServiceDefinitionConfig addInstance(ServiceDefinition instance);
+
}
@@ -24,6 +24,6 @@
* Generate a REST resource based on the information a {@link org.sonatype.restsimple.api.ServiceDefinition} represents.
* @param serviceDefinition a {@link ServiceDefinition}
*/
- void generate(ServiceDefinition serviceDefinition);
+ void generate(ServiceDefinition serviceDefinition, ServiceHandlerMapper mapper);
}
@@ -1,112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2011 Sonatype, Inc.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Apache License v2.0 which accompanies this distribution.
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * The Apache License v2.0 is available at
- * http://www.apache.org/licenses/LICENSE-2.0.html
- * You may elect to redistribute this code under either of these licenses.
- *******************************************************************************/
-package org.sonatype.restsimple.jaxrs.guice;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Binder;
-import com.google.inject.Module;
-import org.sonatype.restsimple.spi.NegotiationTokenGenerator;
-import org.sonatype.restsimple.spi.RFC2295NegotiationTokenGenerator;
-import org.sonatype.restsimple.spi.ResourceModuleConfig;
-import org.sonatype.restsimple.api.ServiceDefinition;
-import org.sonatype.restsimple.jaxrs.impl.JAXRSServiceDefinitionGenerator;
-import org.sonatype.restsimple.jaxrs.impl.JAXRSServiceDefinitionProvider;
-import org.sonatype.restsimple.spi.ServiceDefinitionGenerator;
-import org.sonatype.restsimple.spi.ServiceDefinitionProvider;
-import org.sonatype.restsimple.spi.ServiceHandlerMapper;
-
-/**
- * A JAXRS module which install the appropriate object needed to generate JAXRS Resource.
- */
-public class JaxrsModule extends AbstractModule {
-
- private final Binder binder;
- private final ServiceHandlerMapper mapper;
- private final NegotiationTokenGenerator tokenGenerator;
- private final Class<? extends ServiceDefinitionProvider> provider;
- private final boolean isChild;
-
- public JaxrsModule(Binder binder,
- ServiceHandlerMapper mapper,
- NegotiationTokenGenerator tokenGenerator,
- Class<? extends ServiceDefinitionProvider> provider,
- boolean isChild) {
-
- this.binder = binder;
- this.mapper = mapper;
- this.tokenGenerator = tokenGenerator;
- this.provider = provider;
- this.isChild = isChild;
- }
-
- public JaxrsModule(Binder binder, NegotiationTokenGenerator tokenGenerator) {
- this(binder, new ServiceHandlerMapper(), tokenGenerator, JAXRSServiceDefinitionProvider.class, false);
- }
-
- public JaxrsModule(Binder binder, NegotiationTokenGenerator tokenGenerator, boolean isChild) {
- this(binder, new ServiceHandlerMapper(), tokenGenerator, JAXRSServiceDefinitionProvider.class, isChild);
- }
-
- public JaxrsModule(Binder binder, ServiceHandlerMapper mapper) {
- this(binder, mapper, new RFC2295NegotiationTokenGenerator(), JAXRSServiceDefinitionProvider.class, false);
- }
-
- public JaxrsModule(Binder binder, ServiceHandlerMapper mapper, boolean isChild) {
- this(binder, mapper, new RFC2295NegotiationTokenGenerator(), JAXRSServiceDefinitionProvider.class, isChild);
- }
-
- public JaxrsModule(Binder binder) {
- this(binder, new ServiceHandlerMapper(), new RFC2295NegotiationTokenGenerator(), JAXRSServiceDefinitionProvider.class, false);
- }
-
- public JaxrsModule(Binder binder, boolean isChild) {
- this(binder, new ServiceHandlerMapper(), new RFC2295NegotiationTokenGenerator(), JAXRSServiceDefinitionProvider.class, isChild);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void configure() {
- bind(ServiceHandlerMapper.class).toInstance(mapper);
- bind(NegotiationTokenGenerator.class).toInstance(tokenGenerator);
- binder.bind(NegotiationTokenGenerator.class).toInstance(tokenGenerator);
- binder.bind(ServiceHandlerMapper.class).toInstance(mapper);
-
- bind(ResourceModuleConfig.class).toInstance(new ResourceModuleConfig<Module>() {
-
- @Override
- public <A> void bindToInstance(Class<A> clazz, A instance) {
- binder.bind(clazz).toInstance(instance);
- }
-
- @Override
- public <A> void bindTo(Class<A> clazz, Class<? extends A> clazz2) {
- binder.bind(clazz).to(clazz2);
- }
-
- @Override
- public void bind(Class<?> clazz) {
- binder.bind(clazz).asEagerSingleton();
- }
-
- @Override
- public void install(Module module) {
- }
- });
-
- bind(ServiceDefinitionGenerator.class).to(JAXRSServiceDefinitionGenerator.class);
- bind(ServiceDefinition.class).toProvider(ServiceDefinitionProvider.class);
- bind(ServiceDefinitionProvider.class).to(provider);
-
- }
-}
Oops, something went wrong.

0 comments on commit fab8fb7

Please sign in to comment.