This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename the module so it doesn't conflicts with Sitebricks itself
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
...ks/src/main/java/org/sonatype/restsimple/sitebricks/guice/RestSimpleSitebricksModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2011 Sonatype, Inc. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
package org.sonatype.restsimple.sitebricks.guice; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Binder; | ||
import com.google.inject.Module; | ||
import org.sonatype.restsimple.api.ResourceModuleConfig; | ||
import org.sonatype.restsimple.api.ServiceDefinition; | ||
import org.sonatype.restsimple.sitebricks.impl.SitebricksServiceDefinitionGenerator; | ||
import org.sonatype.restsimple.sitebricks.impl.SitebricksServiceDefinitionProvider; | ||
import org.sonatype.restsimple.spi.ServiceDefinitionGenerator; | ||
import org.sonatype.restsimple.spi.ServiceDefinitionProvider; | ||
import org.sonatype.restsimple.spi.ServiceHandlerMapper; | ||
|
||
/** | ||
* A Sitebricks module that install the appropriate object needed to generate Sitebricks Resource. | ||
*/ | ||
public class RestSimpleSitebricksModule extends AbstractModule { | ||
|
||
private final Binder binder; | ||
|
||
public RestSimpleSitebricksModule(Binder binder) { | ||
this.binder = binder; | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
final ServiceHandlerMapper mapper = new ServiceHandlerMapper(); | ||
bind(ServiceHandlerMapper.class).toInstance(mapper); | ||
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); | ||
} | ||
|
||
@Override | ||
public void install(Module module) { | ||
binder.install(module); | ||
} | ||
}); | ||
|
||
|
||
bind(ServiceDefinitionGenerator.class).to(SitebricksServiceDefinitionGenerator.class); | ||
bind(ServiceDefinition.class).toProvider(ServiceDefinitionProvider.class); | ||
bind(ServiceDefinitionProvider.class).to(SitebricksServiceDefinitionProvider.class); | ||
|
||
} | ||
} |