use of com.google.inject.Binder in project kernel by exoplatform.
the class GuiceContainer method start.
/**
* {@inheritDoc}
*/
@Override
public void start() {
ConfigurationManager cm = super.getComponentInstanceOfType(ConfigurationManager.class, false);
// We check if the component has been defined in the configuration of the current container
// The goal is to enable the GuicegContainer only if it is needed
Component component = cm.getComponent(ModuleProvider.class);
if (component == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No ModuleProvider has been defined, thus the GuiceContainer will be disabled." + " To enable the Guice Integration please define a ModuleProvider");
}
} else {
ModuleProvider provider = super.getComponentInstanceOfType(ModuleProvider.class, false);
injector = Guice.createInjector(provider.getModule(), new AbstractModule() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void configure() {
Collection<ComponentAdapter<?>> adapters = delegate.getComponentAdapters();
Binder binder = binder();
for (ComponentAdapter<?> adapter : adapters) {
Object key = adapter.getComponentKey();
Class<?> type;
Annotation annotation = null;
Class<? extends Annotation> annotationType = null;
if (key instanceof Class<?> && !((Class<?>) key).isAnnotation()) {
type = (Class<?>) key;
} else {
if (key instanceof String) {
annotation = Names.named((String) key);
} else if (key instanceof Class<?>) {
annotationType = (Class<? extends Annotation>) key;
}
type = adapter.getComponentImplementation();
}
if (annotation == null && annotationType == null) {
binder.bind(type).toProvider(new ComponentAdapterProvider(type, adapter));
} else {
// As we don't know the type, we will bind it for each super classes and interfaces too
ComponentAdapterProvider provider = new ComponentAdapterProvider(type, adapter);
bindAll(binder, type, provider, annotation, annotationType);
}
}
}
});
LOG.info("A GuiceContainer has been enabled using the ModuleProvider " + provider.getClass());
}
super.start();
}
use of com.google.inject.Binder in project xtext-core by eclipse.
the class AbstractLanguageServerTest method getServerModule.
protected com.google.inject.Module getServerModule() {
ServerModule _serverModule = new ServerModule();
final com.google.inject.Module _function = (Binder it) -> {
AnnotatedBindingBuilder<RequestManager> _bind = it.<RequestManager>bind(RequestManager.class);
_bind.toInstance(new RequestManager() {
@Override
public <V extends Object> CompletableFuture<V> runRead(final Function1<? super CancelIndicator, ? extends V> request) {
final CompletableFuture<V> result = new CompletableFuture<V>();
try {
final CancelIndicator _function = () -> {
return false;
};
result.complete(request.apply(_function));
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
result.completeExceptionally(e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
@Override
public <U extends Object, V extends Object> CompletableFuture<V> runWrite(final Function0<? extends U> nonCancellable, final Function2<? super CancelIndicator, ? super U, ? extends V> request) {
final CompletableFuture<V> result = new CompletableFuture<V>();
try {
final CancelIndicator _function = () -> {
return false;
};
result.complete(request.apply(_function, nonCancellable.apply()));
} catch (final Throwable _t) {
if (_t instanceof Throwable) {
final Throwable e = (Throwable) _t;
result.completeExceptionally(e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
return result;
}
});
};
return Modules2.mixin(_serverModule, _function);
}
Aggregations