Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up the Guice integration

  • Loading branch information...
commit ca05771b267baa97b951246aab0867cf7c342671 1 parent 8fdc7d9
@jfarcand jfarcand authored
View
23 ...ks/src/main/java/org/sonatype/restsimple/sitebricks/guice/RestSimpleSitebricksModule.java
@@ -33,42 +33,27 @@
private final ServiceHandlerMapper mapper;
private final NegotiationTokenGenerator tokenGenerator;
private final Class<? extends ServiceDefinitionProvider> provider;
- private final boolean isChild;
public RestSimpleSitebricksModule(Binder binder,
ServiceHandlerMapper mapper,
NegotiationTokenGenerator tokenGenerator,
- Class<? extends ServiceDefinitionProvider> provider,
- boolean isChild) {
+ Class<? extends ServiceDefinitionProvider> provider) {
this.binder = binder;
this.mapper = mapper;
this.tokenGenerator = tokenGenerator;
this.provider = provider;
- this.isChild = isChild;
}
public RestSimpleSitebricksModule(Binder binder, NegotiationTokenGenerator tokenGenerator) {
- this(binder, new ServiceHandlerMapper(), tokenGenerator, SitebricksServiceDefinitionProvider.class, false);
- }
-
- public RestSimpleSitebricksModule(Binder binder, NegotiationTokenGenerator tokenGenerator, boolean isChild) {
- this(binder, new ServiceHandlerMapper(), tokenGenerator, SitebricksServiceDefinitionProvider.class, isChild);
+ this(binder, new ServiceHandlerMapper(), tokenGenerator, SitebricksServiceDefinitionProvider.class);
}
public RestSimpleSitebricksModule(Binder binder, ServiceHandlerMapper mapper) {
- this(binder, mapper, new RFC2295NegotiationTokenGenerator(), SitebricksServiceDefinitionProvider.class, false);
- }
-
- public RestSimpleSitebricksModule(Binder binder, ServiceHandlerMapper mapper, boolean isChild) {
- this(binder, mapper, new RFC2295NegotiationTokenGenerator(), SitebricksServiceDefinitionProvider.class, isChild);
+ this(binder, mapper, new RFC2295NegotiationTokenGenerator(), SitebricksServiceDefinitionProvider.class);
}
public RestSimpleSitebricksModule(Binder binder) {
- this(binder, new ServiceHandlerMapper(), new RFC2295NegotiationTokenGenerator(), SitebricksServiceDefinitionProvider.class, false);
- }
-
- public RestSimpleSitebricksModule(Binder binder, boolean isChild) {
- this(binder, new ServiceHandlerMapper(), new RFC2295NegotiationTokenGenerator(), SitebricksServiceDefinitionProvider.class, isChild);
+ this(binder, new ServiceHandlerMapper(), new RFC2295NegotiationTokenGenerator(), SitebricksServiceDefinitionProvider.class);
}
/**
View
16 ...e-sitebricks/src/main/java/org/sonatype/restsimple/sitebricks/guice/SitebricksConfig.java
@@ -54,11 +54,11 @@
private final List<Package> packages = new ArrayList<Package>();
public SitebricksConfig() {
- this(null, new ServiceHandlerMapper(), false);
+ this(null, null, false);
}
public SitebricksConfig(Injector parent) {
- this(parent, new ServiceHandlerMapper(), false);
+ this(parent, null, false);
}
public SitebricksConfig(Injector parent, ServiceHandlerMapper mapper) {
@@ -67,8 +67,15 @@ public SitebricksConfig(Injector parent, ServiceHandlerMapper mapper) {
public SitebricksConfig(Injector parent, ServiceHandlerMapper mapper, boolean createChild) {
this.parent = parent;
- this.mapper = mapper;
this.createChild = createChild;
+
+ if (mapper == null && injector != null) {
+ this.mapper = injector.getInstance( ServiceHandlerMapper.class );
+ } else if (mapper == null) {
+ this.mapper = new ServiceHandlerMapper();
+ } else {
+ this.mapper = mapper;
+ }
}
public SitebricksConfig(ServiceHandlerMapper mapper) {
@@ -80,10 +87,11 @@ public SitebricksConfig(ServiceHandlerMapper mapper) {
*/
@Override
protected final void configureServlets() {
+
if (!createChild || parent == null) {
injector = Guice.createInjector(new RestSimpleSitebricksModule(binder(), mapper));
} else {
- injector = parent.createChildInjector( new RestSimpleSitebricksModule(binder(), mapper, createChild) );
+ injector = parent.createChildInjector( new RestSimpleSitebricksModule(binder(), mapper) );
}
List<ServiceDefinition> list = defineServices( parent == null ? injector : parent);
Please sign in to comment.
Something went wrong with that request. Please try again.